[英]Writing to excel using jxl, getting indexOutofBoundException error
public static void main(String args[]) throws BiffException, IOException, RowsExceededException, WriteException{
WritableWorkbook workbookCP;
try {
Workbook workbook = Workbook.getWorkbook(new File("C:/Users/collections.xls"));
workbookCP = Workbook.createWorkbook(new File("C:/Users/collectionsCopy.xls"),workbook);
WritableSheet sheet = workbookCP.getSheet("collections");
Label label = new Label(10, 0, "Name");
sheet.addCell(label);
Label label1 = new Label(11, 0, "Surname");
sheet.addCell(label1);
Label label2 = new Label(13, 0, "Ammount");
sheet.addCell(label2);
workbookCP.write();
workbookCP.close();
workbook.close();
}
catch(Exception e)
{
e.printStackTrace();
}
i'm trying to write data to an existing excel file with the code above, but i'm getting the following error Thanks 我正在尝试使用上述代码将数据写入到现有的excel文件中,但出现以下错误,谢谢
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
Try changing these two lines: 尝试更改这两行:
Workbook workbook = Workbook.getWorkbook(new File("C:/Users/collections.xls"));
workbookCP = Workbook.createWorkbook(new File("C:/Users/collectionsCopy.xls"),workbook);
into this: 到这个:
Workbook workbook = Workbook.getWorkbook(new File("C:\\Users\\collections.xls"));
workbookCP = Workbook.createWorkbook(new File("C:\\Users\\collectionsCopy.xls"),workbook);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.