问题
I am using JExcel(2.6.10) and I want to copy sheet . I want to create as like that
- Open existing Excel file (pre created it as template for don't need to add style and layout)
- Update or insert required fields
- return it as ByteArrayOutPutStream for download (user can download that excel file)
My Excel file may include one or more sheet that with dynamic sheet count. I don't want to create many template file . I want to copy template and insert datas at on these copied templates. But I got troubles when I copied it. Copied sheets are wrong format , I means their border styles are false . Except it others are fine. Any suggestions would be appriciated. Here 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 have also tried with WorkBook.Import() method, like as 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 get exact datas , merge regions but not right borders ! I am still trouble!
来源:https://stackoverflow.com/questions/17078543/error-occured-in-copying-excel-sheet-with-jexel-api