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

Free Support Forum - aspose.com

OpenInExcel using ASP.NET MVC

I am looking for an advice how to open newly created Excel workbook from Controller of ASP.NET MVC. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

VS2010 does not like line:

workbook.Save("book1.xls", FileFormatType.Excel97To2003, Aspose.Cells.SaveType.OpenInExcel, this.Response);

saying the method has some invalid arguments.

I appreciate your help.

Thanks,

Vlado

Hi,
I noticed 2nd and 3rd arguments are not as expected. Interchange your 2nd and 3rd arguments as below.

workbook.Save(“book1.xls”, Aspose.Cells.SaveType.OpenInExcel, FileFormatType.Excel97To2003, this.Response);

For more details please visit the following:
http://www.aspose.com/documentation/.net-components/aspose.cells-for-.net/saving-files.html

Example Code Snippet:
=============================
Workbook workbook = new Workbook();

Worksheets sheets = workbook.Worksheets;

Cells cells = sheets[0].Cells;

cells[“A1”].PutValue(1234);

workbook.Save(“book1.xls”, SaveType.OpenInExcel, FileFormatType.Excel97To2003, Response);

=============================

thanks

You are right: there were not in correct order, but it did not help. The same error.


Vlado

Hi,

Well, if you are building
a web application, please use the Aspose.Cells.dll in the net2.0 directory.<o:p></o:p>

The dll in net3.5_ClientProfile directory is used only for the console application with Net frame client profile. For complete reference, please check the readme.txt in the bin directory.


Thank you.


Yes, this is what I used. Not the one from net_ClientProfile

Vlado

For oders to use I put down here how to open Excel file in browser using ASP.NET MVC from a controller:

MemoryStream stream = new MemoryStream();
workbook.Save(stream, FileFormatType.Excel97To2003);
WriteStream(stream, resultFileName);


private static void WriteStream(MemoryStream memoryStream, string excelFileName)

{
HttpContext context = System.Web.HttpContext.Current;
context.Response.Clear();
context.Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", excelFileName));
memoryStream.WriteTo(context.Response.OutputStream);
memoryStream.Close();
context.Response.End();
}

I hope somebody finds this helpful.

Vlado