I am using jxl api to edit an existing excel file. But when I try to add a new column and write a leaflet, it will show a null pointer exception. The code I'm using is shown below:
File file = new File("d:\\test.xls");
Workbook workbook;
WritableWorkbook copy = null;
if (file.exists()) {
try {
workbook = Workbook.getWorkbook(file);
copy = Workbook.createWorkbook(new File("C:\\TEMP\\temp.xls"),
workbook);
} catch (BiffException e) {
e.printStackTrace();
} catch (FileNotFoundException fnf) {
fnf.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
WritableSheet sheet = copy.getSheet(0);
sheet.insertColumn(2);
try {
copy.write();
copy.close();
}
catch(Exception e)
{
e.printStackTrace();
}
Please help me solve this problem and insert a new column.
I can successfully edit individual excel cells and write the file.
source
share