This project has moved and is read-only. For the latest updates, please go here.

How to display excel file without using SaveAS method

Jan 22, 2011 at 6:07 AM

Thanks for your wonderful ClosedXML. I am new to ClosedXML and i am trying to display my data to Excel. But in sample code SaveAS method used.

Do we have any way to disply the excel file instead of saving ?


Jan 22, 2011 at 6:30 AM

Nope, I have so much left to do with ClosedXML I can only dream of building a spreadsheet component. You'd have to use a commercial software for that...

Jan 22, 2011 at 6:40 AM

Thanks for reply. I think i didn't expalin clearly. I want to display the data instead of saving(SaveAS Method) by using ClosedXML.

Jan 22, 2011 at 7:05 AM

Then I don't understand what you mean by "display the data". Please clarify that...

Jan 22, 2011 at 9:06 AM

@kartookforyou:  you can simply read cell by cell and display it in a gridview right?.

Jan 22, 2011 at 4:21 PM

Just i used your Hello World code.Its saving the xlsx file in a directory. I want to open a excel file in browser and i want to display the Hello World.

Thanks for your replies.

Jan 22, 2011 at 8:47 PM

This is used to create Excel files not to display them in any way. You'll have to get a commercial component if you want to display the spreadsheets on your web page.

If you only want to present the data then do as prasun said and build your table/grid manually. Although I don't see the point in putting values in a spreadsheet only to put the same values into an html table and discard the spreadsheet.

Jan 23, 2011 at 4:40 AM

Thanks for your reply. So we can't use this in a web based report generation application as file will be stored in Server. Please let me where exactly ClosedXML will be used ?


Jan 23, 2011 at 5:13 AM

The most common use for this component is to generate Excel reports and then let users download them to their computers. In the case of web applications the Excel report can be streamed to the browser and thus never have to be saved to disk at all.

Jan 24, 2011 at 1:53 AM

I am really very sorry.I didn't understand your points. My requirement is very simple. In my application,i have to take records from database and display to a browser in spreadsheet(excel) format Or allow to save in client machine as spreadsheet(excel) format.

Please let me know whether i can use ClosedXML.

Jan 24, 2011 at 3:02 AM

"i have to take records from database and display to a browser in spreadsheet(excel) format "

You don't typically display the data on a browser with a spreadsheet. You use a table/grid.

"Or allow to save in client machine as spreadsheet(excel) format."

You can do that with this component.


For more information on how to create data driven websites go to ASP.NET

Jan 25, 2011 at 2:02 AM

Currently our excel report generation application is in VB 6. My manager wants to convert VB to Web application(ASP.Net) and wants to display the data in excel to perform the financial calculations and they don't want to display in table/grid. What i understood from your code is i have to save the excel document in server and then i have to open and send the streaming data to client to display in browser.

Please let me know if i am wrong. As a new developer i am learning so many things from your code.


Jan 25, 2011 at 4:11 AM

That scenario is very common. In that case you won't be displaying a spreadsheet on the browser. Instead you'll let your users download a report in Excel. For that you don't have save the file to disk if you don't want/have to.

Here's what you need to do:

  1. Create a web page that will serve the Excel files.
  2. On an event (probably a button click) create the spreadsheet for your user.
  3. Instead of saving the workbook you can use code like the following to serve the Excel file (I shamelessly copied this piece of code from GFraser):

Response.Buffer = True
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"
Response.AddHeader("Content-Disposition", "attachment; filename=Report.xlsx")
Response.Charset = ""

Jan 26, 2011 at 7:52 AM
Edited Jan 26, 2011 at 7:55 AM

Dear kartookforyou,

I think this is what you are looking for.

let us know if it helps

Nov 29, 2013 at 8:12 AM
First of all i like to appriciate for such a useful functionality.
I like to use it, My requirement is as below..
(1)Working on a wpf application with mvvm design pattern. Having the requirement to export to excel(independent of excel installation, should be compatible with 32bit and 64 bit both) the nested(master and child) datagrid data.
(2)I also have the requirement to format the header cells and also merge the cells from where child data suppose to start. as following

I think i can achieve all this using closed xml with fast speed, am i right?

I have few doubts.
(1)i am not able to run the examples. While i am trying to run ClosedXML_Examples.exe it throws error of object reference and redirects to debug point "f (opCell.FormulaReference.FirstAddress.Equals(opCell.Address))". Before it, i have corrected the excel file locations as D:\drive does not exist on my machine. Can you help me how can i make it running.
(2)I read somewhere in reviews that it doesn't work properly or gives out of memory exception when no. of record is more then 1000, is this true...any correction made in the latest version?

Please help me with the above so i can start using codeplex and meet my deadlines.
Dec 2, 2013 at 8:34 PM
(1) The file that defines where the excel files get created is CreateFiles.cs in the Creating directory of the ClosedXML_Examples project.
(2) I have created Excel files with over 100,000 rows no problem.