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

Free Support Forum - aspose.com

Copying worksheet from file to file corrupts Excel file

Using Cells for Java V2.0, if you open a new workbook, copy a worksheet from another workbook to sheet 0 of the new workbook, and then save the new workbook, the new workbook is somehow corrupted. Depending on the version of Excel I use, I either get a “file corrupted” error when I open the new workbook, or an error when I try to close it (Excel needs to quit).

Creating a new worksheet, copying the worksheet from another workbook to it, and then deleting worksheet 0 from the new file seems to solve the problem.

Hi,

Could you post your template file(s) with sample code here, we will check your issue soon.

Thank you.

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

Well, I have executed your scenario by using the latest version of Aspose.Cells for Java and it works fine. Following is my sample code.

Sample Code:

//Create a Workbook.

Workbook excelWorkbook0 = new Workbook();

//Create another Workbook.

Workbook excelWorkbook1 = new Workbook();

//Open a file into the first book.

excelWorkbook0.open("C:\\Sample.xls");

//Copy the first sheet of the first book into second book.

excelWorkbook1.getWorksheets().getSheet(0).copy(excelWorkbook0.getWorksheets().getSheet(0));

//Save the file.

excelWorkbook1.save("C:\\FinalBook.xls", FileFormatType.DEFAULT);

Please Share your template file, so we can figure out the issue.

Thank You & Best Regards,

Here is my sample code and designer.

Hi,

Thanks for providing the template file with sample code.

We have found the issue after an initial test, we will figure it out soon.

Thank you.

Hi,

We have figured out your issue and fixed it, please try the new fix V2.0.0.7 (attached).

By the way, we have analyzed this issue(Copying Worksheets issue) and the Worksheets.removeSheet issue which you posted some days ago in the thread: <A href="https://forum.aspose.com/t/83231</A> both are caused by some improper records in your original files. So, we think maybe your original files were created by some tools other than MS Excel, would you please let us know which tool(s) you used to create those files? If they were generated by Aspose.Cells for Java, please give us your codes to create such Workbooks, so we can trace the root cause of such problem and get rid of the issue next time. </P> <P>We do appreciate your help in this regard.</P> <P>Thank you.<BR></P>