apache-poi

Creating custom color styles for an XSSFWorkbook in Apache POI 4.0

为君一笑 提交于 2019-12-05 14:53:39
To apply a custom color for an XSSFWorkbook in Apache POI 3.7 and below the following was possible: java.awt.Color c = new java.awt.Color (1,2,3) XSSFCellStyle xcs = xssfWorkbook.createCellStyle(); XSSFFont headerFont = xssfWorkbook.createFont(); headerFont.setColor(new XSSFColor(c)); xcs.setFont(headerFont); cell.setCellStyle(xcs); In version 4.0 XSSFColor(java.awt.Color) got removed. It is still possible to achieve the same, just with additional 'hackery': XSSFColor xc = new XSSFColor(); xc.setARGBHex(String.format("%02x%02x%02x",c.getRed(),c.getGreen(),c.getBlue())); headerFont.setColor(xc)

Is there any code to read MS Office PPT on Android?

回眸只為那壹抹淺笑 提交于 2019-12-05 14:42:19
I'm looking for code to read MS Office PPT on Android, is there anyone interested in sharing the code? You might want to take a look at Apache POI - the Java API for Microsoft Documents The Apache POI Project's mission is to create and maintain Java APIs for manipulating various file formats based upon the Office Open XML standards (OOXML) and Microsoft's OLE 2 Compound Document format (OLE2). In short, you can read and write MS Excel files using Java. In addition, you can read and write MS Word and MS PowerPoint files using Java. http://poi.apache.org/ I found an useful Url here: http://code

How to get the line number, page number of a particular word in a doc,docx file using apache poi?

你。 提交于 2019-12-05 13:01:55
I am trying to create a java application which would search for particular word in the selected doc, docx file and generates a report on it. That report will contain the page number and the line number of the searched word. Now that what I have achieved is I am able to read the doc and docx file by paragraph. But I didn't find any way to search for a particular word and to get the line & page number where that word is present. I searched a lot but no luck till now. Hope someone knows the way to do this. Here is my code if(fc.getSelectedFile().getAbsolutePath().contains("docx")) { File file =

Writing to a particular cell location using Apache POI Excel

时光怂恿深爱的人放手 提交于 2019-12-05 12:56:22
If I've got an list of parameters 'x,y,z' that aren't sorted, is there a straightforward way to write them to particular cells in an excel document created with POI, as though the first two parameters are X and Y coordinates? For example, I have rows like: 10,4,100 Is it possible to write the value '100' in the cell at the 10th row, 4th column? Looking at the documentation, it looks straightforward to iterate values into the next row, but I can't see any way of creating a fixed number of rows and columns and writing particular values to only certain cells. Any advice or suggestions would be

Setting Excel cell value in Numeric format using POI

混江龙づ霸主 提交于 2019-12-05 11:44:41
问题 I want to store numeric data in excel sheet. The numeric data is represented by String type in my java code. Is it possible to set it as numeric without casting it? I've tried the following code, but it wasn't converted to numeric type (I get a warning in excel saying that number is stored as text...) HSSFCell dCell =... dCell.setCellType(Cell.CELL_TYPE_NUMERIC); dCell.setCellValue("112.45") 回答1: You have to provide the value as a double. As the doc says: setCellValue public void setCellValue

Apache POI XSSF reading in excel files

▼魔方 西西 提交于 2019-12-05 11:24:35
问题 I just have a quick question about how to read in an xlsx file using the XSSF format from Apache. Right now my code looks like this: InputStream fs = new FileInputStream(filename); // (1) XSSFWorkbook wb = new XSSFWorkbook(fs); // (2) XSSFSheet sheet = wb.getSheetAt(0); // (3) ...with all the relevant things imported. My problem is that when I hit run, it gets stuck at line (2), in almost an infinite loop. filename is just a string. If anybody could give me some sample code on how to fix this

Get Excel SheetNames using POI jar

我的未来我决定 提交于 2019-12-05 10:52:04
I need all Excel sheet Names (what r all contains the datas) using POI jar. Like jxl jar - getSheetNames() You don't say how you want them, so I'll guess at a list. You just need to iterate over the sheet indicies, getting the name for each. Your code would be something like: File myFile = new File("/path/to/excel.xls"); Workbook wb = WorbookFactory.create(myFile); List<String> sheetNames = new ArrayList<String>(); for (int i=0; i<wb.getNumberOfSheets(); i++) { sheetNames.add( wb.getSheetName(i) ); } 来源: https://stackoverflow.com/questions/12600883/get-excel-sheetnames-using-poi-jar

XMLBeans jar can't be signed when imported from custom class

∥☆過路亽.° 提交于 2019-12-05 10:25:12
In NetBeans I created an Exporter class that exports some data to an EXCEL file using APACHE POI, which uses XMLBeans. I added the APACHE POI 3.10.1 libraries by downloading the zip binaries and adding the jars manually. When I use this class inside the same project, everything runs correctly. Then I added this class to another project, via right click Libraries -> Add Project. But when I tried running this I got the following error while compiling. Signing JAR: C:\Users\c\p\dist\lib\xmlbeans-2.6.0.jar to C:\Users\c\p\dist\lib\xmlbeans-2.6.0.jar as nb-jfx jarsigner: unable to sign jar: java

Parsing Excel file without Apache POI

ぐ巨炮叔叔 提交于 2019-12-05 10:04:19
I know that we can use Apache POI to parse an Excel file and get data. But I heard of a strange thing that excel file can be passed in a similar way we parse CSV (Like just read the file from file Stream and separate each column value with a "comma" separator). When we parse Excel we have to use tab as a delimiter. Is it possible? If yes then why Apache has come up with such a complicated framework. I am puzzled. Can someone help me? CSV is a text format, so it can be parsed using the delimiters. Old Excel is a binary and proprietary format so it needs clever decoding. The new Excel format is

Your InputStream was neither an OLE2 stream, nor an OOXML stream

Deadly 提交于 2019-12-05 10:02:07
I am using Apache Commons to upload a .docx file in google app engine as explained in this link File upload servlet . While uploading, I also want to extract text by using Apache POI libraries. If I pass this to the POI API: InputStream stream = item.openStream(); I get the below exception: java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 stream, nor an OOXML stream public static String docx2text(InputStream is) throws Exception { return ExtractorFactory.createExtractor(is).getText(); } I am uploading a valid .docx document. The POI API works fine if I pass a