https://poi.apache.org/apidocs/dev/org/apache/poi/xssf/streaming/SXSSFWorkbook.html#SXSSFWorkbook-org.apache.poi.xssf.usermodel.XSSFWorkbook-
之前我想写一个这样的方法,将rows写入一个已存在的 SXSSFWorkbook ,方法里面先调用 getLastRowNum() 来获取表格中已有的行数,好多情况下获取不到或不准,现在知道了不能这样写,应该用一个全局变量保存已写入的行数。
* 将行数据写入Workbook
* @param wb
* @param rows
* @return
private void writeToWorkbook(Workbook wb, List<List<String>> rows) {
// 获取sheet
Sheet sheet = wb.getSheetAt(0);
int lastRowNum = sheet.getLastRowNum(); //经常为0
// 写入excel
for (int i = 0, rowCount = rows.size(); i < rowCount; i++) {
Row row = sheet.createRow(lastRowNum++);
List<String> rowData = rows.get(i);
for (int j = 0, colCount = rowData.size(); j < colCount; j++) {
logger.info(rowData.get(j));
row.createCell(j).setCellValue(rowData.get(j));
改成下面这样写就好了,多一个起始行数参数:
* 将行数据写入Workbook
* @param wb
* @param lastRowNum wb中已有行数
* @param rows
private int writeToWorkbook(Workbook wb, int lastRowNum, List<List<String>> rows) {
// 获取sheet
Sheet sheet = wb.getSheetAt(0);
// 写入excel
for (int i = 0, rowCount = rows.size(); i < rowCount; i++) {
Row row = sheet.createRow(lastRowNum++);
List<String> rowData = rows.get(i);
for (int j = 0, colCount = rowData.size(); j < colCount; j++) {
logger.info(rowData.get(j));
row.createCell(j).setCellValue(rowData.get(j));
return lastRowNum;
POI-处理大EXCEL文件(XLSX写)
https://www.cnblogs.com/resentment/p/6414210.html
Read xlsx file with POI (SXSSFWorkbook)
https://stackoverflow.com/questions/13873489/read-xlsx-file-with-poi-sxssfworkbook
Reading data from xlsx with Apache POI’s SXSSFSheet
https://stackoverflow.com/questions/12513981/reading-data-from-xlsx-with-apache-pois-sxssfsheet
Apache POI getRow() returns null and .createRow fails
https://stackoverflow.com/questions/30868325/apache-poi-getrow-returns-null-and-createrow-fails
SXSSFWorkbook XSSFWorkbook 我所遇到的坑大集合,希望能帮助更多的人。
https://blog.csdn.net/qq_31615049/article/details/82228812
使用poi读取excel时,getRow()方法返回null
https://www.cnblogs.com/study-room/p/5459363.html
SXSSFSheet对象调用getLastRowNum的问题
https://blog.csdn.net/zc123456zzc/article/details/47301461
https://poi.apache.org/apidocs/dev/org/apache/poi/xssf/usermodel/XSSFWorkbook.html
Class SXSSFWorkbook
https://poi.apache.org/apidocs/dev/org/apache/poi/xssf/streaming/SXSSFWorkbook.html
Class SXSSFSheet
https://poi.apache.org/apidocs/dev/org/apache/poi/xssf/streaming/SXSSFSheet.html
- tabula-java 从pdf提取表格
- 问题
- OLE2NotOfficeXmlFileException
- Strict OOXML isn’t currently supported
- POI 读 docx 文件报错 Zip bomb detected
- 单元格最大内容长度为32767字符错误
- POI 删除 doc/docx 页眉页脚
- doc HWPFDocument 删除页眉页脚
- POI 无法读取 word 中的自动编号
- SXSSFWorkbook 处理超大Excel
- HSSFWorkbook/XSSFWorkbook/SXSSFWorkbook 区别
- SXSSFSheet有数据但getLastRowNum值为0问题
- 常用类