I need to edit an XLS file already created, but I'm only able to create a new file and delete the old file, so far it works, but I wonder if you can edit the old file and not have to delete the old one and create a new one with the same name.
String autEdit = request.getParameter("aut");
response.setContentType("text/html;charset=UTF-8");
File file = new File("C:\Tratados\4-600dpi.xls");
Workbook workbook = null;
try {
workbook = Workbook.getWorkbook(new File("C:\teste.xls"));
} catch (BiffException ex) {
Logger.getLogger(autorizacao.class.getName()).log(Level.SEVERE, null, ex);
}
WritableWorkbook copy = Workbook.createWorkbook(new File("C:\Teste.xls"), workbook);
Sheet sheet = workbook.getSheet(0);
int linhas = sheet.getRows();
int i = 0, x = 0;
WritableSheet sheet2 = copy.getSheet(0);
for (i = x; i < linhas; i++) {
Cell a1 = sheet.getCell(0, i);
WritableCell a2 = sheet2.getWritableCell(1, i);
WritableCell a3 = sheet2.getWritableCell(2, i);
String as1 = a1.getContents();
String as2 = a2.getContents();
String as3 = a3.getContents();
if ("-".equals(as2)){
Label l = (Label) a2;
l.setString(autEdit);
Label ll = (Label) a3;
ll.setString("Editado");
linhas = i - 1;
}
}
copy.write();
file.delete();
try {
copy.close();
} catch (WriteException ex) {
Logger.getLogger(autorizacao.class.getName()).log(Level.SEVERE, null, ex);
}
workbook.close();