Multiple saves creates blank excel file


#1

I am currently using the demo version of Aspose Excel version 3.5.3.0. I have run into a problem where a 2nd save creates a blank excel file. Here is some sample code:

Dim stream As New System.IO.MemoryStream(data)
_excelDocument = New Aspose.Excel.Excel
_excelDocument.Open(stream)
_excelDocument.Save("c:\temp\1.xls")
_excelDocument.Save("c:\temp\2.xls")
_excelDocument.Open(stream)
_excelDocument.Save("c:\temp\3.xls")

1.xls and 3.xls look fine. But 2.xls looks blank (except for the Evaluation Copyright Warning of course). Any ideas?

Thanks


#2

After Save method is called, Aspose.Excel discards all internal data. So you got blank file in the second call.


#3

Any reason why it discards the data? Is there anyway to prevent it from discarding the data?


#4

When calling Excel.Save method, many intermedia data are changed and many state data are updated. For performance consideration we don't roll them back. So we discard data to avoid problems.

If you want to preserve data, please use Excel.Copy method to make a copy before saving.

Excel excel1 = new Excel();

//do something here

....

Excel excel2 = new Excel();

excel2.Copy(excel1);

excel1.Save(...);

excel1 = null;

Then you can use excel2 object for future use.


#5

I tried this and save gives me an empty excel document. Is there a chance that the Copy call discards the internal data as well?


#6

What's your sample code? Following is my detail code:

Excel excel1 = new Excel();

excel1.Worksheets[0].Cells["A1"].PutValue("hello");

Excel excel2 = new Excel();

excel2.Copy(excel1);

excel2.Worksheets[0].Cells["A2"].PutValue("world");

excel1.Save("c:\\book1.xls");

excel1 = null;

excel2.Save("c:\\book2.xls");

In book1.xls, you will see "hello" in A1. In book2.xls, you will see "hello" in A1 and "world" in A2.

Only after calling save method, excel1 and excel2 internally discard data.