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.

8871 questions
151
votes
21 answers

How can I read numeric strings in Excel cells as string (not numbers)?

I have excel file with such contents: A1: SomeString A2: 2 All fields are set to String format. When I read the file in java using POI, it tells that A2 is in numeric cell format. The problem is that the value in A2 can be 2 or 2.0 (and I want…
joycollector
  • 1,847
  • 4
  • 16
  • 18
127
votes
11 answers

Cannot import XSSF in Apache POI

I am referencing the version 3.7 of the Apache POI and I am getting a "cannot be resolved" error when I do: import org.apache.poi.xssf.usermodel.XSSFWorkbook; Other import statements that reference POI DO NOT give me errors, such as: import…
Mark Jackson
  • 2,337
  • 3
  • 22
  • 21
111
votes
12 answers

Apache POI Excel - how to configure columns to be expanded?

I am using Apache POI API to generate excel spreadsheet to output some data. The problem I am facing is when the spreadsheet is created and opened, columns are not expanded so that some long text like Date formatted text is not showing up on first…
Meow
  • 16,125
  • 50
  • 122
  • 176
105
votes
6 answers

How do I set cell value to Date and apply default Excel date format?

I've been using Apache POI for some time to read existing Excel 2003 files programmatically. Now I have a new requirement to create entire .xls files in-memory (still using Apache POI) and then write them to a file at the end. The only problem…
Jim Tough
  • 13,464
  • 23
  • 66
  • 90
95
votes
4 answers

What is the better API to Reading Excel sheets in java - JXL or Apache POI

Which of the 2 APIs is simpler to read/write/edit excel sheets ? Do these APIs not support CSV extensions ? Using JXL for file.xls and file.xlsx, I get an exception like: jxl.read.biff.BiffException: Unable to recognize OLE stream at…
Swagatika
  • 3,300
  • 5
  • 28
  • 38
84
votes
3 answers

Apache POI Locking Header Rows

Is anyone out there familiar with a way to lock a row in a spreadsheet created with Apache POI 3.7? By locking I mean that I want the title row for the columns to remain visible when the user is scrolling through the rows. My created spreadsheet…
user1795755
75
votes
8 answers

How to read Excel cell having Date with Apache POI?

I'm using Apache POI 3.6, I want to read an excel file which has a date like this 8/23/1991. switch (cell.getCellType()) { ... ... case HSSFCell.CELL_TYPE_NUMERIC: value = "NUMERIC value=" + cell.getNumericCellValue(); break; …
Venkat
  • 2,444
  • 6
  • 23
  • 34
68
votes
5 answers

Java POI : How to read Excel cell value and not the formula computing it?

I am using Apache POI API to getting values from an Excel file. Everything is working great except with cells containing formulas. In fact, the cell.getStringCellValue() is returning the formula used in the cell and not the value of the cell. I…
Aminoss
  • 681
  • 1
  • 5
  • 5
68
votes
5 answers

Merging cells in Excel using Apache POI

Is there any other way to merge cells in Excel using Apache POI library? I was trying using the following, but its not working // selecting the region in Worksheet for merging data CellRangeAddress region = CellRangeAddress.valueOf("A" + rowNo +…
androidDev
  • 1,039
  • 3
  • 12
  • 29
66
votes
12 answers

Cannot get a text value from a numeric cell “Poi”

I'm trying to consume data from a spreadsheet in Excel, but always of this error, already tried formatting the worksheet to text and number and still the error persists. I saw a person using it resolved cell.setCellType ( Cell.CELL_TYPE_STRING ) ;…
Paulo Roberto
  • 1,264
  • 3
  • 17
  • 37
64
votes
5 answers

Setting Column width in Apache POI

I am writing a tool in Java using Apache POI API to convert an XML to MS Excel. In my XML input, I receive the column width in points. But the Apache POI API has a slightly queer logic for setting column width based on font size etc. (refer API…
Arun
  • 649
  • 1
  • 5
  • 3
57
votes
8 answers

Alternative to deprecated getCellType

I'm reading an excel-file (file extension xlsx) using org.apache.poi 3.15. This is my code: try (FileInputStream fileInputStream = new FileInputStream(file); XSSFWorkbook workbook = new XSSFWorkbook(file)) { XSSFSheet sheet =…
user1766169
  • 1,893
  • 3
  • 21
  • 41
54
votes
8 answers

How to insert a row between two rows in an existing excel with HSSF (Apache POI)

Somehow I manage to create new rows between two rows in an existing excel file. The problem is, some of the formatting were not include along the shifting of the rows. One of this, is the row that are hide are not relatively go along during the…
ace
  • 6,507
  • 7
  • 36
  • 46
53
votes
6 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
  • 531
  • 1
  • 4
  • 4
52
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)…
XenoRo
  • 5,581
  • 4
  • 39
  • 54
1
2 3
99 100