apache-poi

Apache POI - Split Word document (docx) to pages

痴心易碎 提交于 2019-12-06 07:34:20
I have been trying to segment a docx document to multiple documents based on a predefined criteria. following is my approach to cut it to paragraphs try { FileInputStream in = new FileInputStream(file); XWPFDocument doc = new XWPFDocument(in); List<XWPFParagraph> paragraphs = doc.getParagraphs(); for (int idx = 0; idx < paragraphs.size(); idx++) { XWPFDocument outputDocument = new XWPFDocument(); createParagraphInAnotherDocument(outputDocument, paragraphs.get(idx).getText()); String fullPath = String.format("./content/output/%1$s_%2$s_%3$04d.docx", FileUtils.getFileName(file), getName(), idx);

Writing to Excel File using hash map

给你一囗甜甜゛ 提交于 2019-12-06 07:15:45
问题 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>>();

Apache POI xlsx read, cell with # value - error unexpected cell type(5)

二次信任 提交于 2019-12-06 07:08:08
问题 Could you hepl me with such issue. I need to read each cell as String value. In this case I am using appache poi lib. and such method for normilizing each cell: String getNormilizedCell(Cell cell){ return new DataFormatter().formatCellValue(cell);} But when In .xlsx file I faced with such value: |#N/A|#N/A|...|...|... I am getting error [Unexpected Cell type (5)] and I don't know how to handle this. In google I can't find necessary information. 回答1: The DataFormatter class only handles CELL

reading excel file --> xlsx format with java

◇◆丶佛笑我妖孽 提交于 2019-12-06 06:57:45
I'm trying to read an excel file (xlsx NOT xls) but without any luck. I tried the jexcel api but it doesn't support xlsx extension, then I tried the Apache api which need to work and tried also the example from their web site but with no luck.I can't pass the read file phase and get a filenotfound exception. also used the poi-ooxml-3.6.jar,xmlbeans-2.6.0 and poi-3.7.jar. can anyone please explain to me what types of api/classes/libraries I need to use and how to use it with eclipse (the external libraries/classes/api is totally new to me) many thanks in advance Benoit Wickramarachi Apache POI

JVM crashing while writing to XLSX file( POI)

南楼画角 提交于 2019-12-06 06:09:53
问题 JVM is crashing while trying to write to the .xlsx file. I am using POI(XSSF) for the same. The error location point in code is the write method--> workBook.write(fileOutputStream); On Console I get.. A fatal error has been detected by the Java Runtime Environment: SIGBUS (0x7) at pc=0xb68d77f3, pid=14653, tid=1849355120 JRE version: 7.0_04-b20 Java VM: Java HotSpot(TM) Server VM (23.0-b21 mixed mode linux-x86 ) Problematic frame: C [libzip.so+0x47f3] newEntry+0x73 Failed to write core dump.

Writing to a existing xls file using POI

感情迁移 提交于 2019-12-06 06:09:28
The scenario is roughly this: I have a java program with several methods getting called randomly. The first method will create an xls file using apache POI and will put the headers for the columns. All the other methods has to write a record into this file. The final method will first mail the created xls and then delete the xls. For above scenario is the below approach correct: 1) Create the file and put the header names in the first method: Workbook wb = new HSSFWorkbook(); CreationHelper createHelper = wb.getCreationHelper(); Sheet sheet = wb.createSheet("First Sheet"); Row row = sheet

Apache POI-HSSF vs POI-XSSF

给你一囗甜甜゛ 提交于 2019-12-06 05:56:37
HSSF is the POI Project's pure Java implementation of the Excel '97(-2007) file format. XSSF is the POI Project's pure Java implementation of the Excel 2007 OOXML (.xlsx) file format. Are there any export limitations when using HSSF? I've once read somewhere that Excel '97 just supported <65.000 Entries . Is it safe to use HSSF to export excel sheets with more than 65.000 Entries, or why would I use XSSF? As you can see here Excel 97 to 2003 supports a maximum of 65,536 rows. So no, with HSSF you won't be able to store more than 65536 entries. However you can do it with XLSX (Excel 2007+)

How to delete contents of an Excel sheet in Java?

风格不统一 提交于 2019-12-06 05:35:23
How to delete contents of an Excel sheet in an Excel workbook, using Java SE and Apache POI? As mentioned in previous comments Sheet sheet = wb.getSheetAt(0); for (Row row : sheet) { sheet.removeRow(row); } this code throwing ConcurrentModificationException to me. So, I have modified the code and it's working fine. Here is the code: Sheet sheet = wb.getSheetAt(0); Iterator<Row> rowIte = sheet.iterator(); while(rowIte.hasNext()){ rowIte.next(); rowIte.remove(); } I've found that removeSheetAt/createSheet isn't really an acceptable answer, because you can't put the new sheet into the correct

Apache poi - print layout, more than one print area in the same sheet

限于喜欢 提交于 2019-12-06 05:17:40
I'm trying to develop a complex report, and I need to set up the print areas for the excel file. I must divide the xls file in 3 part, but if I do setPrintArea(..) the new area subscribe the old and the result is that I have in the print preview only the last page. How can I set more than one print area? This is the code: protected void createCustomerSheet(String label) { createSheet(label); getCurrentSheet().getPrintSetup().setPaperSize(PrintSetup.A4_PAPERSIZE); getCurrentSheet().getPrintSetup().setFitHeight((short)1); getCurrentSheet().getPrintSetup().setFitWidth((short)1); getCurrentSheet()

apache poi reading date from excel date() function gives wrong date

自作多情 提交于 2019-12-06 05:14:48
Im using an xlsx file that contains a DATE(year, month, day) formula within a cell. This cell is formatted as date, so Excel/OpenOffice shows the proper date. e.g. the cell content is '=DATE(2013;1;1)' which produces : '01.01.2013' So far - so good. When reading this file with the poi library I do: XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File("/home/detlef/temp/test.xlsx"))); XSSFSheet sheet = workbook.getSheet("Sheet A"); XSSFCell cell = sheet.getRow(0).getCell(0); System.out.println(cell.getDateCellValue()); This will print out: Sun Dec 31 00:00:00 CET 1899 I am