apache-poi

How to get the formula cell value(data) using apache poi 3.1

元气小坏坏 提交于 2019-12-04 14:46:15
I am using Apache poi-3.1-FINAL-20080629 in my application. here, I have one problem using formula... My Cell has formula(sheet2!C10) and the data inside this cell is String type (e.g $3,456)...How to access that cell also want to display the formula. My code Looks like: HSSFWorkbook wb = new HSSFWorkbook(file); HSSFSheet sheet = wb.getSheetAt(0); HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(sheet, wb); Iterator rows = sheet.rowIterator(); while (rows.hasNext()) { HSSFRow row = (HSSFRow) rows.next(); System.out.println("\n"); Iterator cells = row.cellIterator(); while (cells

Setting Time in Excel using POI

試著忘記壹切 提交于 2019-12-04 13:45:40
问题 I am trying to create an Excel Work sheet using POI api in Java. In that Excel Work Sheet I want to have a cell with TIME alone. By setting this we can include the cell in summation of that particuluar column as we do in number columns. For this we need to format the cell as Time >> 13:30:55. (The internal format is 'h:mm:ss;@' ). And we need to remove the date part from the cell. When I read the cell the cell value using the POI, it is returning as 'Sun Dec 31 01:00:00 IST 1899' ( When i set

How do I check if a cell contains an image using Apache POI?

…衆ロ難τιáo~ 提交于 2019-12-04 13:44:05
I have the following block of code: File file = new File("myFile.xlsx"); // my file inputStream = new FileInputStream(file); System.out.println("reading"); XSSFWorkbook wb = new XSSFWorkbook(inputStream); XSSFSheet sh = wb.getSheetAt(0); // first sheet Iterator rowIter = sh.rowIterator(); while(rowIter.hasNext()){ // iterate over all rows System.out.println("New Row "); // notify of new row Row myRow = (Row) rowIter.next(); Iterator cellIter = myRow.cellIterator(); while(cellIter.hasNext()){ // iterate over all cells in row XSSFCell myCell = (XSSFCell) cellIter.next(); //how can I check that

Apache POI: cloning worksheets containing charts

守給你的承諾、 提交于 2019-12-04 13:05:30
According to numerous sources, for example Limitations section on official page , probably the only good way to work with excel charts from POI is using Excel file with existing chart as a template and modify source cells used by chart. And it works great. The problem is that we need to have not only one but multiple (and we don't know how many at compile time) worksheets with the same chart but different (dynamically generated) data. Using cloneSheet(sheetNumber) is a way to duplicate a template worksheet. But if works fine only until charts are on sheet being cloned. When I try to clone a

Understanding ZipSecureFile.setMinInflateRatio(double ratio)

江枫思渺然 提交于 2019-12-04 12:47:11
I am using this function call, because when I read a trusted file, It results in zipbomb error. ZipSecureFile.setMinInflateRatio(double ratio) FileInputStream file = new FileInputStream("/file/path/report.xlsx"); ZipSecureFile.setMinInflateRatio(-1.0d); XSSFWorkbook wb = new XSSFWorkbook(file); I am trying to understand how it works? The only source I could find is https://poi.apache.org/apidocs/org/apache/poi/openxml4j/util/ZipSecureFile.html But, couldn't get a clear picture as I am new to this concept. What are the differences between ZipSecureFile.setMinInflateRatio(-1.0d); vs

Writing to Excel File using hash map

半世苍凉 提交于 2019-12-04 12:39:27
Hi,I'm getting exact values from hash map but my Apache POI Row and Cell cannot set values properly expected result like that please let me know.Thanks I'm getting result hash-map like that: {1=[ACSS Description1, ACSS Description2, ACSS Description3, SACSS Description4], 2=[11, 1, 4, 12]} I'm expecting: I'm getting result based on below code : And that's my code: public void getList(List<ExportReport> listcriteria) { Map<Integer, List<String>> hashmap = new HashMap<Integer , List<String>>(); List<String> listpropertyvalue =new ArrayList<String>(); for(int i=0; i < listcriteria.size(); i++) {

Crash when calling autoSizeColumn on worksheet, when run under Linux (Servicemix)

谁说胖子不能爱 提交于 2019-12-04 12:10:57
I've written module that generates excel, and deployed it under Servicemix. In Windows environment everything is fine, but under Linux Servicemix unexpectedly crashes on following call: for (short i=0;i<=3;i++) { log.trace("AutoSize column {}", i); worksheet.autoSizeColumn(i); } I'm using POI version 4.2-FINAL, FuseESB 4.2, Java 5.0. There are, however, no hs_err*.pid files. Servicemix logs ends on first autoSizeColumn call. Did anyone met such behaviour and know, how it is caused and how to come this around? In order to be able to calculate the column widths, POI needs to get hold of the Font

Apache POI rate formula inconsistency with long periods

江枫思渺然 提交于 2019-12-04 11:52:25
In order to emulate Excel's rate function, I'm using the Apache POI rate function I grabbed from the svn: private double calculateRate(double nper, double pmt, double pv, double fv, double type, double guess) { //FROM MS http://office.microsoft.com/en-us/excel-help/rate-HP005209232.aspx int FINANCIAL_MAX_ITERATIONS = 20; //Bet accuracy with 128 double FINANCIAL_PRECISION = 0.0000001; //1.0e-8 double y, y0, y1, x0, x1 = 0, f = 0, i = 0; double rate = guess; if (Math.abs(rate) < FINANCIAL_PRECISION) { y = pv * (1 + nper * rate) + pmt * (1 + rate * type) * nper + fv; } else { f = Math.exp(nper *

.xls convert to xlsx using java and POI APACHE

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 11:33:59
I'm trying to use POI.APACHE to edit excel files in java. I have to convert a .xls to .xlsx because I need to send the file to sharepoint. Thats why it just can't be renamed with a different extension. How would I go about this? I couldn't find any examples on their site. Thanks import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Iterator; import org.apache.poi.hssf.usermodel.HSSFWorkbook

java.lang.NoClassDefFoundError: org/openxmlformats/schemas/spreadsheetml/x2006/main/CTWorkbook$Factory

牧云@^-^@ 提交于 2019-12-04 11:13:20
I use example: http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/ss/examples/BusinessPlan.java This is my dependencies list: <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.15</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.15</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml