apache-poi

Mimetype check using Tika jars

寵の児 提交于 2019-12-19 08:49:26
问题 I am developing standard alone Java batch process. I am trying to determine file attachment mimetype using Tika Jars. I am using Tika 1.4 Jar files. My code look like Parser parser= new AutoDetectParser(); InputStream stream = new FileInputStream(fileAttachment); int writerHandler =-1; ContentHandler contentHandler= new BodyContentHandler(writerHandler); Metadata metadata= new Metadata(); parser.parse(stream, contentHandler, metadata, new ParseContext()); String mimeType = metadata.get

Apache POI DataFormatter Returns Scientific Notation

懵懂的女人 提交于 2019-12-19 08:27:11
问题 I have an xlsx file I'm reading with apache poi 3.17 in java 6. In one instance I have a cell with the value, 123456789011. This is read into java as a NUMERIC CellTypeEnum Cell. When I use DataFormatter to get the value of the cell like this: DataFormatter formatter = new DataFormatter(Locale.US); String strVal = formatter.formatCellValue(cell); The String value comes out as "1.234567+11". I need the real value in the cell which is "123456789011". How can I get that? I already tried using

how to change the tab color of a worksheet with Apache Poi

不羁岁月 提交于 2019-12-19 07:23:10
问题 I am trying to set the background color of a worksheet tab using Apache POI. I can't seem to figure out how to set the style on the tabs themselves though. Thanks for the help! 回答1: It would appear that it is not possible. boo. This was the best explanation of why: http://osdir.com/ml/user-poi.apache.org/2009-03/msg00034.html 回答2: As commented by Alfabravo... it's possible now to change the XSSFSheet tab color. sheet.setTabColor(int colorIndex) is used for that, and so if we use sheet

How to read font size of each word in a word document using POI?

[亡魂溺海] 提交于 2019-12-19 07:20:31
问题 I am trying to find out whether there exist anything in the word document that has a font of 2. However, I have not been able to do this. To begin with, I've tried to read the font of each word in a sample word document that only has one line and 7 words. I am not getting the correct results. Here is my code: HWPFDocument doc = new HWPFDocument (fileStream); WordExtractor we = new WordExtractor(doc); Range range = doc.getRange() String[] paragraphs = we.getParagraphText(); for (int i = 0; i <

POI Appending .0 while reading numeric data from excel

北城以北 提交于 2019-12-19 07:19:08
问题 I am using POI HSSF to read excel data and I am using JUnit to check the data against database proc RefCursor. The Junit test fails as the numeric data from the Refcursor for example 100 are compared against the data in the excel sheet 100 but it fails as the POI reads it as 100.0. InputStream fileInputStream = Testdb.class.getClassLoader().getResourceAsStream(fileName); //retrieve number of columns and rows int numRows=0, numCols=0, i, j, minColIndex=0, maxColIndex=0; POIFSFileSystem

Java Apache POI Opening file? [closed]

可紊 提交于 2019-12-19 03:58:48
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I have a Java program that edits an existing excel file and saves it as a new file. However, I would also like the program to automatically open the newly created file upon ending. Is there an apache poi command that lets me do this? 回答1: As you have not Provided Code , I m using the Example of ViralPatel

Missing cell policy of Apache POI Java

一世执手 提交于 2019-12-19 03:37:12
问题 Can somebody please explain about the Missing cell policy of Apache POI ? What are exactly missing cells ? I didn't find the Apache POI docs link to be self-explanatory on what exactly are missing cells. 回答1: Did you read the Apache POI Excel Busy Developer's Guide? In some cases, when iterating, you need full control over how missing or blank rows and cells are treated, and you need to ensure you visit every cell and not just those defined in the file. (The CellIterator will only return the

Merging Two excel files as two sheets in one workbook in java

雨燕双飞 提交于 2019-12-19 00:50:07
问题 I have two xlsx files at folder C:\DemoFilesExcel\demo1.xlsx and C:\DemoFilesExcel\demo2.xlsx. I want to create a new xlsx C:\DemoFilesExcel\merged.xlsx that will have these two files as two sheets in merged.xlsx workbook. This is to be done using apache POI in java. Any idea how to do 回答1: //Open the first excel file. Workbook SourceBook1 = new Workbook("F:\\Downloads\\charts.xlsx"); //Define the second source book. //Open the second excel file. Workbook SourceBook2 = new Workbook("F:\

null pointer exception apache poi

核能气质少年 提交于 2019-12-18 21:53:40
问题 hi we've been reading xls and xlsx file using apache poi ing our java program, the problem is we are getting null pointer exception with two reasons.. the first 1 is the blank cell which we already solved and the other one is when we are choosing a certain column that doesn't have any record.. our program ask for the path of the excel file then the specific sheet number of the file and the specific column number of the sheet you want to read.. here is the code for reading xls file public void

How to set formulas in cells using Apache POI?

不打扰是莪最后的温柔 提交于 2019-12-18 13:52:59
问题 I am currently using Apache POI for Java to set formulas in cells. But after I run the program and open the Excel file that I created and processed, the cells with the formula include the formula as a string, rather than the value the formula should have returned. 回答1: The HSSFCell object has methods .setCellType and .setCellFormula which you need to call like this: // "cell" object previously created or looked up String strFormula= "SUM(A1:A10)"; cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);