I am using JExcel (2.6.10) and I want to copy a sheet. I want to create as if
- Open an existing Excel file (pre-created as a template for no need to add style and layout)
- Update or insert required fields
- return it as ByteArrayOutPutStream to load (user can download this excel file)
My Excel file may contain one or more sheets with a dynamic number of sheets. I do not want to create many template files. I want to copy a template and paste data on these copied templates. But I had problems when I copied it. Copied sheets of the wrong format, I mean that their border styles are false. In addition, everything is in order. Any suggestions will be assigned. Here are my codes ..
WorkbookSettings wsWrite = new WorkbookSettings(); wsWrite.setEncoding("UTF-8"); WorkbookSettings wsRead = new WorkbookSettings(); wsRead.setEncoding("UTF-8"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); WritableWorkbook workBook = Workbook.createWorkbook(baos, Workbook.getWorkbook(new File(templateDir + "/shipping_template.xls"), wsRead), wsWrite); for (int i = list.size() - 1; i > 0; i--) { workBook.copySheet("S1", "S" + (i + 1), 2); } workBook.write(); baos.close(); workBook.close();
I also tried using the WorkBook.Import () method as shown below.
Workbook readableWorkbook = Workbook.getWorkbook(new File(templateDir + "/shipping_template.xls"),wsRead); WritableWorkbook writableWorkbook = Workbook.createWorkbook(baos, readableWorkbook, wsWrite); for (int i = vehicleList.size() - 1; i > 0; i--) { writableWorkbook.importSheet("S" + (i + 1), 2, readableWorkbook.getSheet(1)); }
It also receives accurate data, combines regions, but not the correct boundaries! I'm still having problems!
source share