我有一个带单页的excel文件(抽象模型).现在我想将工作表复制到另一个现有工作簿.我怎样才能做到这一点?
我正在尝试将一种细胞样式应用于不同的woekbooks.当我将它应用于第一个工作簿时,它运行良好,但是当我尝试使用第二个和下一个工作簿时 - 没有应用样式并抛出以下异常.
Exception in thread "Thread-3" java.lang.IllegalArgumentException: This Style does not belong to the supplied Workbook Stlyes Source. Are you trying to assign a style from one workbook to the cell of a differnt workbook?
at org.apache.poi.xssf.usermodel.XSSFCellStyle.verifyBelongsToStylesSource(XSSFCellStyle.java:118)
at org.apache.poi.xssf.usermodel.XSSFCell.setCellStyle(XSSFCell.java:500)
at CoreLayer.ExportManager.ExcelExproter.applyStyle(ExcelExproter.java:224)
at CoreLayer.ExportManager.ExcelExproter.groupSchedule(ExcelExproter.java:47)
at UILayer.ExportDialog$ExportWorker.run(ExportDialog.java:111)
at java.lang.Thread.run(Thread.java:722)
Run Code Online (Sandbox Code Playgroud)
使用以下代码:
public void professorSchedule(Professor professor) {
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet(TextConstants.SCHEDULE);
String safeName = WorkbookUtil.createSafeSheetName(professor.toString() + ".xlsx");
LinkedHashMap<ScheduleSlot, Lesson> professorSchedule = data.getSchedule().getProfessorSchedule(professor);
fillProfessorSchedule(sheet, professorSchedule);
applyStyle(wb, sheet);
try { …Run Code Online (Sandbox Code Playgroud)