Free Support Forum - aspose.com

Upgraded from Aspose .Cells 4.5.1 to 4.7.1 and now all Excel files are corrupt

This is a continuation of the thread started off in the prior post:

<A href="</A></P> <P>I was unable to see your attached demo, possibly because it was not authorized for me to get. However, I do have the following information:</P> <P>I have already used your standard Aspose.Cell.Demos and had the coded inside HelloWorld.cs work fine for me. I then copied over the HelloWorld.cs file into one of my projects and the code didn't work anymore. I'm quite certain that your simple demo will work fine for me. The issue is to figure out why Aspose won't work in my complex demo. Our corporate website is a complex website and so for Aspose to be of value it needs to be able to work in a complex website and not just simple demo websites.</P> <P>Clearly there is something about the interaction of Aspose with our website that causes Aspose Cells to not work correctly. Version 4.5.1 works fine but version 4.8.1 does not. </P> <P>I have the following code:</P><FONT size=2> <P>workbook.Save(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>"TestName.xls");

workbook.Save("HelloWorld.xls",FileFormatType.Default,SaveType.OpenInExcel,System.Web.HttpContext.Current.Response);

System.Web.HttpContext.Current.Response.End();

The 1st line saves fine locally with no file corruption. The 2nd line saves with a corrupt Excel file.

I'm running this all locally on my development machine and not a production website. My development machine is running Visual Studio 2008 under the development webservice that is part of visual studio. I am running on Windows XP Professional in 32-bit mode. I am running with ASP .NET 3.5, have Elmah installed, DevExpress installed and Aspose.Cells installed.

What should I do now?

Hi,

Thank you for considering Aspose.

As the standard demos can work fine and workbook.Save("TestName.xls") works fine then it should not be the issue of Aspose.Cells. Please check the following steps:

1: Please remove all Aspose.Cells.dlls in your project, add then add new Aspose.Cells 4.8.1 for Net2.0 to the project (The project refers to the Aspose.Cells for Net1.0 by default) and then rebuild all. Then please check if the demo works fine for you.

2: If the generated file is still corrupt, please simply export a template excel file by Response object without using Aspose.Cells code.
For example:
FileStream fs = File.OpenRead(@"F:\FileTemp\Book1.xls");

byte[] data = new byte[fs.Length];

fs.Read(data, 0, data.Length);

Response.Clear();

Response.ClearHeaders();

Response.ContentType = "application/vnd.ms-excel";

Response.AddHeader("Content-Length", data.Length.ToString());

Response.AddHeader("content-disposition", "attachment; filename=Book1.xls");

Response.BinaryWrite(data);

Response.End();

If the generated file is still corrupt, you have to check setting of your webservice.

3: If the generated file in the step 2 is still corrupt, please post your corrupted "Hello World.xls" file here. We will check it soon.

Thank You & Best Regards,

OK. Your mention of the need to reference .NET 2.0 seems key here. The prior Aspose.Cells.dll for version 4.5.1 did get added correctly as .NET 2.0 compiled. I do notice that the Apose.Cells version 4.8.1 is using .NET 1.0. However, when I look to re-add Apose.Cells there does not seem to be a .NET 2.0 compiled version available. I see two Aspose Cells one inside the NET1.0 directory and another in the NET2.0 directory. However, both dll files seem identical and both are compiled for .NET 1.0 and not .NET 2.0 Something has clearly gone wrong here.

I'll try redownloading and reinstalling Aspose Cells again.

Hi,

When you install Aspose.Cells for .NET v4.8.1, you will get two different dlls: one compiled on .net 1.x and the other compiled on .net2.0. I did test and install the version and I can get two different versions of the product.

The size of the version in Net1.0 folder is 3.98 MB.
The size of the version in Net2.0 folder is 4.29 MB.

I think you should re-download/re-install it.

Thank you.

I reinstalled and this time verified that I got the .NET 2.0 version. However, after doing so it made no difference I still got corrupt Excel files.

I then went ahead and followed your suggestion to use the Response object directly. I still got the same corrupt Excel files.

I then stumbled upon the following link which mentions use of the Response object constantly yielding corrupt files.

http://bytes.com/topic/asp-net/answers/544580-all-files-corrupted-using-response-write-response-binarywrite-net-1-1-a

The solution was to NOT use Response.ClearHeaders(). When I commented out Response.ClearHeaders() everything finally worked!

So I'm thinking could you make the fix in your code. I'd much rather not have to rewrite our code to use the Response object and continue just using your Save() method as we always have been. By having you do the code changes I also don't have to deal with trying to make sure each temporary file has a unique filename since more than one user at a time could call the same code.

Based upon my findings will you be coming out with a patch release that does not use Response.ClearHeaders()? If so, when would it come out?

Hi,

Thank you for your constant feedback and support to figure out the issue. We will remove Response.ClearHeaders from our APIs and will provide you a fix in 1 ~ 2 day’s time.

Thank You & Best Regards,

Hi,

Please try the attached version.


p
{
margin: 0pt;
font-family: Arial,Verdana,Tahoma;
font-size: 12px;
}
.footer { color:Gray; font-size: 11px; text-align: center; }
.back1 { background-color: whitesmoke; }
.back2 { background-color: #f1f5e1; }
.back3 { background-color: cornsilk; }

We have
removed Response.ClearHeaders() in the Workbook.Save method.
If you still have any problem, please feel free to contact us anytime.

Thank you.

Everything works now. So I will go ahead and publish this new verson 4.8.1.7 dll for further testing and eventual release to our production website.

Now 4.8.1.7 doesn't work on our test websites. I updated 2 of our test websites and now the problem is that the file does not complete saving. I see that it appears to download quickly, but the download progress dialog box stays up forever. If I cancel the dialog box the file is never saved. So this change to remove the ClearHeaders() call might not be the best thing or maybe there is something further that is wrong. Do you have any further clues?

At this time I guess my best path to diagnosing the problem is to save the file locally and see what it takes to get a file saved successfully on the client side. Doing this activity makes it a basic problem of how to transfer a file from the website to the client.

This feels like it's going to be a long effort so any help or clues that you can offer will be most appreciated. But as it stands now the latest version that of your dll that works fine is 4.5.1. Could you send me some versions that followed 4.5.1 so that I could isolate when your stopped working. This maybe could help shed light on the solution.

Hi,

Well, we think you have to rebuild your web demo/site and re-start the web service or machine
If you still find the problem, please try to save workbook to the stream using Workbook.SaveToStream() method and then export/write this stream by yourself using Response object if it works fine.


Thank you.

You guys are making me work too hard. I'm supposed to be your customer, not one of your developers. Doing some test and debugging on the develoment machine is fine, but doing it remotely on the test machines feels like it's going to be hard and cumbersome. I think I need a more help than what you've supplied. But first, let me explain my configurations.

1) Development machine: Running Windows XP Pro, VS 2008, MS SQL Developer 2005.

2) Test machine #1: Running Windows 2003 server 64-bit. MS SQL Server Enterprise 2005, and IIs 6.0

3) Test machine #2: Running Windows 2003 server 32-bit, IIs 6.0

4) Production machine: Running Windows 2003 server 64-bit, MS SQL Server Enterprise 2005, and IIs 6.0

So far version 4.5.1 works on all 4 configurations and some other machines that I have not listed above. Version 4.5.1 has never had any problems. Our first attempt to upgrade was with 4.7.1 which is when we started seeing the corrupt files.

Version 4.8.1.7 works fine on the development machine. It does not work well on Test machine #1 or #2. We have not deployed to the production machine because it failed on the test machines. Whenever we deploy the process is:

a) Publish the website to a local directory on the development machine. I had done a complete clean and rebuild of the website at this point.

b) zip up the published website and copy over to one of the test machines.

c) on the test machines, unzip and copy over all the files. The act of copying over all the files including the global.ascx file will effectively shut down the website. The next access starts it back up. So I get a restart.

But anyway I went in and explicitly restarted all webservices with no change.

I'm not familiar with the SaveToStream() and follow up code with the Response object. Can you save me the effort of research and send me a sample code snippet?

Also are you investigating the key differences between version 4.5.1 and 4.7.1 and later as a way of isolating the problem? If so then maybe it would be worthwhile for me to download and install version 4.6.0. Should I try to download and install version 4.6.0?

Hi,

Please use this Save method to Replace Workbook.Save method . See following demo code:

public static void Save(Workbook workbook,string fileName,
FileFormatType fileFormatType, SaveType saveType, bool compression,

System.Web.HttpResponse response)
{
MemoryStream ms = new MemoryStream();
workbook.Save(ms, fileFormatType);
//Clear response content
//response.ClearContent();
response.Clear();
//response.ClearHeaders();

//Set content type
switch (fileFormatType)
{
case FileFormatType.ODS:
response.ContentType = “application/ods”;
break;
case FileFormatType.Pdf:
response.ContentType = “application/pdf”;
break;
case FileFormatType.CSV:
response.ContentType = “application/csv”;
break;
case FileFormatType.TabDelimited:
response.ContentType = “application/txt”;
break;
case FileFormatType.Excel2007Xlsx:
case FileFormatType.Excel2007Xlsm:
case FileFormatType.Excel2007Xltm:
case FileFormatType.Excel2007Xltx:
response.ContentType = “application/xlsx”;
break;
//case FileFormatType.SpreadsheetML:
// response.ContentType = “text/xml”;
// break;
default:
response.ContentType = “application/vnd.ms-excel”;
break;
}



int index = fileName.LastIndexOf(’\’);
if (index >= 0)
throw new Exception(“filename should not contain path”);

//added for http://www.aspose.com/Community/Forums/9361/ShowPost.aspx
//This is for http compression, however, it doesn’t work for ssl
if (compression)
{
HttpCachePolicy cache = response.Cache;
cache.SetExpires(DateTime.Now - TimeSpan.FromMinutes(1));
cache.SetCacheability(HttpCacheability.Private);

response.AddHeader(“pragma”, “no-cache”);
}

response.AddHeader(“Content-Length”, ms.Length.ToString());
//Add header
if (saveType == SaveType.OpenInExcel)
response.AddHeader(“content-disposition”, “attachment; filename=” + fileName);
else
response.AddHeader(“content-disposition”, “inline; filename=” + fileName);
//4.8.1
//ms.WriteTo(response.OutputStream);
//4.5.1
response.BinaryWrite(ms.ToArray());
response.Flush();
response.End();
}


public static void CreateStaticReport()
{
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;

//put a string value into the cell
Cell cell = cells[0, 0];
cell.PutValue(“Hello World”);
//Put an boolean value into the cell
cell = cells[1, 0];
cell.PutValue(true);
//Put an int value into the cell
cell = cells[2, 0];
cell.PutValue(100);
//Put an double value into the cell
cell = cells[3, 0];
cell.PutValue(2856.5);
//Put an string value that can be converted to other data type if appropriate
cell = cells[4, 0];
cell.PutValue(“123.6”, true);
//Put an object value into the cell
cell = cells[5, 0];
object obj = “Aspose”;
cell.PutValue(obj);
//Put an datetime value into the cell
cell = cells[6, 0];
DateTime dt = DateTime.Now;
cell.PutValue(dt);
Style style = workbook.Styles[workbook.Styles.Add()];
style.Number = 14;
cell.SetStyle(style);
Save(workbook,“Hello world.xls”,FileFormatType.Default,SaveType.OpenInExcel,false,System.Web.HttpContext.Current.Response);


}

Hopefully it helps to sort out the things.

Thank you.