用的操作系统是win2003,开发环境.net2003 webform
执行m_oExcelApp= new Excel.ApplicationClass();
报错,报错信息:拒绝访问。 谁有webform下导出excel程序能否给份源码?
QQ:87221857  
[email protected]

解决方案 »

  1.   

    web.config中设模拟身份就不会报错了
    <identity impersonate="true"  />
      

  2.   

    try
    {
    Application exc = new Application();
    if (exc == null) 
    {
    Response.Write("ERROR: EXCEL couldn't be started!");

    }

    Workbooks workbooks = exc.Workbooks;
    _Workbook workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet); 
    Sheets sheets = workbook.Worksheets;
    _Worksheet worksheet = (_Worksheet) sheets.get_Item(1);
                   
    if (worksheet == null) 
    {
    Console.WriteLine ("ERROR: worksheet == null");
    }
    Range range1 = worksheet.get_Range("C1", Type.Missing);
    if (range1 == null) 
    {
    Console.WriteLine ("ERROR: range == null");
    }
    const int nCells = 1;
    Object[] args1 = new Object[1];
    args1[0] = nCells;
    range1.GetType().InvokeMember("Value", BindingFlags.SetProperty, null,range1, args1);
    exc.Visible=true;

    FileName = "temp.xls";
           
                    string fullFileName   = Path.Combine(Environment.CurrentDirectory, FileName);
    fullFileName = Path.GetFullPath("WebForm1.");
    if(File.Exists(fullFileName).Equals(true))
    {
       File.SetAttributes(fullFileName, FileAttributes.Normal);
    }
    exc.DisplayAlerts = false;
                    workbook.SaveAs(fullFileName,string.Empty,string.Empty,string.Empty,string.Empty,string.Empty,Excel.XlSaveAsAccessMode.xlExclusive,string.Empty,string.Empty,string.Empty,string.Empty,string.Empty);
                  
    if( File.Exists(fullFileName).Equals(true))
    {
    File.SetAttributes(fullFileName, FileAttributes.ReadOnly);
    } }
    catch(Exception e )
    {
       throw e;
    }