Kev*_*rey 7 java api excel jxl jexcelapi
我正在处理一些相当复杂的excel文件,并遇到了复制工作表的问题.每当我尝试复制不完全空白的工作表时,我都会收到以下消息:
Exception in thread "main" java.lang.NullPointerException
at jxl.write.biff.WritableSheetCopier.shallowCopyCells(WritableSheetCopier.java:499)
at jxl.write.biff.WritableSheetCopier.copySheet(WritableSheetCopier.java:239)
at jxl.write.biff.WritableSheetImpl.copy(WritableSheetImpl.java:1622)
at jxl.write.biff.WritableWorkbookImpl.copySheet(WritableWorkbookImpl.java:987)
at excelCalc.main(excelCalc.java:18)
Run Code Online (Sandbox Code Playgroud)
我想知道这里的问题是什么.为什么会有一个".copySheet("函数,如果它不能用于包含信息的工作表.为了尝试以更简单的比例重现问题,我创建了你在下面看到的代码.我希望输出看是2个相同的表格,单元格(0,0)的标签是"test".一个名为"Flows"的表格,另一个是"复制".有关为何给出这个空指针的任何想法?
import java.io.File;
import jxl.*;
import jxl.write.*;
public class excelCalc
{
public static void main(String[] args) throws Exception
{
WritableWorkbook outputBook = Workbook.createWorkbook(new File("C:/Users/Kevin Brey/CS243/ExcelTest/files/output", "output.xls"));
WritableSheet rSheet = outputBook.createSheet("Flows", 0);
rSheet.addCell(new Label(0, 0, "test"));
outputBook.copySheet(0, "copy", 0);
outputBook.write();
outputBook.close();
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:此代码也提供相同的异常:
import java.io.File;
import jxl.*;
import jxl.write.*;
public class excelCalc
{
public static void main(String[] args) throws Exception
{
WritableWorkbook outputBook = Workbook.createWorkbook(new File("C:/Users/Kevin Brey/CS243/ExcelTest/files/output", "output.xls"));
WritableSheet sheet1 = outputBook.createSheet("Sheet1", 0);
WritableSheet sheet2 = outputBook.createSheet("Sheet2", 1);
sheet1.addCell(new Label(0, 0, "Label1"));
sheet2.addCell(new Label(0, 0, "Label2"));
outputBook.copySheet(0, "Copy", 1);
outputBook.write();
outputBook.close();
}
}
Run Code Online (Sandbox Code Playgroud)
我对可能出错的一个想法是,由于工作表已打开并已编辑,因此无法复制.我真的不知道如何解决这个问题.
小智 10
这是jxl-2.6.12.jar中的一个错误,请使用jxl-2.6.10.jar.
细节:
拼写'&&'成'''
第493行 - WritableSheetCopier.java中的第504行
if (c != null)
{
toSheet.addCell(c);
// Cell.setCellFeatures short circuits when the cell is copied,
// so make sure the copy logic handles the validated cells
if (c.getCellFeatures() != null &
c.getCellFeatures().hasDataValidation())
{
validatedCells.add(c);
}
}
Run Code Online (Sandbox Code Playgroud)
第540行 - WritableSheetCopier.java中的第551行
if (c != null)
{
toSheet.addCell(c);
// Cell.setCellFeatures short circuits when the cell is copied,
// so make sure the copy logic handles the validated cells
if (c.getCellFeatures() != null &
c.getCellFeatures().hasDataValidation())
{
validatedCells.add(c);
}
}
Run Code Online (Sandbox Code Playgroud)
第990行 - SheetCopier.java中的第1001行
if (c != null)
{
toSheet.addCell(c);
// Cell.setCellFeatures short circuits when the cell is copied,
// so make sure the copy logic handles the validated cells
if (c.getCellFeatures() != null &
c.getCellFeatures().hasDataValidation())
{
validatedCells.add(c);
}
}
Run Code Online (Sandbox Code Playgroud)