如果用XSSFWorkbook 来读取excel,遇到文件太大时候,会导致oom, OutOfMemoryError: Java heap space
所以apache官网上有推荐
If memory footprint is an issue, then for XSSF, you can get at the underlying XML data, and process it yourself.
http://poi.apache.org/spreadsheet/how-to.html#xssf_sax_api
通过xml的方式读取excel,一行一行的处理,也不需要将整个文件载入,导致内存不足情况
带注释的官网例子:
package com.datacenter.hbase.adapter;
import java.io.InputStream;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.poi.xssf.eventusermodel.XSSFReader;
import org.apache.poi.xssf.eventusermodel.XSSFReader.SheetIterator;
import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.openxm