Error occured in copying excel sheet with JExel API

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 06:24:17

问题


I am using JExcel(2.6.10) and I want to copy sheet . I want to create as like that

  1. Open existing Excel file (pre created it as template for don't need to add style and layout)
  2. Update or insert required fields
  3. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!