Introduction to Apache POI - GeeksforGeeks

10 Dec, 2021
Apache POI is an open-source java library to create and manipulate various file formats based on Microsoft Office. Using POI, one should be able to perform create, modify and display/read operations on the following file formats. For Example, Java doesn’t provide built-in support for working with excel files, so we need to look for open-source APIs for the job. 
Apache POI provides Java API for manipulating various file formats based on the Office Open XML (OOXML) standard and OLE2 standard from Microsoft. Apache POI releases are available under the Apache License (V2.0). 
Some important features of Apache POI are as follows: 
Apache POI provides stream-based processing, that is suitable for large files and requires less memory.
Apache POI is able to handle both XLS and XLSX formats of spreadsheets.
Apache POI contains HSSF implementation for Excel ’97(-2007) file format i.e XLS.
Apache POI XSSF implementation should be used for Excel 2007 OOXML (.xlsx) file format.
Apache POI HSSF and XSSF API provide mechanisms to read, write or modify excel spreadsheets.
Apache POI also provides SXSSF API that is an extension of XSSF to work with very large excel sheets.
SXSSF API requires less memory and is suitable when working with very large spreadsheets and heap memory is limited.
There are two models to choose from – the event model and the user model. The event model requires less memory because the excel file is read in tokens and requires processing. The user model is more object-oriented and easy to use.
Apache POI provides excellent support for additional excel features such as working with Formulas, creating cell styles by filling colors and borders, fonts, headers and footers, data validations, images, hyperlinks, etc.
Commonly used components of Apache POI
HSSF (Horrible Spreadsheet Format): It is used to read and write xls format of MS-Excel files.XSSF (XML Spreadsheet Format): It is used for xlsx file format of MS-Excel.POIFS (Poor Obfuscation Implementation File System): This component is the basic factor of all other POI elements. It is used to read different files explicitly.HWPF (Horrible Word Processor Format): It is used to read and write doc extension files of MS-Word.HSLF (Horrible Slide Layout Format): It is used for read, create, and edit PowerPoint presentations.
HSSF (Horrible Spreadsheet Format): It is used to read and write xls format of MS-Excel files.
XSSF (XML Spreadsheet Format): It is used for xlsx file format of MS-Excel.
POIFS (Poor Obfuscation Implementation File System): This component is the basic factor of all other POI elements. It is used to read different files explicitly.
HWPF (Horrible Word Processor Format): It is used to read and write doc extension files of MS-Word.
HSLF (Horrible Slide Layout Format): It is used for read, create, and edit PowerPoint presentations.
Environment
Apache POI runtime dependencies: If you are working on a maven project, you can include the POI dependency in the pom.xml file using the below set of lines of code.
<dependency> 
    <groupId>org.apache.poi</groupId> 
    <artifactId>poi</artifactId> 
    <version>3.9</version> 
</dependency> 
Now, in order to add this in eclipse, go to 
Window -> Show View -> Other -> Maven -> Maven Repositories
If you are not using maven, then you can download maven jar files from the POI download page. Include the following jar files minimum to run the sample code: 
poi-3.10-FINAL.jar
poi-ooxml-3.10-FINAL.jar
commons-codec-1.5.jar
poi-ooxml-schemas-3.10-FINAL.jar
xml-apis-1.0.b2.jar
stax-api-1.0.1.jar
xmlbeans-2.3.0.jar
dom4j-1.6.1.jar
This article is contributed by Pankaj Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
solankimayank
GBlog
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Roadmap to Become a Web Developer in 2022
DSA Sheet by Love Babbar
GET and POST requests using Python
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Working with csv files in Python
Roadmap to Become a Web Developer in 2022
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to fetch data from an API in ReactJS ?
Installation of Node.js on Linux
Convert a string to an integer in JavaScript