# Tutorial ## Docs - [https://poix.readthedocs.io](https://poix.readthedocs.io) ## Getting Started ![](https://s0.wailian.download/2019/07/23/apache-poi-min-min.png) Step 1: Download ``` git clone https://github.com/T5750/poi-repositories.git cd poi-repositories ``` Step 2: Start Server ``` docker-compose up -d # or mvn clean spring-boot:run ``` [http://localhost:8080/poi](http://localhost:8080/poi) ### Tests - `TestReadExcel`, `TestReadExcelDemo` - `TestExportExcel`, `TestExportExcel2007`, `TestWriteExcelDemo` - `TestTemplate`, `TestExcelReplace` - `CalendarDemo` - `TestExcelFormulaDemo`, `TestExcelStylingDemo`, `TestAll` ### Runtime Environment - [Java 8](https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html) - [Spring Framework 5.x](https://spring.io/projects/spring-framework) - [Spring Boot 2.x](https://spring.io/projects/spring-boot) - [Derby 10.x](https://db.apache.org/derby/) - [Hibernate ORM 5.x](http://hibernate.org/orm) - [POI 5.x](https://poi.apache.org/download.html) - [Bootstrap 4.x](https://github.com/twbs/bootstrap) - [Docker 19.x](https://www.docker.com/) ### Classes 1. **HSSF, XSSF and XSSF classes** Apache POI main classes usually start with either **HSSF**, **XSSF** or **SXSSF**. - **HSSF** – is the POI Project’s pure Java implementation of the Excel ’97(-2007) file format. e.g. [HSSFWorkbook](https://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFWorkbook.html), [HSSFSheet](https://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFSheet.html). - **XSSF** – is the POI Project’s pure Java implementation of the Excel 2007 OOXML (.xlsx) file format. e.g. [XSSFWorkbook](https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFWorkbook.html), [XSSFSheet](https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFSheet.html). - **SXSSF** (since 3.8-beta3) – is an API-compatible streaming extension of XSSF to be used when very large spreadsheets have to be produced, and heap space is limited. e.g. [SXSSFWorkbook](https://poi.apache.org/apidocs/org/apache/poi/xssf/streaming/SXSSFWorkbook.html), [SXSSFSheet](https://poi.apache.org/apidocs/org/apache/poi/xssf/streaming/SXSSFSheet.html). SXSSF achieves its **low memory footprint by limiting access to the rows that are within a sliding window**, while XSSF gives access to all rows in the document. 2. **Row and Cell** Apart from above classes, [Row](https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/Row.html) and [Cell](https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/Cell.html) are used to interact with a particular row and a particular cell in excel sheet. 3. **Style Classes** A wide range of classes like [CellStyle](https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/CellStyle.html), [BuiltinFormats](https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/BuiltinFormats.html), [ComparisonOperator](https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/ComparisonOperator.html), [ConditionalFormattingRule](https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/ConditionalFormattingRule.html), [FontFormatting](https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/FontFormatting.html), [IndexedColors](https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/IndexedColors.html), [PatternFormatting](https://poi.apache.org/apidocs/org/apache/poi/hssf/record/cf/PatternFormatting.html), [SheetConditionalFormatting](https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/SheetConditionalFormatting.html) etc. are used when you have to add formatting in a sheet, mostly based on some rules. 4. **FormulaEvaluator** Another useful class **FormulaEvaluator** is used to evaluate the formula cells in excel sheet. ### Write an excel file 1. Create a workbook 3. Create a sheet in workbook 4. Create a row in sheet 5. Add cells in sheet 6. Repeat step 3 and 4 to write more data ### Read an excel file 1. Create workbook instance from excel sheet 3. Get to the desired sheet 4. Increment row number 5. iterate over all cells in a row 6. repeat step 3 and 4 until all data is read ## Getting Help Having trouble with T5750's POI? We’d like to help! - Ask a question on [CSDN](https://blog.csdn.net/evangel_z/article/details/7332535). - Report bugs at [https://github.com/T5750/poi/issues](https://github.com/T5750/poi/issues). ## Branch - View POI 3.x branch at [https://github.com/T5750/poi/tree/poi3](https://github.com/T5750/poi/tree/poi3). - View servlet branch at [https://github.com/T5750/poi/tree/servlet](https://github.com/T5750/poi/tree/servlet). ## References - [Java POI导出EXCEL经典实现 Java导出Excel弹出下载框](https://blog.csdn.net/evangel_z/article/details/7332535) - [Java POI读取Office excel (2003,2007)及相关jar包](https://blog.csdn.net/evangel_z/article/details/7312050) - [HSSF and XSSF Examples](http://poi.apache.org/spreadsheet/examples.html) - [Apache POI – Read and Write Excel File in Java](https://howtodoinjava.com/library/readingwriting-excel-files-in-java-poi-tutorial/) ## License This project is Open Source software released under the [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0.html).