Issue while copying workbook

Hi,

I am using Aspose.cells.1.9.4.13 for java.

While copying the workbook, I am getting following exception.

java.lang.IllegalArgumentException: Invalid sheet index: -1
at com.aspose.cells.Worksheets.a(Unknown Source)
at com.aspose.cells.Worksheets.getSheet(Unknown Source)
at com.aspose.cells.Worksheets.setActiveSheet(Unknown Source)
at com.aspose.cells.Workbook.copy(Unknown Source)

I can not provide you sample code as I am not able to simulate it in sample code.

Can you please tell me what is the possible cause of this issue?

Thanks.
Kailas

Hi,

Any help in this issue?

Thanks
Kailas

Hi Kailas,

Please try this attached patch. we add some code to avoid this error. But it is some strange for this issue, for common workbook, this sheet index of -1 should never be matched, would you please send us your template file and code so we can check the reason and improve on the logic. You can post it to nanjing@aspose.com , We will take your data with ultimate care(as we always do with our cusomer data), thank you.

Hi,

Thanks for the fix.

I am not able to simulate the same issue outside my project. So I am not able to provide the sample code.

I will explain you the scenario.

I have a workbook in cache.
I want to add some more worksheets in this workbook.
I generate a new WorkbookDesigner object as I need to process smart markers in the added worksheet and I get the workbook from this workbookDesigner.
Then I copy the cached workbook to the workbook taken from workbookDesigner object.
Here it was creating the problem during copy.

This issue has been resolved but it is affecting the performance.

Can you please provide me an API (highlighted in DeepPink color) like below

Workbook workbook =
WorkbookDesigner workbookDesigner = workbook.getWorkbookDesigner();

OR

WorkbookDesigner workbookDesigner = new WorkbookDesigner();
Workbook workbook =
workbookDesigner.setWorkbook(workbook);

Thanks.
Kailas






Hi Kailas,

For your scenario, I think you need not copy the workbook. If the workbook in cache is completely created by code, you can just get it from a WorkbookDesigner object then add sheets and data to it.

If the workbook in cache is built by an existed template file, you can build a WorkbookDesigner first, then get the Workbook object from the WorkbookDesigner, and then read in the template file by call open() method on this Workbook object. And you can do anything on this Workbook object just as it is created by "new Workbook()", such as add more sheets and data to it after read in the template file.

Hi Jhonson,

Please find my response below.

"If the workbook in
cache is completely created by code, you can just get it from a
WorkbookDesigner object then add sheets and data to it"


I have right now implemented your first solution. But it is hitting the performance as there are almost more than 70 sheets in a workbook so this is not good solution.

"If the workbook in
cache is built by an existed template file, you can build a
WorkbookDesigner first, then get the Workbook object from the
WorkbookDesigner, and then read in the template file by call open()
method on this Workbook object. And you can do anything on this
Workbook object just as it is created by “new Workbook()”, such as add
more sheets and data to it after read in the template file"

I was doing your second solution initially before implementing your first solution. It is also causing lots of IO operations for adding worksheets.

Thanks.
Regards,
Kailas





Hi Kailas,

Would you please give us more detail and sample of your scenario? We appreciate if you can provide your code snatch or sample project here which can demonstrate what you want to get, we will check it soon. Thank you.