Excel.Save as aspx (SSL?)

Laurence,

We have recently upgraded a client of ours with the Aspose.Cells version 3.8.0.2, along with the latest version of our product. Recently they were running Aspose.Excel ver.3.1.1.0. We are running the new version at existing clients as well as on all our development and testing servers with no issue. At the client we just upgraded, we are seeing this behavior.... When the save dialog opens, the file name contains the name of the aspx page instead of the excel file, and the File Type is blank. On all other servers, the file name will contain the name of the excel file and the file type will be Microsoft Excel Worksheet.

The only difference I can see on this server from others is that they are using SSL. Other than that the set-up is pretty standard (Windows 2000, excel 2003) and like I said it worked fine before with the old code. A snippet from the new code is as follows.......

oExcel.Save(oEmpManager.Text & "_Merit_Workbook.xls", SaveType.OpenInExcel, MyFileFormatType, Response)

the MyFileFormatType variable is setting the type to "FileFormatType.Excel2003".

The only thing in the code that may be different from the past is that we used to set the content type of the header, after we called both Response.ClearHeaders() and Response.Clear(), now just call the previous methods and then do not set the Content Type and like i said it works great everywhere except this machine that uses SSL.

Any Thaoughts?

Thanks as always.

-Scott

Hi Scott,

I think this problem may be caused by http headers. I changed some http headers settings to solve a problem with http compression.

I think you can save the data into a memory stream and send the file to client with your own code. Then you can handle the http headers.

Following is my sample code to send file to client with OpenInExcel option:

response.Clear();

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


// this piece of code is to solve http compression issue
HttpCachePolicy cache = response.Cache;
cache.SetExpires(DateTime.Now - TimeSpan.FromMinutes(1));
cache.SetCacheability(HttpCacheability.Private);

response.AddHeader("pragma","no-cache");


// Set OpenInExcel option
if(saveType == SaveType.OpenInExcel)
response.AddHeader( "content-disposition","attachment; filename=" + resultSpreadsheet);

By the way, have you tried to access this ssl server with another client machine?

Laurence,

this behavior is exhibited when trying to download a sheet on the server. Are you saying that there may be no problem downloading from an actual client machine?

Scott

Yes. As I know, this problem may be caused by:

1. Client browser is not updated to latest windows patch.

2. Http headers setting.

3. Generating Excel file in event other than Page_Load event.

Laurence,

The save excel dialog still won't recognize the excel file. It is asking to download the .aspx page still. Here is the code as implemeted as per your suggestion. I tested on my dev machine before promotion and it works great here but when I send it to the SSL machine it is still broken..... (this has always contained in a button click event)

Dim oExcel As Excel

Dim oSettings As New JGIM.BusinessLayer.Settings(ConfigurationSettings.AppSettings("WebConfigLocation"))

oExcel = oXLSGenerator.CreateWorkbookInMemory(ConfigurationSettings.AppSettings("InsertIntroductionPage"), _

ConfigurationSettings.AppSettings("StartwithTemplateWorkbook"), _

sExcelTemplateXLS, _

sExcelTemplateXML, _

oSettings, _

colGroupsToExport, _

String.Empty, _

oEmpManager, _

JGIM_WorksheetTemplateOptions.AutoDetect)

Dim MyFileFormatType As FileFormatType

Select Case ConfigurationSettings.AppSettings("ExcelOutputFormat").ToLower

Case "XP"

MyFileFormatType = FileFormatType.ExcelXP

Case "2003"

MyFileFormatType = FileFormatType.Excel2003

Case "2000"

MyFileFormatType = FileFormatType.Excel2000

Case "default"

MyFileFormatType = FileFormatType.Default

Case Else

MyFileFormatType = FileFormatType.ExcelXP

End Select

Dim _filename As String = oEmpManager.Text & "_Merit_Workbook.xls"

Response.Clear()

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

Dim cache As HttpCachePolicy = Response.Cache

cache.SetExpires(DateTime.Now.Subtract(TimeSpan.FromMinutes(1)))

cache.SetCacheability(HttpCacheability.Private)

Response.AddHeader("pragma", "no-cache")

Response.AddHeader("Content-Disposition", "attachment; filename=" & _filename)

oExcel.Save(_filename, _

SaveType.OpenInExcel, _

MyFileFormatType, _

Response)

Response.End()

Hi Scott,

Does old Aspose.Excel work fine with SSL? If yes, please change your code to:

Dim oExcel As Excel

Dim oSettings As New JGIM.BusinessLayer.Settings(ConfigurationSettings.AppSettings("WebConfigLocation"))

oExcel = oXLSGenerator.CreateWorkbookInMemory(ConfigurationSettings.AppSettings("InsertIntroductionPage"), _

ConfigurationSettings.AppSettings("StartwithTemplateWorkbook"), _

sExcelTemplateXLS, _

sExcelTemplateXML, _

oSettings, _

colGroupsToExport, _

String.Empty, _

oEmpManager, _

JGIM_WorksheetTemplateOptions.AutoDetect)

Dim MyFileFormatType As FileFormatType

Select Case ConfigurationSettings.AppSettings("ExcelOutputFormat").ToLower

Case "XP"

MyFileFormatType = FileFormatType.ExcelXP

Case "2003"

MyFileFormatType = FileFormatType.Excel2003

Case "2000"

MyFileFormatType = FileFormatType.Excel2000

Case "default"

MyFileFormatType = FileFormatType.Default

Case Else

MyFileFormatType = FileFormatType.ExcelXP

End Select

Dim _filename As String = oEmpManager.Text & "_Merit_Workbook.xls"

Response.Clear()

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

Response.AddHeader("Content-Disposition", "attachment; filename=" & _filename)

dim stream as MemoryStream = new MemoryStream()

oExcel.Save(stream, _MyFileFormatType)

Response.BinaryWrite(stream.ToArray())

Response.End()

If old Aspose.Excel also doesn't work with SSL, please try to put your code in Page_Load event.

Laurence,

Old Aspose.Excel does indeed work with the SSL. I will try your code with the stream.

Laurence,

That did it. It works with the SSL now.

Thanks,

Scott