在服务器上托管时出现问题 [英] Issue when hosting on server

查看:72
本文介绍了在服务器上托管时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private static Microsoft.Office.Interop.Excel.Workbook mWorkBook;
 private static Microsoft.Office.Interop.Excel.Sheets mWorkSheets;
 private static Microsoft.Office.Interop.Excel.Worksheet mWSheet1;
 private static Microsoft.Office.Interop.Excel.Application oXL;
 public void ReadExistingExcel()
 {
    // string path = @"F:\\tempExcel.xls";
     string fileName = "../Admin/Excel/tempExcel.xls";
     string path = Server.MapPath(fileName);

     oXL = new Microsoft.Office.Interop.Excel.Application();
     oXL.Visible = true;
     oXL.DisplayAlerts = false;
     mWorkBook = oXL.Workbooks.Open(path, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
     //Get all the sheets in the workbook
     mWorkSheets = mWorkBook.Worksheets;
     //Get the allready exists sheet
     mWSheet1 = (Microsoft.Office.Interop.Excel.Worksheet)mWorkSheets.get_Item("Sheet1");
     Microsoft.Office.Interop.Excel.Range range = mWSheet1.UsedRange;
     int colCount = range.Columns.Count;
     int rowCount = range.Rows.Count;
     for (int index = 1; index < 15; index++)
     {
         mWSheet1.Cells[rowCount + index, 1] = rowCount + index;
         mWSheet1.Cells[rowCount + index, 2] = "New Item" + index;
     }

 }





我在我的网络应用程序中使用了这段代码在asp.net中。为此,我包括一个DLL文件microsoft.office.interop.excel.dll。它在当地运作良好。但是当在线托管它显示错误。请帮助我..



我尝试过:



一旦我从web配置中删除了以下行

< add assembly =stdole,Version = 7.0.3300.0,Culture = neutral,PublicKeyToken = B03F5F7F11D50A3A>

该网站正在运行,但无法读取和写入excel



I have used this code in my web application in asp.net. For that i include an dll file microsoft.office.interop.excel.dll. It is working fine in local . But when hosting online it shows error.Please help me..

What I have tried:

Once i removed the following line from web config
<add assembly="stdole, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A">
the site is working but cant read and write on excel

推荐答案

您忘记告诉我们错误是什么。最可能的罪魁祸首是错误80040154,这意味着Office未安装在服务器上。



您应该阅读以下Microsoft知识库文章:

You've forgotten to tell us what the error is. The most likely culprit would be error 80040154, which means that Office is not installed on the server.

You should read the following Microsoft knowledgebase article:



Microsoft目前不建议也不支持从任何无人参与的非交互式客户端应用程序或组件(包括ASP,ASP.NET,DCOM和NT服务)自动化Microsoft Office应用程序,因为Office可能会出现不稳定的行为, /或在此环境中运行Office时出现死锁。


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.



有多种方法可以在不使用Office互操作的情况下在服务器上读取和创建Excel电子表格。例如:

  • EPPlus [ ^ ];
  • ClosedXML [ ^ ];
  • ExcelDataReader [ ^ ] ;
  • OpenXML SDK [ ^ ];

  • There are various ways to read and create Excel spreadsheets on the server without using Office interop. For example:

    • EPPlus[^];
    • ClosedXML[^];
    • ExcelDataReader[^];
    • The OpenXML SDK[^];

    • 在服务器上部署word / excel(自动化dll)时,需要在服务器上获得额外权限才能运行COM组件

      I有一些工作你可以试试

      是II II还是7你得到错误?请解释错误代码和异常消息,以便我能为您提供更多帮助
      When you deploy an word/excel (automation dll) on server it needs an extra permission on server to run COM component
      I have some work around that you can try out
      Is it II6 or 7 you get error ? please explain with error code and exception message so that I will help you more


      这篇关于在服务器上托管时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆