Questions tagged [apache-poi]

Apache POI is a Java library for reading and writing various Microsoft file formats, especially Office related ones. It supports OLE2 and OOXML based formats, such as XLS, XLSX, DOC, DOCX, PPT and PPTX as well as a few others.

The mission statement of the Apache POI project 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). This includes Excel formats (.xls and .xlsx), Word (.doc and .docx), PowerPoint (.ppt and .pptx), as well as others to a lesser extent like Visio, Outlook and Publisher.

This tag should be used for questions around using and extending Apache POI. Questions on the .Net port should use the tag instead.

More information on Apache POI, the bug tracker and download links are available from https://poi.apache.org/

If you are starting with Apache POI, you may find the Busy Developer's link very useful : https://poi.apache.org/spreadsheet/quick-guide.html

Apache POI releases are available under the Apache License, Version 2.0.

9727 questions
31
votes
9 answers

Merge and align center cell using apache poi

I want to export data to excel using Apache poi. Now the problem that I am facing is that I am unable to merge rows and align them in the center. Code for export data is: List> lstReportHeader = null; HSSFWorkbook wb =…
shrey
  • 833
  • 1
  • 7
  • 15
31
votes
4 answers

How to speed up autosizing columns in apache POI?

I use the following code in order to autosize columns in my spreadsheet: for (int i = 0; i < columns.size(); i++) { sheet.autoSizeColumn(i, true); sheet.setColumnWidth(i, sheet.getColumnWidth(i) + 600); } The problem is it takes more than 10…
antken
  • 919
  • 1
  • 10
  • 12
31
votes
1 answer

Can't Set Fill Color Apache POI Excel Workbook

I have scanned this forum over and over and tried every method mentioned on here and still can't get Apache POI to change to fill background color of my excel document. Here is my code: errorOccured = true; XSSFCellStyle cs =…
Richie Episcopo
  • 383
  • 1
  • 3
  • 15
31
votes
1 answer

How to change font color of particular cell apache poi 3.9

I can change foreground color with the following code in apache POI. Now I want to change font color of a single cell. CellStyle style = wb.createCellStyle(); style.setFillForegroundColor(IndexedColors.GREEN.getIndex()); …
H4SN
  • 1,482
  • 3
  • 24
  • 43
30
votes
8 answers

Java:using apache POI how to convert ms word file to pdf?

By using apache POI how to convert ms word file to pdf? I an using the following code but its not working giving errors I guess I am importing the wrong classes? import java.io.File; import java.io.FileInputStream; import…
Harinder
  • 11,776
  • 16
  • 70
  • 126
30
votes
3 answers

Java POI the supplied data appears to be in the Office 2007+ XML

I am getting this error: org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of…
Marco Dinatsoli
  • 10,322
  • 37
  • 139
  • 253
30
votes
7 answers

Removing a row from an Excel sheet with Apache POI HSSF

I'm using the Apache POi HSSF library to import info into my application. The problem is that the files have some extra/empty rows that need to be removed first before parsing. There's not a HSSFSheet.removeRow( int rowNum ) method. Only removeRow(…
fmaste
  • 383
  • 1
  • 5
  • 7
29
votes
1 answer

Apache POI Streaming (SXSSF) for Reading

I need to read large excel files and import their data to my application. Since POI takes up a large amount of heap to work, often throwing OutOfMemory errors, I found out that there is a Streaming API for handling excel data in a serial fashion…
bruno_cw
  • 994
  • 1
  • 8
  • 22
29
votes
5 answers

Java Apache POI Excel save as PDF

How can I convert/save excel file to pdf? I'm using java play framework to generate some excel files and now the requirement changes to pdf. I don't want to recode everything. Is there a way to convert to pdf? The excel files I'm generating are…
Oscar Yuandinata
  • 1,025
  • 1
  • 13
  • 31
28
votes
1 answer

Problem in fitting the excel cell size to the size of the content when using apache poi

I am beginner to Apache POI api. I am trying to create excel sheet using arraylist. My java code is as follows. HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("new sheet"); HSSFCellStyle style =…
mvg
  • 1,574
  • 4
  • 37
  • 63
28
votes
3 answers

org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException:

I'm using the following jar files: dom4j-1.6.1.jar poi-3.9-20121203.jar poi-ooxml-3.9-20121203.jar poi-ooxml-schemas-3.9-20121203.jar xmlbeans-2.3.0.jar Code: package ExcelTest; import java.io.File; import java.io.FileInputStream; import…
Learner
  • 945
  • 11
  • 23
  • 38
26
votes
5 answers

Cell vertical top alignment using poi

I am using POI api. Now my problem is that I am not able to align cell text vertically top.I am using getCellStyle().setAlignment(HSSFCellStyle.VERTICAL_TOP) to set alignment . Yet when I open sheet it is not impacted.
sahab singh
  • 351
  • 2
  • 4
  • 8
26
votes
10 answers

Getting Exception(org.apache.poi.openxml4j.exception - no content type [M1.13]) when reading xlsx file using Apache POI?

i'm using Apache POI(XSSF API) for reading xlsx file.when i tried to read file.i got the following error: org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part…
Sameek Mishra
  • 9,174
  • 31
  • 92
  • 118
26
votes
5 answers

Changing cell color using apache poi

I'm using Apache POI to read data in a spreadsheet of part numbers. I look up the part number in our database, if we have a CAD drawing of the part I color the part number cell green, if we don't I color it red. After the processing is done the…
Striker
  • 339
  • 1
  • 3
  • 13
25
votes
4 answers

NoClassDefFoundError: Could not initialize class sun.awt.X11FontManager

when we migrated from Oracle JDK-8 to Open JDK-11, Apache POI excel generation has issues tried already -Djava.awt.headless=true org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is…
PCB
  • 638
  • 1
  • 11
  • 22