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

Free Support Forum - aspose.com

Excel files corrupted by latest version of Aspose.Cells?


I’ve been using Aspose.Cells 4.1.00 since it came out in 2006, and have never had any problems with Excel files being corrupted. However, now I’ve upgraded to Aspose.Cells, and when I call Worksheet.Copy() between two sheets that are in different workbooks, the result is a file that throws an exception in Excel. I have attached one of these broken files (though it seems to look okay, it has the error message “File error: Data may have been lost.” pop up).

For reference, I have also included a copy of the original template (though not the worksheet that is being copied into the broken workbook). I presume this is a problem with file headers that you can resolve just by looking at the broken workbook, but please let me know if you need more information.


Hi Chris,

The only file you attached is one of your template workbooks, is not it? I opened this template file into MS Excel (2000 - 2007) fine and don't get the error message stating: "File error: Data may have been lost.". Could you give us more details, in which excel version you got this error and what is the end result of that (did the excel file opened fine after giving the error message or not). Could you post your two source template files, resultant corrupted excel file and sample code here, It will help us to reproduce and rectify the problem (if found).

Thank you.

Yes, that was indeed the template – I had tried to upload both, but evidently these message boards only allow one attachment per message (the second attachment is always replacing the first one). Here is the corrupted resultant file. Another message to follow with more information.

Here is the other template file, the first tab of which gets copied into a single tab in the other file (and the other file is saved). The code for this follows, but note that I did simply it a bit because normally it has a lot of portions that require a dataset from our database to function. This does not cause a corrupt file if the mergeSheet.Copy( sheet ) line is commented out, but it does if that line is included.

Workbook book = new Workbook();
string templatePath = “c:<span id=“ctl00_ctl01_bhcr_AggHeader___Header1”>NAHT_TaxBenefitSummary.xls”;
book.Open( templatePath );

Workbook bookFinal = this.RunImport( book );

MemoryStream stream = bookFinal.SaveToStream();
byte[] data = stream.ToArray();
return data;

public Workbook RunImport( Workbook Workbook )
Worksheet sheet = Workbook.Worksheets[“Variables”];

//data is now imported by using PutValue on a number of cells in this sheet

string mergeFile = “c:<span id=“ctl00_ctl01_bhcr_AggHeader___Header1”>Current TBS Template.xls”;
Workbook mergeBook = new Workbook();
mergeBook.Open( templatePath );

Worksheet mergeSheet = null;
{ //get the old variables sheet, if it exists
mergeSheet = mergeBook.Worksheets[“Variables”];
catch {}

if ( mergeSheet == null )
mergeSheet = mergeBook.Worksheets[mergeBook.Worksheets.Add()];
mergeSheet.Move( 0 ); //put as first sheet
mergeSheet.Name = “Variables”;

mergeSheet.Copy( sheet );
Workbook = mergeBook;

Workbook.CalculateFormula( true );
return Workbook;

To answer your other questions, I get this error message in Excel 2003 SP3. The workbook does seem to be mostly fine after I open it, although it is hard to say because there are a LOT of #VALUE and #NUM! values in there, and I’m not sure if they are all correct based on your calculation engine, or if some of them have to do with an inability to properly link to the cells in the copied Variables tab.


Please try this fix.

I think error values in the cells are caused by there are no values in the template file.

That worked great, thanks!