When writing from JTable to Excel, a new file is created with xls, instead of creating new sheets. For example :
There are 5 sheets in excel spreadsheet.
The program builds a JTable based on this table.
And it is necessary that when a change is made in the JTable, all data is saved back to the Excel spreadsheet.
In my code the following happens: each sheet opens in a new window. but by pressing the key, save all sheets in the xls file, create the current sheet and save the data. And it is necessary that he overwrites the data in one of the existing sheets.
All code works on Apache POI, but this section of code works with JXL
WritableWorkbook workbook1 = Workbook.createWorkbook(new File("C:\\result.xls")); WritableSheet sheet1 = workbook1.createSheet(list, listnum); TableModel model = table.getModel(); for (int i = 0; i < model.getColumnCount(); i++) { Label column = new Label(i, 0, model.getColumnName(i)); sheet1.addCell(column); } int j = 0; for (int i = 0; i < model.getRowCount(); i++) { for (j = 0; j < model.getColumnCount(); j++) { Label row = new Label(j, i + 1, model.getValueAt(i, j).toString()); sheet1.addCell(row); } } workbook1.write(); workbook1.close(); how to fix code to convert it from jxl to apache POI?
The first line needs to be changed not to create a new book, but to read an existing one.