apache-poi

Apache POI not returning the proper value for large numbers coming from Excel

我只是一个虾纸丫 提交于 2019-12-23 16:24:13
问题 I have an excel file with the value 6228480018362050000 the exported csv looks like this... Int,Bigint,String 1,6228480018362050000,Very big When I try running the following code... InputStream inp = new FileInputStream("/.../test.xlsx"); DataFormatter df = new DataFormatter(true); df.formatCellValue(WorkbookFactory.create(inp).getSheetAt(0).getRow(1).getCell(1)); I get 6228480018362049500 which is the wrong number because precision is hosed. Is there a way to get the actual value? 回答1: If we

Apache POI formulas not evaluating

点点圈 提交于 2019-12-23 15:49:33
问题 So I'm having some issues getting Apache POI to evaluate formulas. Here's the code I call to evaluate formulas before writing: complete.getCreationHelper().createFormulaEvaluator().evaluateAll(); complete.write(fileOut); Here's the code I call to write to the cells being used (proving they're numbers): try{ cell.setCellValue((Double)grid[i][j]); } catch(Exception e){ cell.setCellValue((String)grid[i][j]); } FYI: grid is a 2D Object array containing only entries of the type double and String .

Why we need to create a Workbook before reading the Excel file using Apache POI?

一笑奈何 提交于 2019-12-23 12:39:00
问题 Please find a Code snippet below public class DataDriven_GetDataExcel { public static void main(String[] args) throws IOException, EncryptedDocumentException, InvalidFormatException { //1 Getting Control over File FileInputStream fis = new FileInputStream("C:\\Users\\bewosaurabh\\Documents\\GetDataFile.xlsx"); //2 Creating a Workbook Workbook wb = WorkbookFactory.create(fis); //3 Getting Control over Sheet Sheet sh = wb.getSheet("Sheet1"); . ...... What I don't understand is why we need to

Can not set font color in conditional formatting cell via apache poi

喜欢而已 提交于 2019-12-23 12:33:05
问题 My purpose is to copy conditional formatting rules from one sheet to another, where two sheets are not in same workbook via apache poi. For this purpose I am using the following code; for(int i=0;i<sscf.getNumConditionalFormattings();i++){ ConditionalFormatting cf = sscf.getConditionalFormattingAt(i); CellRangeAddress[] range = cf.getFormattingRanges(); //getting various properties from source ConditionalFormattingRule rule = cf.getRule(0); PatternFormatting pattern = rule

Skipping Blank Excel Cells in Apache POI

只谈情不闲聊 提交于 2019-12-23 12:27:12
问题 I'm new to the Apache POI, but what I want to do is read though an Excel file (.xls) and put that into a ArrayList to store so that I can later manipulate. I can get the whole sheet, but my problem is just that: I get the whole dang sheet (~54183 rows). I want to skip over the cells that are blank, which is of type 3. For some reason, when I system.out.print the ArrayList, it has all the blank cells in there. Is there a way to skip over those and not add them to the ArrayList I'm trying to

How to extract images from Thumbs.db in Java?

帅比萌擦擦* 提交于 2019-12-23 10:01:46
问题 HI I read about POI project and tried to extract images from thumbs.db but getting exception in code .. Code os InputStream stream = new FileInputStream("C:\\Thumbs.db"); POIFSFileSystem fs = new POIFSFileSystem(stream); DirectoryEntry root = fs.getRoot(); Entry entry = root.getEntry("2"); DocumentInputStream is = fs.createDocumentInputStream(entry.getName()); JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(is); JPEGDecodeParam param = JPEGCodec.getDefaultJPEGEncodeParam(4,

Apache poi - Thousand separator

时光毁灭记忆、已成空白 提交于 2019-12-23 09:48:28
问题 Do you know how can I set the thousand sepator and have a value formatted like this? 403.000 I'm using apache-poi 3.8 with Java. I googled it a lot but I didn't find an answer. I can't use a string value because my formulas are not evaluated correctly in this way. Any help? thanks! I've tried something like this: cellStyle.setDataFormat(creationHelper.createDataFormat().getFormat("#.##0")); but it doesn't work.. 回答1: You can do this: final HSSFCell dataCell = dataRow.createCell(1); dataCell

how to set page margins for word document using apache poi?

孤者浪人 提交于 2019-12-23 07:31:40
问题 I want to set page-margins for word document created using apache poi-3.9. I found it can be done using CTPageMar but CTPageMar is not being resolved. I am using apache poi-3.9 I tried this CTSectPr sectPr = document.getDocument().getBody().addNewSectPr(); CTPageMar pageMar = sectPr.addNewPgMar(); pageMar.setLeft(BigInteger.valueOf(720L)); pageMar.setTop(BigInteger.valueOf(1440L)); pageMar.setRight(BigInteger.valueOf(720L)); pageMar.setBottom(BigInteger.valueOf(1440L)); 回答1: As far as I

How to apply background color for the rows in excel sheet using Apache POI?

杀马特。学长 韩版系。学妹 提交于 2019-12-23 06:51:08
问题 I am using Apache POI for exporting data into excel sheet. it works fine. the problem is i need apply yellow background color for few rows in the excel sheet while generating the excel sheet. please hellp me how to apply background color for the rows of excel sheet while generating. Thanks, Reddy 回答1: straight from the official guide: // Aqua background CellStyle style = wb.createCellStyle(); style.setFillBackgroundColor(IndexedColors.AQUA.getIndex()); style.setFillPattern(CellStyle.BIG_SPOTS

How to Convert .doc/.docx to pdf in java using POI..?

自作多情 提交于 2019-12-23 06:41:22
问题 how to convert ms-document to PDF, is there any example pls share with me.. thanks. 回答1: If you are requiered to use POI i guess you should take a look at org.apache.poi.hwpf.converter I never tried this, but i guess it´s worth a try atleast. It seems like you can use WordToFoConverter to convert your XWPFDocument to a FO-file (example here). From there you can use apaches FOP to transform the FO-file to a PDF like this: // Step 1: Construct a FopFactory // (reuse if you plan to render