Excel file become corrupted and remove existing data validation when workbook created from original file with Apache POI

112 Views Asked by At

I need to write data to existing excel workbook (.xls) but when the workbook is created, it become corrupted with error We found a problem with some content in.... When yes is clicked, the excel workbook lost some of the formula and the cell style.

The excel file is protected and cannot change anything in the sheet that contains the data validation list.

There are two cells with data validation list. The first one has list of 54 items and the second one has list of 229 items and the format is custom date. The validation data list is pre-existing and protected, so cannot change anything in the sheet.

Is there any workaround can be done? I cannot change any other thing to the excel except for write the data to the unprotected cell using the java code.

This is test code that I use:

FileInputStream fileInput = new FileInputStream("D:/Test/Test.xls");
Workbook wb = null;
wb = new HSSFWorkbook(fileInput);

fileInput.close();

Sheet sheet = null;
Cell cell = null;

sheet = wb.getSheetAt(1);

cell = sheet.getRow(10).getCell(2);

cell.setCellValue("10.00");

FileOutputStream fileOut = new FileOutputStream("D:/Out/Test_Updated.xls");
workbook.write(fileOut);
fileOut.close();
0

There are 0 best solutions below