环境配置
首先要再maven的 pom.xml 中导入 poi,poi-ooxml , poi-ooxml-schemas 这三个依赖
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.9</version>
</dependency>
```
# 入门示例
```java
public class LearnPOI {
public static void main(String[] args) throws IOException {
SXSSFWorkbook workbook = new SXSSFWorkbook();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
int cnt = 0;
SXSSFSheet sheet = (SXSSFSheet) workbook.createSheet("0");
for(int i=0; i<20000;i++){
if(i%10000==0 && i!=0){
sheet = (SXSSFSheet) workbook.createSheet(String.valueOf(i));
cnt = 0;
}
SXSSFRow row = (SXSSFRow) sheet.createRow(cnt);
row.createCell(0).setCellValue(df.format(new Date()));
cnt++;
}
FileOutputStream fileOutputStream = new FileOutputStream("Martin.xlsx");
workbook.write(fileOutputStream);
fileOutputStream.close();
}
}