apache-poi

Apache poi Excel: Creating a formula based on the integer index of the column

一世执手 提交于 2020-01-01 10:45:06
问题 Say that my column number is 26, when I create a formula my formula should look like, say: SUM(AA1:AA3) for example. but how do I translate 26 to AA? Or say 27 to AB? Is there a way for Apache POI to use Column index as an integer and translate it into its letter representation? 回答1: That requires just a little code: public static String columnName(int index) { StringBuilder s = new StringBuilder(); while (index >= 26) { s.insert(0, (char) ('A' + index % 26)); index = index / 26 - 1; } s

Apache poi Excel: Creating a formula based on the integer index of the column

倖福魔咒の 提交于 2020-01-01 10:44:26
问题 Say that my column number is 26, when I create a formula my formula should look like, say: SUM(AA1:AA3) for example. but how do I translate 26 to AA? Or say 27 to AB? Is there a way for Apache POI to use Column index as an integer and translate it into its letter representation? 回答1: That requires just a little code: public static String columnName(int index) { StringBuilder s = new StringBuilder(); while (index >= 26) { s.insert(0, (char) ('A' + index % 26)); index = index / 26 - 1; } s

File is corrupted after creating excel (.xlsx) file by using Apache POI with Java

只愿长相守 提交于 2020-01-01 09:18:31
问题 I have created a Workbook/Excel in .xlsx format with Java using Apache POI API successfully. My code is as below that is created a file named "RiponAlWasim.xlsx" in D drive: Workbook wb = new XSSFWorkbook(); FileOutputStream fileOut = new FileOutputStream("D:\\RiponAlWasim.xlsx"); wb.write(fileOut); fileOut.close(); wb.close(); When I tried to open "RiponAlWasim.xlsx" it was shown the file is corrupted. What's the wrong? 回答1: It needs to be added at least one sheet to the workbook. So, after

How to get the Cell value of A1(Cell Address) using apache poi 3.6

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-01 07:33:10
问题 I have Excel Cell Address like A1,A2. So, how to access this cell programatically using poi3.6 another way is row=mySheet.getRow(); cell=row.getCell(); But i have the address in the format of A1 ... so, how do I access those cell programatically 回答1: CellReference cr = new CellReference("A1"); row = mySheet.getRow(cr.getRow()); cell = row.getCell(cr.getCol()); See Quick Guide for more samples. 回答2: There's a cellReference function E.g. CellReference cellReference = new CellReference("B3");

How can I get the user to download my file? (Java, MVC, Excel, POI)

久未见 提交于 2020-01-01 07:13:21
问题 I'm using Struts2, Spring, and Hibernate. I have written a simple Excel file called test.xls with POI. When I run the action, it works because test.xls appears, but in my tomcat folder. I want that file to be downloadable on my jsp page. How do I go about getting the user to download the .xls file? Rather, how do I call that path? Sorry if the answer is obvious, I am new to this. I know it probably has something to do with the ServletContext or HttpServletRequest? [edit] I got it working

How can I get the user to download my file? (Java, MVC, Excel, POI)

六眼飞鱼酱① 提交于 2020-01-01 07:13:11
问题 I'm using Struts2, Spring, and Hibernate. I have written a simple Excel file called test.xls with POI. When I run the action, it works because test.xls appears, but in my tomcat folder. I want that file to be downloadable on my jsp page. How do I go about getting the user to download the .xls file? Rather, how do I call that path? Sorry if the answer is obvious, I am new to this. I know it probably has something to do with the ServletContext or HttpServletRequest? [edit] I got it working

How put a image in a cell of excel java?

会有一股神秘感。 提交于 2019-12-31 17:24:49
问题 I have tried to put an image into an Excel cell with java but without much success this is the code I was working but the only thing I've done is put the image on excel sheet but not in a cell specified XSSFWorkbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet("My Sample Excel"); //FileInputStream obtains input bytes from the image file InputStream inputStream = new FileInputStream("C:/images/logo.png"); //Get the contents of an InputStream as a byte[]. byte[] bytes = IOUtils

How put a image in a cell of excel java?

痴心易碎 提交于 2019-12-31 17:24:39
问题 I have tried to put an image into an Excel cell with java but without much success this is the code I was working but the only thing I've done is put the image on excel sheet but not in a cell specified XSSFWorkbook wb = new XSSFWorkbook(); Sheet sheet = wb.createSheet("My Sample Excel"); //FileInputStream obtains input bytes from the image file InputStream inputStream = new FileInputStream("C:/images/logo.png"); //Get the contents of an InputStream as a byte[]. byte[] bytes = IOUtils

org.apache.poi.EncryptedDocumentException: Unsupported hash algorithm

﹥>﹥吖頭↗ 提交于 2019-12-31 06:49:59
问题 I was trying to read a standard password protected Microsoft Excel Worksheet when I get the error: org.apache.poi.EncryptedDocumentException: Unsupported hash algorithm I've been following the standard procedure for xlsx files: POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file)); EncryptionInfo info = new EncryptionInfo(fs); // exception strikes here Decryptor d = Decryptor.getInstance(info); What can I do ? 回答1: The document at http://poi.apache.org/encryption.html describes

How to identify a cell is blank or null or empty while reading a excel file

亡梦爱人 提交于 2019-12-31 05:58:57
问题 I read a excel file to pass the input for some data fields. But when I run the program, some cell values are returning as null, some as blank.Physically when I open the excel file no value is available in the cell. How can I identify manually an excel cell is null or blank. For some scenarios I need to pass the blank values to the fields. If the cell is null I cannot pass the values to the fields. Guide me to reach out. Code: public static void readAllData() throws IOException{ Object result