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
45
votes
7 answers

How to set formulas in cells using Apache POI?

I am currently using Apache POI for Java to set formulas in cells. But after I run the program and open the Excel file that I created and processed, the cells with the formula include the formula as a string, rather than the value the formula should…
vamsi
  • 461
  • 1
  • 5
  • 7
41
votes
2 answers

Using Apache POI HSSF, how can I refresh all formula cells at once?

I am filling cells of an Excel file using Apache POI, and there are a lot of formula cells in the document. However, their values are not refreshed when I open the document in Excel. It's my understanding that I need to use a FormulaEvaluator to…
zneak
  • 134,922
  • 42
  • 253
  • 328
40
votes
9 answers

Processing large xlsx file

I need to auto-fit all rows in large (30k+ rows) xlsx file. The following code via apache poi works on small files, but goes out with OutOfMemoryError on large ones: Workbook workbook = WorkbookFactory.create(inputStream); Sheet sheet =…
miah
  • 8,190
  • 2
  • 24
  • 23
39
votes
6 answers

POI setting Cell Background to a Custom Color

I want to set custom color to a cell's background. I use HSSFWorkbook (can't use anything else). HSSFPalette palette = aWorkBook.getCustomPalette(); Color col = new Color(backgroundColor); HSSFColor myColor =…
kenny
  • 2,000
  • 6
  • 28
  • 38
36
votes
2 answers

How can I create a simple docx file with Apache POI?

I'm searching for a simple example code or a complete tutorial how to create a docx file with Apache POI and its underlying openxml4j. I tried the following code (with a lot of help from the Content Assist, thanks Eclipse!) but the code does not…
guerda
  • 23,388
  • 27
  • 97
  • 146
36
votes
3 answers

Multiline text in Excel cells

I'm trying to write multiline text to excel cells. cell.setCellValue("line1 \n line2"); But when I open the document, I see only one line until I double-click it for editing, then it becomes two-lined. Why is it so? Thanks
Timofei Davydik
  • 7,244
  • 7
  • 33
  • 59
35
votes
10 answers

How to Cache InputStream for Multiple Use

I have an InputStream of a file and i use apache poi components to read from it like this: POIFSFileSystem fileSystem = new POIFSFileSystem(inputStream); The problem is that i need to use the same stream multiple times and the POIFSFileSystem…
Azder
  • 4,698
  • 7
  • 37
  • 57
35
votes
15 answers

Required maven dependencies for Apache POI to work

I want to use Apache POI library to parse excel files (old versions and newer versions of excel). So I was wondering what jars do i need to include from the Apache POI because in following link: http://mvnrepository.com/artifact/org.apache.poi I…
Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498
35
votes
4 answers

Basic Excel currency format with Apache POI

I'm able to get cells to format as Dates, but I've been unable to get cells to format as currency... Anyone have an example of how to create a style to get this to work? My code below show the styles I'm creating... the styleDateFormat works like a…
Dave K
  • 1,674
  • 4
  • 16
  • 22
35
votes
5 answers

Damaged file handling

I would like to know if anyone has any advice on handling damaged files with Apache POI I am trying to open a file and am receiving this message: Exception in thread "main" org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException:…
Farmer Joe
  • 6,020
  • 1
  • 30
  • 40
35
votes
3 answers

is it possible to change sheet name with apache poi MS excel java android

is there any way to update existing sheet name of MS Excel file knowing that I am using apache poi in my android app I can create a sheet with my custom name HSSFSheet sheet = workbook.createSheet("my custom name"); but when I want to copy…
funfordevelopping
  • 383
  • 1
  • 3
  • 7
34
votes
2 answers

How to insert a linebreak as the data of a cell using Apache POI?

I use Apache POI 3.16 to create an Excel file. I want to set the data inside a particular cell to have a linebreak : rowConsommationEtRealisation.createCell(0).setCellValue("Consommation (crédits)\r\nRéalisation (produits)"); When I open the file…
pheromix
  • 18,213
  • 29
  • 88
  • 158
33
votes
10 answers

Converting docx into pdf in java

I am trying to convert a docx file which contains table and images into a pdf format file. I have been searching everywhere but did not get proper solution, request to give proper and correct solution: here what i have tried : import…
user1999397
32
votes
5 answers

Reading date values from excel cell using POI HSSF API

I'm using POI HSSF API for my excel manipulations in Java. I've a date value "8/1/2009" in one of my excel cell and while I try to read this value using HSSF API, it detects the cell type as Numeric and returns the 'Double' value of my date. See the…
Veera
  • 32,532
  • 36
  • 98
  • 137
32
votes
10 answers

Apache POI autoSizeColumn Resizes Incorrectly

I'm using Apache POI in java to create an excel file. I fill in the data then try to autosize each column, however the sizes are always wrong (and I think consistent). The first two rows are always(?) completely collapsed. When I autosize the…
Jaws212
  • 750
  • 2
  • 7
  • 18