Results 1 to 5 of 5

Thread: Forcing HTML file to open in Excel

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2006
    Posts
    507

    Forcing HTML file to open in Excel

    Hi All

    How can I make HTML file open in Excel programmatically? I can drag it into Excel and it will open no problem. but I need this done programmatically.

    The file is a download from webpage, it will prompt the user to Open or Save, I need when the user click Open it will open in Excel 2003/2007

    That is what I have now:

    Response.AddHeader("content-disposition", "attachment;filename="test.html");
    Response.ContentType = "application/ms-excel";
    Response.Buffer = true;
    System.IO.FileStream myFileStream = new System.IO.FileStream("test.html", System.IO.FileMode.Open);
    long FileSize = myFileStream.Length;
    byte[] Buffer = new byte[(int)FileSize];
    myFileStream.Read(Buffer, 0, (int)FileSize);
    myFileStream.Close();
    myFileStream.Dispose();
    Response.BinaryWrite(Buffer);
    Response.Flush();
    File.Delete(sPath);
    Response.Close();

    Thanks in advance

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Forcing HTML file to open in Excel

    That isn't possible.

    Your program is running on the web server and the users local machine is what gets to choose what program to open a file in.

    If you need this file opened in excel, why aren't you creating an excel file?

  3. #3
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Forcing HTML file to open in Excel

    @kfcSmitty: I wouldn't say impossible, if it does what he wants dragging the file into Excel. --> Command line arguments
    Code:
    "C:\Program Files\Microsoft Office\Office15\EXCEL.EXE" %USERPROFILE%\Desktop\index.html
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - 2018)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Forcing HTML file to open in Excel

    Quote Originally Posted by AceInfinity View Post
    @kfcSmitty: I wouldn't say impossible, if it does what he wants dragging the file into Excel. --> Command line arguments
    Code:
    "C:\Program Files\Microsoft Office\Office15\EXCEL.EXE" %USERPROFILE%\Desktop\index.html
    Yes, but how is a web application/site supposed to execute a commandline like that? Simply put, it can't. The web application is running in the user's browser so you'd have to get the browser to do it, but you don't choose what functionality the browser provides. If the file is to be opened in Excel then the user will have to do that themselves.

  5. #5
    Fanatic Member AceInfinity's Avatar
    Join Date
    May 2011
    Posts
    696

    Re: Forcing HTML file to open in Excel

    Ahh, I didn't notice the methods being used, I just seen the regular IO stuff, and there was no mention that this was ASP.
    <<<------------
    Improving Managed Code Performance | .NET Application Performance
    < Please if this helped you out. Any kind of thanks is gladly appreciated >


    .NET Programming (2012 - 2018)
    ®Crestron - DMC-T Certified Programmer | Software Developer
    <<<------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width