Results 1 to 6 of 6

Thread: [RESOLVED] launching excel from asp.net app

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    In A House :)
    Posts
    291

    Resolved [RESOLVED] launching excel from asp.net app

    i have an app that outputs a gridview to excel spreadsheet and adds a couple of rows for accounting.

    i'm trying to launch the spreadsheet after its saved off, using

    Code:
                excelApp.ActiveWorkbook.SaveAs(filename);
                excelApp.ActiveWorkbook.Saved = true;
                excelApp.Quit();
                var si= new ProcessStartInfo {FileName = filename, UseShellExecute = true}; //hits here and crashes
                Process.Start(si);
    it hits the marked line and crashes that it cant find the file, its automatically saving it to the documents folder on my local machine, and i cant seem to get it to save elsewhere (i have a data directory in the project i use for the other file types) that i would like to save to if possible, but it seems that if you have office installed it don't like it. i could always copy the file from documents to the datastore, but that's a pain in the backside.

    so how do i launch excel application using the file i just saved off to show to the bean crunchers? VB examples will work as well, i can translate
    Last edited by DirtyHowi; Apr 17th, 2013 at 11:40 AM.
    --"Tap Dancing On The Brittle Edge Of Sanity"--

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Re: launching excel from asp.net app

    You can't launch Excel from ASP.NET because the file will be opened on the SERVER and not your computer. What you can do is process the file and serve it for the client to download it.

  3. #3
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: launching excel from asp.net app

    Caution! Microsoft votes heavily against the usage of the office interops in an asp.net environment. I found out the hard way.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    In A House :)
    Posts
    291

    Re: launching excel from asp.net app

    Quote Originally Posted by sapator View Post
    Caution! Microsoft votes heavily against the usage of the office interops in an asp.net environment. I found out the hard way.
    then remove it from the framework this is an internal application only, we are licensed to the hilt all i use it for is creating the file.

    i'll look at the download thing unless someone wants to throw the old dog a bone with some code
    --"Tap Dancing On The Brittle Edge Of Sanity"--

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Location
    In A House :)
    Posts
    291

    Re: launching excel from asp.net app

    for those interested
    Code:
                excelApp.ActiveWorkbook.SaveAs(Server.MapPath(filename));
                excelApp.ActiveWorkbook.Saved = true;
                excelApp.ActiveWorkbook.Close();
                excelApp.Quit();
                Response.Clear();
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", "attachment;filename=" + fileorig + ".xlsx");
                Response.WriteFile(filename+".xlsx");
                Response.Flush();
                Response.End();
    works to open the file from the server after it's saved.
    --"Tap Dancing On The Brittle Edge Of Sanity"--

  6. #6
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: [RESOLVED] launching excel from asp.net app

    Whatever.
    "Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment."

    http://support.microsoft.com/kb/257757
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

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