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
58
votes
8 answers

Apache POI error loading XSSFWorkbook class

I'm trying to write a program that works with Excel docs, but the HSSF format is too small for my requirements. I'm attempting to move to XSSF, but I keep getting errors when trying to use it. I managed to solve the first two by adding…
Cameron Zach
  • 581
  • 1
  • 4
  • 4
57
votes
8 answers

How to load a large xlsx file with Apache POI?

I have a large .xlsx file (141 MB, containing 293413 lines with 62 columns each) I need to perform some operations within. I am having problems with loading this file (OutOfMemoryError), as POI has a large memory footprint on XSSF (xlsx)…
CosmicGiant
  • 6,275
  • 5
  • 43
  • 58
55
votes
11 answers

Replacing a text in Apache POI XWPF

I just found Apache POI library very useful for editing Word files using Java. Specifically, I want to edit a DOCX file using Apache POI's XWPF classes. I found no proper method / documentation following which I could do this. Can somebody please…
Gagan93
  • 1,826
  • 2
  • 25
  • 38
55
votes
7 answers

How to get row count in an Excel file using POI library?

Guys I'm currently using the POI 3.9 library to work with excel files. I know of the getLastRowNum() function, which returns a number of rows in an Excel file. The only problem is getLastRowNum() returns a number with the count starting from 0. So…
Ahmad
  • 12,886
  • 30
  • 93
  • 146
55
votes
5 answers

Setting filter on headers of an Excel sheet via POI

I generate a sheet, pretty bog standard headers and columns of data. I want to turn on the "Filter" function for the sheet, so the user can easily sort and filter the data. Can I so this using POI?
Anders Johansen
  • 10,165
  • 7
  • 35
  • 52
52
votes
8 answers

Add borders to cells in POI generated Excel File

I am using POI to generate an Excel File. I need to add borders to specific cells in the worksheet. How can I accomplish this?
jzd
  • 23,473
  • 9
  • 54
  • 76
52
votes
12 answers

How to check if an excel cell is empty using Apache POI?

I am taking input from an excel sheet using Poi.jar and wanted to know how to check if a cell is empty or not. Right now I m using the below code. cell = myRow.getCell(3); if (cell != null) { cell.setCellType(Cell.CELL_TYPE_STRING); …
user1312312
  • 605
  • 1
  • 8
  • 16
51
votes
3 answers

Setting foreground color for HSSFCellStyle is always coming out black

I am using POI to create an Excel spreadsheet in Java. I have the following code used for creating a header row: HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Report"); // some more code HSSFRow row =…
Ascalonian
  • 14,409
  • 18
  • 71
  • 103
49
votes
3 answers

get number of columns of a particular row in given excel using Java

I want the number of columns of a particular row in excel. How is that possible? I used POI API but I could get only columns count to 7 . try { fileInputStream = new FileInputStream(file); workbook =…
muthukumar
  • 2,233
  • 3
  • 23
  • 30
48
votes
6 answers

Apache POI XSSFColor from hex code

I want to set the foreground color of a cell to a given color in hex code. For example, when I try to set it to red: style.setFillForegroundColor(new XSSFColor(Color.decode("#FF0000")).getIndexed()); No matter what Hex value I set in the parameter…
Neets
  • 4,094
  • 10
  • 34
  • 46
47
votes
7 answers

Writing a large resultset to an Excel file using POI

This is sort of inline w/ Writing a large ResultSet to a File but the file in question is an Excel file. I'm using the Apache POI library to write an Excel file with a large data set retrieved from a ResultSet object. The data could range from a few…
Ranga
  • 618
  • 1
  • 8
  • 14
46
votes
11 answers

Auto size height for rows in Apache POI

I am inputting values into a spreadsheet using Apache POI. These values have newlines, and I was able to use this code successfully: CellStyle style = cell.getCellStyle() style.setWrapText(true) cell.setCellStyle(style) Unfortunately, while the…
user1007895
  • 3,925
  • 11
  • 41
  • 63
46
votes
2 answers

Display percentage values in Excel using POI API

I need to display a value in an excel cell formatted like a percentage, e.g. like 12.3%. By default the value is displayed as Text, but I need to display it as a number. What is the appropriate method to achieve this?
nagireddy
  • 491
  • 2
  • 6
  • 6
46
votes
12 answers

How to determine empty row?

How I can determine empty rows in .xls documents using Apache POI?
WelcomeTo
  • 19,843
  • 53
  • 170
  • 286
45
votes
9 answers

How to get an Excel Blank Cell Value in Apache POI?

I have a huge excel file with tons of columns which looks like this :- Column1 Column2 Column3 Column4 Column5 abc def ghi mno pqr ...... This is the code that I wrote to print these values: try { …
user607429
  • 451
  • 1
  • 4
  • 4