Click here to Skip to main content
15,886,639 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
Hi,

How to view excel file in ASP.Net page using c#?

I need to view excel file in asp.net form and access the all excel functionality in this excel sheet.
Note:
Excel sheet will open inside the form tag, it means open within a page, not open separate file.

Like: Update fields, Merge fields, Wrap cells, Format the fields and apply text color. whatever Excel sheet have functionality all will be work asp.net excel page.

Thanks in Advance

--
Mohankumar. S
Posted
Updated 25-Mar-15 3:42am
v4
Comments
Sinisa Hajnal 25-Mar-15 9:40am    
Unless you're using online office, you cannot. Do you?

1 solution

Excel files can use open format based on Open XML standard, but it has nothing to do with W3 standards and is foreign to the Web.

There is no such concept as "embedding". You can simply store Excel and other office files on the server. To present them, you have to use HTML. You can develop some mapping between your dynamic HTML representing, say, a spreadsheet, and Excel document. This is quite possible to implement based, in particular, on ASP.NET System.Web.UI.WebControls.GridView:
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview%28v=vs.110%29.aspx.

Is some page or on some HTTP request, you can open requested Excel document on the server side, read it and create some data source out of it, create and populate a grid view. You can bind the data source with the grid view (https://msdn.microsoft.com/en-us/library/fkx0cy6d(v=vs.110).aspx). If the document is supposed to be read/write, you can generate a new Excel file based on the updated data source.

To work with data, I would recommend to use Microsoft Open XML SDK (and not Office interop). Please see this CodeProject article:
Creating basic Excel workbook with Open XML.

See also Microsoft warnings against using Office interop in server sittings:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2,
http://support.microsoft.com/kb/257757/en-us.

See also my past answer with references to other answers and other links: How to add microsoft excel 15.0 object library from Add Reference in MS Visual Studio 2010.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900