Writing to an Existing Excel File

白昼怎懂夜的黑 提交于 2019-11-30 09:35:33

LabelCell is just an interface with only one method i.e getString() you can learn more about it here

You should use jxl.write.Label instead.
What you should exactly do is as follows
You should import the following file

import jxl.write.Label

Then following is the code for adding a cell at desired location to an excel file

Workbook existingWorkbook = Workbook.getWorkbook(new File(fileToEdit.getAbsolutePath()));
WritableWorkbook workbookCopy = Workbook.createWorkbook(new File("output.xls"), existingWorkbook);
WritableSheet sheetToEdit = workbookCopy.getSheet(sheetName);
WritableCell cell;
Label l = new Label(currentColumn, currentRow, value);
cell = (WritableCell) l;
sheetToEdit.addCell(cell);
 workbookCopy.write();
 workbookCopy.close();
 existingWorkbook.close();

currentColumn and currentRow define the index and value contains the String to be placed in that cell.

Hope it helps

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!