fix readBySax for xls not support sheetName

This commit is contained in:
Looly
2021-05-25 01:59:29 +08:00
parent c5887344e9
commit 9c290c4bcc
7 changed files with 174 additions and 57 deletions

View File

@@ -9,6 +9,7 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.cell.FormulaCellValue;
import cn.hutool.poi.excel.sax.Excel03SaxReader;
import cn.hutool.poi.excel.sax.handler.RowHandler;
import cn.hutool.poi.exceptions.POIException;
import org.apache.poi.ss.usermodel.CellStyle;
import org.junit.Assert;
import org.junit.Ignore;
@@ -41,10 +42,24 @@ public class ExcelSaxReadTest {
public void excel03Test() {
Excel03SaxReader reader = new Excel03SaxReader(createRowHandler());
reader.read("aaa.xls", 1);
// Console.log("Sheet index: [{}], Sheet name: [{}]", reader.getSheetIndex(), reader.getSheetName());
ExcelUtil.readBySax("aaa.xls", 1, createRowHandler());
}
@Test
public void excel03ByNameTest() {
Excel03SaxReader reader = new Excel03SaxReader(createRowHandler());
reader.read("aaa.xls", "校园入学");
}
@Test(expected = POIException.class)
public void excel03ByNameErrorTest() {
// sheet名称不存在则报错
Excel03SaxReader reader = new Excel03SaxReader(createRowHandler());
reader.read("aaa.xls", "校园入学1");
}
@Test
@Ignore
public void readBlankLineTest() {
@@ -124,7 +139,6 @@ public class ExcelSaxReadTest {
@Test
public void formulaRead03Test() {
Console.log(FileUtil.file("data_for_sax_test.xls"));
List<Object> rows = new ArrayList<>();
ExcelUtil.readBySax("data_for_sax_test.xls", -1, (i, i1, list) -> {
if(list.size() > 1){