Document corruption after opening Excel 2007 file with Aspose Cells 4.8.2.15 and resaving the filestream as a new file

Hi,

I am using Aspose Cells to open workbooks on the server and resaving the filestream as a new file. But the resulting document is corrupt.

I am prompted by Excel to fix the unreadable content on opening the resulting file.

Code used to save the filestream:
Workbook workbook = new Workbook();
fstream = new System.IO.FileStream(docFile, FileMode.Open); /docfile is path to xlsm file/
workbook.Open(fstream, fileFormat);

//To avoid aspose workbook corrupte file so close filestream
fstream.Dispose();
.
.
.
. LINK BREAKING using LEGACY CODE
.
.
.
if (workbook.Worksheets.CustomDocumentProperties.Contains("_PID_HLINKS"))
workbook.Worksheets.CustomDocumentProperties.Remove("_PID_HLINKS");

// To avoid aspose workbook corrupte file so create a new filestream
fstream = new System.IO.FileStream(docFile, FileMode.Create);
workbook.Save(fstream, FileFormatType.Excel2007Xlsm);

Attaching the file for your reference. Please assist.

thanks

Hi,

Thanks for providing us the template file, I think it is your output file.
Well, since you are using some older version e.g v4.8.2.15 for which I am not sure.

Please try our latest version Aspose.Cells for .NET (Latest Version)
if it works fine.

You may change your sample code a bit accordingly (for the new version) as follows (if you want):

Code used to save the filestream:

fstream = new System.IO.FileStream(docFile, FileMode.Open); /docfile is path to xlsm file/
Workbook workbook = new Workbook(fstream);

//To avoid aspose workbook corrupte file so close filestream
fstream.Dispose();
.
.
.
. LINK BREAKING using LEGACY CODE
.
.
.
if (workbook.Worksheets.CustomDocumentProperties.Contains(“_PID_HLINKS”))
workbook.Worksheets.CustomDocumentProperties.Remove(“_PID_HLINKS”);

// To avoid aspose workbook corrupte file so create a new filestream
fstream = new System.IO.FileStream(docFile, FileMode.Create);
workbook.Save(fstream, SaveFormat.Xlsm);

If you still find the issue, kindly do post your input file here, we will check your issue soon.

thank you.

How can i identify from code if the file has been processed by Aspose or not? Any programattic way of identifying this or any excel value that I should be looking at?

Thanks

Hi,

When you write file with Aspose.Save(), then it is your output file. Your code suggests, you are not using any input file. You are creating a file from scratch.

Will you please test your issue with Aspose.Cells for .NET (Latest Version).


If the problem still occurs, then please provide your complete code. The section of code you provided has already been tested by Amjad and no issue was found inside it.

My mistake. Please notice that the docFile is the input file and the output file is Destfile.

it should be

Code used to save the filestream:
Workbook workbook = new Workbook();
fstream = new System.IO.FileStream(docFile, FileMode.Open); /docfile is path to xlsm file/
workbook.Open(fstream, fileFormat);

//To avoid aspose workbook corrupte file so close filestream
fstream.Dispose();
.

.
. LINK BREAKING using LEGACY CODE
.
.
if (workbook.Worksheets.CustomDocumentProperties.Contains("_PID_HLINKS"))
workbook.Worksheets.CustomDocumentProperties.Remove("_PID_HLINKS");

workbook.Save(destFile, FileFormatType.Excel2007Xlsm);

The document corruption happens consistently for the following file as DocFile.

I am reattaching the file again and it is reproducible on 5.3. version of the Aspose.Cells assembly.


I have confirmed that the file gets corrupt with Aspose Cells 4.8.2.15 but if I change the code such that it uses the SaveFormat in v5.3.0.5, it doesn’t get corrupt. My application is already live and it would be great if you could suggest based on this document, the types of documents that are susceptible to corruption. This would help resolve some support issues for those documents.

Thanks
Vijit Khanna

Hi,

"I have confirmed that the file gets corrupt with Aspose
Cells 4.8.2.15 but if I change the code such that it uses the
SaveFormat in v5.3.0.5, it doesn’t get corrupt. My application is
already live and it would be great if you could suggest based on this
document, the types of documents that are susceptible to corruption.
This would help resolve some support issues for those documents.
"

Well, for your older version v4.8.2.15, I am afraid, I cannot help you much on how to sort out the susceptible spreadsheets for corruption. But if it works fine with v5.3.0.5, you should use it for your need.

By the way, if I simply opens your attached file in MS Excel 2007, MS Excel does prompts me the error message “Excel found unreadable content…”.

Thank you.

Thank you.

For the error to reproduce you have to save the file stream of this file as a new file after opening it with Aspose. This is a good file otherwise.


Thanks

Hi,

Just for your confirmation, using the latest fix v5.3.0.5 (we have tested), it works fine when saving the file stream of your file as new file using Aspose.Cells API. So kindly use the latest Aspose.Cells for .NET version v5.3.0.5. It might be an issue with older versions.

Thanks for your understanding!

Hi,

Please try the Aspose.Cells for .NET (Latest Version).
We have fixed the issue you mentioned.