We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Copy Worksheet having some problems

Hi there,


I am currently using Java Aspose Cell 7.0.4. Here is the code snipped:

License license = new License();
license.setLicense("/tmp/aspose.cells.lic");
Workbook workbook = new Workbook("/tmp/CurveSheet.xls", new LoadOptions(LoadFormat.EXCEL_97_TO_2003));
List sheetNames = Arrays.asList(“Sheet 1”, “Sheet 2”);
for (String sheetName : sheetNames) {
int newSheetIndex = workbook.getWorksheets().addCopy(“TEMPLATE”);
Worksheet newSheet = workbook.getWorksheets().get(newSheetIndex);
newSheet.setName(sheetName);
}
// [MARK]
// workbook.getWorksheets().removeAt(“TEMPLATE”);
workbook.save("/tmp/mod_curvesheet.xls", new XlsSaveOptions(SaveFormat.EXCEL_97_TO_2003));


If I run this code, the generated workbook is working fine. Now, if I un-comment the code under [MARK], then generated workbook is actually having a problem. Problem is that any changes to the cell in Sheet 2 is actually reflect to Sheet 1.

Note: to re-produce this problem, you have to load the aspose license.

Look forward for your help

Hi,


After removing the “Template” sheet, please activate your desired sheet in the workbook, it will works fine as I have tested.

See your updated code segment.
Sample code:

License lic = new License();
lic.setLicense(new FileInputStream(“Aspose.Cells.lic”));

Workbook workbook = new Workbook(“CurveSheet.xls”, new LoadOptions(LoadFormat.EXCEL_97_TO_2003));
List sheetNames = Arrays.asList(“Sheet 1”, “Sheet 2”);
for (String sheetName : sheetNames) {
int newSheetIndex = workbook.getWorksheets().addCopy(“TEMPLATE”);
Worksheet newSheet = workbook.getWorksheets().get(newSheetIndex);
newSheet.setName(sheetName);
}
// [MARK]
workbook.getWorksheets().removeAt(“TEMPLATE”);

//Set the second sheet as an active sheet.
workbook.getWorksheets().setActiveSheetIndex(1);
workbook.save(“mod_curvesheet.xls”, new XlsSaveOptions(SaveFormat.EXCEL_97_TO_2003));