Write to an Excel file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Randy

    Write to an Excel file

    Hello,
    I'm trying to figure out how to do the above. I'm using a snippet of code I
    found on the net (see below). My problem is when I hit the line (oXL = new
    Excel.Applicati on();) I get an exception which says..."Access is Denied".
    Does anyone know what I'm doing wrong?

    string strFileName = null;
    string fileName = "Hockey";
    Excel.Applicati on oXL;
    Excel._Workbook oWB;
    Excel._Workshee t oSheet;

    oXL = new Excel.Applicati on();
    oXL.Visible = false;
    oWB= (Excel._Workboo k)(oXL.Workbook s.Add( Missing.Value ));
    oSheet = (Excel._Workshe et)oWB.ActiveSh eet;
    oSheet.Cells[1,1]="this is a test value";
    ((Range)oSheet. Cells[1,1]).ColumnWidth = 45;
    ((Range)oSheet. Cells[1,1]).EntireColumn. WrapText=true;
    oWB.SaveAs(file Name,Excel.XlFi leFormat.xlWork bookNormal, null, null,false,
    false, Excel.XlSaveAsA ccessMode.xlSha red, false, false, null,
    null, null);
    // Below line will kill the unkilled Excel process

    Process[] pProcess;
    pProcess = System.Diagnost ics.Process.Get ProcessesByName ("Excel");
    pProcess[0].Kill();

    oSheet= null;
    oWB = null;
    oXL = null;


  • Randy

    #2
    Re: Write to an Excel file

    I found some information on the net that talked about having to handling
    user rights to spawn Excel through the <identity> tag in the web.config
    file?
    Does anyone know what this is about?


    Comment

    • Alvin Bruney [MVP - ASP.NET]

      #3
      Re: Write to an Excel file

      which line is dying?

      --
      Regards,
      Alvin Bruney - ASP.NET MVP

      [Shameless Author Plug]
      The Microsoft Office Web Components Black Book with .NET
      Now available @ www.lulu.com/owc, Amazon.com etc
      "Randy" <temp@temp.co m> wrote in message
      news:eDcnjflVFH A.3944@TK2MSFTN GP10.phx.gbl...[color=blue]
      >I found some information on the net that talked about having to handling
      >user rights to spawn Excel through the <identity> tag in the web.config
      >file?
      > Does anyone know what this is about?
      >[/color]


      Comment

      Working...