使用jxl时,文件损坏是怎么回事?
今天在学习使用jxl修改excel。第一次执行的时候,程序是正常运行,但第二次的时候文件就损坏了。代码如下:
public class ExcelWrite { @Test public void read() throws Exception { Workbook wb = Workbook.getWorkbook(new File("开通账号.xls")); WritableWorkbook book = Workbook.createWorkbook(new File("开通账号.xls"), wb); Sheet sht = wb.getSheet(0); WritableSheet sheet = book.getSheet(0); Cell[] numCells = sht.getColumn(0); List<String> names = new ArrayList<String>(); for (int i = 1; i < numCells.length; i++) { names.add(numCells[i].getContents()); } for (String s : names) { System.out.println(2 << 3); } book.close(); } }
异常:
java.lang.ArrayIndexOutOfBoundsException: 0 at jxl.read.biff.BOFRecord.<init>(BOFRecord.java:81) at jxl.read.biff.WorkbookParser.parse(WorkbookParser.java:548) at jxl.Workbook.getWorkbook(Workbook.java:237) at jxl.Workbook.getWorkbook(Workbook.java:198) at com.ceprei.mis.service.ExcelWrite.read(ExcelWrite.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最近遇到这异常,我的情况是给标题加了背景颜色导致,jxl对有些样式支持不好,清除格式试下吧。
java.lang.ArrayIndexOutOfBoundsException:0,越界了,看下异常,指向哪行代码
java.lang.ArrayIndexOutOfBoundsException:0