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
20
votes
6 answers

How to get more than 255 columns in an excel sheet using Apache POI 3.6

I'm creating a calendar in excel. Column 1 is 01.01.2010 (dd.MM.yyyy), Column 2 is 02.01.2010 and so on. This is my code: int day_cell = 0; for(int i = 0; i < days.size(); i++) { Date day = days.get(i); HSSFCell cell =…
Tommy
  • 4,011
  • 9
  • 37
  • 59
20
votes
4 answers

java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException

In order to read an xlsx file I'm using apache POI, I've downloaded the zip and placed the following jsrs in my servlet location webcontent/web-inf/lib and configured build path through eclipse and my code looks as follows, import…
user1733583
19
votes
4 answers

How to loop through all the rows and cells in an excel file

I want to use foreach to iterate through all the cells in my excel file in order to set a single foreground color. This is what I have so far. HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Sheet1"); sheet =…
user582485
  • 509
  • 3
  • 13
  • 23
19
votes
1 answer

Lock single column in Excel using Apache POI

I want to create a Excel in which only a specific column is locked(Read-only), and the rest are editable, I am using the following approach, but that doesn't seem to work. Create two CellStyles, one with setLocked(true) and other with…
shams.haq
  • 703
  • 1
  • 6
  • 20
19
votes
8 answers

Apache POI XSSF reading in excel files

I just have a quick question about how to read in an xlsx file using the XSSF format from Apache. Right now my code looks like this: InputStream fs = new FileInputStream(filename); // (1) XSSFWorkbook wb = new XSSFWorkbook(fs); //…
Andrew
  • 191
  • 1
  • 1
  • 3
19
votes
4 answers

Java Apache Poi, how to set background color and borders at same time

at start i want to say that i'm totally new in developers world. I tried to generate an excel sheet that contains Mutiplication Table with borders and set background color but only for 1st column and row. Here is a correct Example: correct…
Robert Lewandowski
  • 213
  • 1
  • 2
  • 8
19
votes
2 answers

How can it set the file for "Fit all columns on one page" setting

I have a requirement where files generated by Apache POI need to produce a fie with the fit all columns on one page setting set. I've tried a bunch of variations with the API but so far I haven't been able to do it. Nor can I really find if it can…
superbAfterSemperPhi
  • 1,292
  • 1
  • 14
  • 27
19
votes
3 answers

Apache POI getRow() returns null and .createRow fails

I have the following problem using Apache POI v3.12: I need to use a XLSX file with 49 rows [0..48] as a template, fill it's cells with data and write it out as a different file, so I can reuse the template again. What I am doing is approximately…
Plamen Vasilev
  • 304
  • 1
  • 2
  • 6
19
votes
1 answer

Auto wrap in apache POI (Excel)

I have a java program which takes header and data as the input and produces an excel file. However, sometimes when the header values are long and the number of columns are more, my excel sheet tends to be unnecessarily wide. Because of the…
Vicky
  • 16,679
  • 54
  • 139
  • 232
19
votes
2 answers

Open EXISTING xls in Apache POI

I have an existing file (C:\wb.xls) that I want to open and make changes to. How in Apachie POI do you open an existing file? All the documentation that I find has to go with creating a new file. And if you know, how do you insert a new row at…
Marco Polo
  • 267
  • 1
  • 5
  • 16
19
votes
3 answers

Convert xlsx to csv with Apache POI API

I am trying to convert .xlsx file to .csv, convertion is happening but the data is not formatted properly. Please find code below and suggest changes to the code. Here I am trying to read an .xlsx file and write it to a csv file i.e. converting…
user2335416
  • 311
  • 2
  • 4
  • 11
19
votes
1 answer

apache poi apply one style to different workbooks

I'm trying to apply one cell style to defferent woekbooks. It works well, when I apply it to first workbook, but when I'm trying to do this with second and next workbooks - no style is applied and the following exception is thrown. Exception in…
mr.nothing
  • 5,141
  • 10
  • 53
  • 77
18
votes
2 answers

Right-align cell content in Apache POI

I am trying to align text. However, the text is not aligned. Cell lastCell = lastCell = row.createCell(cellNumber++); if (value != null) { lastCell.setCellValue(value); } CellStyle cellStyle =…
user6583549
18
votes
0 answers

how to copy one workbook sheet to another workbook sheet using apache POI and java

I have one excel file with single sheet (abstract model). Now I want to copy the sheet to another existing workbook. How can I do this?
Saravanan
  • 11,372
  • 43
  • 143
  • 213
18
votes
6 answers

Matching Excel's floating point in Java

I have an .xlsx spreadsheet with a single number in the top-left cell of sheet 1. The Excel UI displays: -130.98999999999 This is visible in the formula bar, i.e. not affected by the number of decimal places the containing cell is set to show. It's…
David North
  • 1,247
  • 1
  • 14
  • 32