How to Open Excel File in Browser, Not in Excel Application

how can i open a excel inside a web browser?

You can't control and launch software on the client (browser) computer - why? Security.

If this was possible, hackers would have taken over all computers long ago...

Can you please explain exactly what you are trying to do? Instead of asking how to open excel from the browser, if you explain what you need to accomplish, perhaps we can come up with a better idea.

Open Excel file url in excel (from source, not downloaded copy)

No it is not possible for security reasons. All newer browsers (and I guess even the newer implementations of IE), don't allow file access to the local system. Internet Explorer is the only browser that supports opening files from locations, that are seen and treated as local ones.

You can open files from a Webdav Server, which is probably, why you can access files from your SharePoint, so you could try mapping that provider of your network drive as a Webdav Server.

Source: AND
Is there an Application URL Protocol for MS Word?

Excel File opening in browser not calling Excel

Your code doesn't create an Excel file, it creates a CSV file. The content type isn't Excel-specific either. A browser may decide that Excel is the appropriate application to open this text file or not.

Even if the browser selects Excel, opening the file may fail, eg if the client's locale uses , as a decimal separator. This is common in European countries. In this case Excel expect ; as the field separator and may open the CSV as a single text block.

Instead of trying to trick the browser into opening a CSV in Excel, create a real Excel file using a library like EPPlus. EPPlus is available as a Nuget package so it's very easy to add it to your project.

The library's documentation contains an article on how to use it in Web applications. Once you remove the formatting code from the example, the code is very simple:

   private void DumpExcel(DataTable tbl)
using (ExcelPackage pck = new ExcelPackage())
//Create the worksheet
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Demo");

//Load the datatable into the sheet, starting from cell A1. Print the column names on row 1
ws.Cells["A1"].LoadFromDataTable(tbl, true);

//Write it back to the client
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment; filename=ExcelDemo.xlsx");

Excel files are compressed which means that sending the file to the client will be a lot faster, especially for large files

Open excel file through normal html link

HTTP is a stateless protocol. What that means for you is that when your users download a file from the intranet via http, they are downloading a copy, rather than the original. Any changes they make will only appear in their copy, and then you end up with loads of copies of the same workbook with different, possibly overlapping changes. You don't want that!

And also ... how are your users even going to upload their changes?

You need to create a shared folder on your network and put the workbook there. You can then use the file:///SERVER/PATH/FILE.xls format in your <a /> links on your intranet to direct your user to the actual file on the server.

I would recommend you start by creating a simple html doc on your desktop to get familiar with the file:/// path format.

<head />
<a href="file:///SERVER/PATH/FILE.xls">Click</a>

save that in notepad and rename the extension from .txt to .html.

You can also type file:/// paths straight into windows explorer's address bar which allow for testing paths without resorting to the html document mentioned above.

UNFORTUNATELY! It seems that the browsers default behavior is to always download a link rather than open it (even if it is a local resource), so if you actually want to open it then you must resort to changing your browser intranet permissions to allow JS to access local resources, which then allows you to use the technique below.

This article ( uses

<script type="text/javascript" language="javascript">
function RunFile() {
WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("c:/windows/system32/notepad.exe", 1, false);

to open notepad. You can use command line arguments with Excel.exe ( to tell it what the file path is...

Excel.exe "C:\PATH\Excel.xls"

Related Topics

Leave a reply