Poi export excel and poiexcel
I. Introduction
HSSF is the implementation of POI project's pure Java Excel97 (-2007) file format. XSSF is a Java implementation of the POI project Excel 2007 OOXML (.xlsx) file format. HSSF and XSSF provides multiple ways to read from, create, modify, read, and write workbooks.
It provides the following functions:
- Provides a low-level structure for Special Needs
- An efficient read-only access event model api
- Provides an api for creating, reading, and modifying xls files.
Project URL: http://poi.apache.org/spreadsheet/index.html.
Ii. Instances
1. related dependencies are as follows:
<dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.12</version></dependency><dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.12</version></dependency>
2. The sample code is as follows:
1 package com. test. excel; 2 3 import java. io. fileOutputStream; 4 import java. util. arrayList; 5 import java. util. list; 6 7 import org. apache. poi. ss. usermodel. cell; 8 import org. apache. poi. ss. usermodel. row; 9 import org. apache. poi. ss. usermodel. sheet; 10 import org. apache. poi. xssf. streaming. SXSSFWorkbook; 11 12/** 13*14 * excle export 15 */16 public class ExcelCreate {17 18/** 19 * excel generate 20 */21 public static void main (String [] args) throws Throwable {22 // header 23 List <String> headerList = new ArrayList <> (10); 24 for (int I = 1; I <= 10; I ++) {25 headerList. add ("Header" + I); 26} 27 28 // data 29 List <String []> dataRowList2 = new ArrayList <String []> (10 ); 30 for (int I = 1; I <= headerList. size (); I ++) {31 dataRowList2.add (new String [] {"data" + I, "data" + I, "data" + I}); 32} 33 34 SXSSFWorkbook workbook = new SXSSFWorkbook (90); 35 Sheet sheet = workbook. createSheet ("Export"); 36 37 int rownum = 0; 38 // header 39 Row row = sheet. createRow (rownum ++); 40 for (int I = 0; I
3. The running result is as follows: