这是我的测试用例:
import java.io.File;
import java.io.IOException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.junit.Before;
import org.junit.Test;
public class TestWB {
File sourceA;
File sourceB;
@Before
public void setUp() throws Exception {
sourceA = new File("C:\\junit\\sourceA.xls");
sourceB = new File("C:\\junit\\sourceB.xls");
}
@Test
public final void testValid() {
try {
Workbook wb = WorkbookFactory.create(sourceA);
} catch (InvalidFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
public final void testInValid() {
try {
Workbook wb = WorkbookFactory.create(sourceB);
} catch (InvalidFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
在sourceA.xls传递并加载的地方,SourceB.xls很麻烦。这是异常代码:
java.lang.RuntimeException: Unexpected record type (org.apache.poi.hssf.record.StringRecord)
at org.apache.poi.hssf.record.aggregates.RowRecordsAggregate.<init>(RowRecordsAggregate.java:97)
at org.apache.poi.hssf.model.InternalSheet.<init>(InternalSheet.java:172)
at org.apache.poi.hssf.model.InternalSheet.createSheet(InternalSheet.java:127)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:291)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:88)
at TestWB.testInValid(TestWB.java:35)
...
如果我打开xls - 据我所知改变什么 - 保存它。它应该工作。 如果没有用户的手动操作(打开 - 保存 - 关闭)
,如何解决此问题谢谢