You must Sign In to post a response.
  • Category: ASP.NET

    Open excel file in browser

    hI

    pl help me how do i open excel file in browers, should i need to use iframe or any other method. am working on asp.net with vb.net
  • #766769
    Hi

    you can try this steps for open excel sheet


    Right Click in your excel sheet -> open with -> then selected Browser
    now you can see the excel sheet in browser window


    if you code wise try this code

    Client side only . Html code only


    <iframe src="file:\\Book1.xls" width="100%" height="500"></iframe>
    <iframe id="ifrm1" runat="server" src="~/Book1.xls" width="400" height="800"></iframe>

    <iframe id="ifm2" runat="server" ></iframe>


    if you need server side

    C-sharp code


    ifm2.Attributes.Add("src", Server.MapPath("~\\Book1.xls"));


    Vb.net Code


    iframe.Attributes.Add("src", Server.MapPath("~\\Book1.xls"))


    Hope it will helpful to you.

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #766770
    you can open Excel files in browser, you can use IFrame for that, but problem is you need to use Virtual path only, I mean IFrame does not accept physical path in its 'src' attribute, see below snippet
    I got some code which is ASP.NET Document Viewer – Display PDF, Word, Excel & 50+ Other Types of Document
    see below link
    https://code.msdn.microsoft.com/ASPNET-Document-Viewer-e7c2a39f
    OR
    Embed Google Doc Viewer in your own webpage to display any kind of documents including Excel files. It's very simple to use and free! Add a markup code like the following in your webpage

    < iframe src="http://docs.google.com/gview?url=URL_TO_YOUR_EXCEL_FILE_HERE&embedded=true" style="width:600px; height:500px;" frameborder="0">< /iframe>

    or you can use javascript and ActiveXObject object to open excel object, see below snippet

    var objExcel;
    objExcel = new ActiveXObject("Excel.Application");
    objExcel.Visible = true;
    objExcel.Workbooks.Open(//file Path);

    see link for more details
    http://www.codeproject.com/Articles/237193/Open-Word-Excel-using-JavaScript

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #766785
    it is not working for me.. i have copy pasted above lines.

    <iframe src="file:\\Book1.xls" width="100%" height="500"></iframe>
    <iframe id="ifrm1" runat="server" src="~/Book1.xls" width="400" height="800"></iframe>
    <iframe id="ifm2" runat="server" ></iframe>

    ~/Book1.xlsx not found error

    and in Page Load
    ifm2.Attributes.Add("src", Server.MapPath("~\\Book1.xlsx"));
    }

    Am getting only blank iframe in browser


Sign In to post your comments