Hi. I have a report, that should include another reports within. So i copy worksheets from source reports to one target. But since version 8.7.1 i got error:
com.aspose.cells.Name cannot be cast to java.lang.Integercom.aspose.cells.Name cannot be cast to java.lang.Integercom.aspose.cells.Name cannot be cast to java.lang.Integer
There is test case:
public static String preventSheetNamesDuplicates(Workbook target, Workbook source, int iCount) {
String sheetName = source.getWorksheets().get(iCount).getName();
int sheenAddNum = 1;
String newSheetName = sheetName;
while (target.getWorksheets().get(newSheetName) != null) {
newSheetName = sheetName + “_” + sheenAddNum;
sheenAddNum++;
}
source.getWorksheets().get(iCount).setName(newSheetName);
return newSheetName;
}
public void copyBook(Workbook target, Workbook source) {
for (int iCount = 0; iCount < source.getWorksheets().getCount(); iCount++) {
//Формируем имя листа, если такой лист уже есть, то переименовываем
String newSheetName = preventSheetNamesDuplicates(target, source, iCount);
target.getWorksheets().add(newSheetName);
}
for (int iCount = 0; iCount < source.getWorksheets().getCount(); iCount++) {
Worksheet sourceWs = source.getWorksheets().get(iCount);
Worksheet targetWs = target.getWorksheets().get(sourceWs.getName());
try {
targetWs.copy(sourceWs);
targetWs.getPageSetup().setPrintArea(sourceWs.getPageSetup().getPrintArea());
} catch (Exception e) {
System.err.print(e.getMessage());
}
}
}
@Test
public void copyBookTest() throws Exception {
Workbook target = new Workbook(“D://target.xls”);
copyBook(target, new Workbook(“D://source.xls”));
copyBook(target, new Workbook(“D://source1.xls”));
copyBook(target, new Workbook(“D://source2.xls”));
copyBook(target, new Workbook(“D://source3.xls”));
}
Best regards. Alexey