Free Support Forum - aspose.com

Using Aspose.Excel inside a framework

I am trying to use Aspose.Excel inside a framework, and it does not work because framework is injecting some code in all html pages and as a result content type is messed up. However if I link to static XLS file everything works fine.

could you please tell me how can I modify the following form to produce the results similar to static xls file.

i.e. if I have href="static.xls" - it works fine, but
when I have href="simple_download.aspx" it does not work.

<%@ Page language="c#" Codebehind="simple_download.aspx.cs" AutoEventWireup="false" Inherits="simple_download" %>



simple_download



http://schemas.microsoft.com/intellisense/ie5">






using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using Aspose.Excel;

namespace test
{

///

/// Summary description for simple_download.

///

public class simple_download : System.Web.UI.Page

{

private void Page_Load(object sender, System.EventArgs e)

{

Excel excel = new Excel();

string pathToLicenseFile = "~/Aspose/Aspose.Report.lic";

Excel.SetLicense(this.Request.MapPath(pathToLicenseFile));

this.Response.ContentType= "text/csv";

excel.Worksheets[0].Cells[0,0].PutValue("TEST");

excel.Worksheets[0].Cells[0,0].Style.Font.Size=16;

excel.Save("Simple.xls", SaveType.OpenInExcel, FileFormatType.Default, this.Response);

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}


///

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

///

private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

}

}

Hi Igor,

With OpenInExcel or OpenInBrowser option, Aspose.Excel set the content type and response header as following:

response.ContentType = “application/vnd.ms-excel”;
//Add header
if(saveType == SaveType.OpenInExcel)
response.AddHeader( “content-disposition”,“attachment; filename=” + resultSpreadsheet);
else
response.AddHeader( “content-disposition”,“inline; filename=” + resultSpreadsheet);
Because we don’t know how your framework messed up the content type, we cannot test it in our machines.
You can try:
1. Save the file to disk and provide a static link to your users.
2. Save the file to MemoryStream and manipulate it by your own code.