以下是托管在服务器PC中时出现错误的代码。
try
{
//Variable Declarations
Microsoft.Office.Interop.Excel._Workbook oWB;
Microsoft.Office.Interop.Excel.Application oXL = null;
Microsoft.Office.Interop.Excel.Workbook workbook;
Microsoft.Office.Interop.Excel.Worksheet NwSheet = null;
Microsoft.Office.Interop.Excel.Worksheet NwSheetSummary;
Microsoft.Office.Interop.Excel.Worksheet NwSheetIndividualTotal;
Microsoft.Office.Interop.Excel.Range ShtRange;
Microsoft.Office.Interop.Excel.Sheets sheets;
Microsoft.Office.Interop.Excel.ApplicationClass excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
excel.Workbooks.Add(System.Reflection.Missing.Value);
excel.Quit();
excel = null;
//Opening Excel file(myData.xlsx)
workbook = excel.Workbooks.Open(System.Web.HttpContext.Current.Server.MapPath("~/Template/Template.xlsx"), Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
sheets = workbook.Worksheets;
foreach (Worksheet ws in sheets)
{
if (ws.Index == 5)
NwSheet = ws;
if (ws.Index == 1)
NwSheetSummary = ws;
if (ws.Index == 4)
NwSheetIndividualTotal = ws;
}
//Reading Excel file.
//Creating datatable to read the containt of the Sheet in File.
System.Data.DataTable dt = export.Tables[0];
int rowCount = 8;
if (dt.Columns.Contains("RowID"))
dt.Columns.Remove("RowID");
if (dt.Columns.Contains("Week"))
dt.Columns.Remove("Week");
if (dt.Columns.Contains("Year"))
dt.Columns.Remove("Year");
foreach (DataRow dr in dt.Rows)
{
rowCount += 1;
for (int i = 1; i < dt.Columns.Count + 1; i++)
{
// Add the header the first time through
if (rowCount == 8)
{
//NwSheet.Cells[1, i] = dt.Columns[i - 1].ColumnName;
}
NwSheet.Cells[rowCount, i] = dr[i - 1].ToString();
}
}
for (int count = 0; count <= dt.Rows.Count; count++)
{
// NwSheet.get_Range("A9", Missing.Value).Value2 = dt.Rows[count]["SlNo"].ToString();
}
workbook.RefreshAll();
String path = Convert.ToString(ConfigurationManager.AppSettings["DefaultPath"]);
CreateFileOrFolder(workbook, week);
NwSheet = null;
ShtRange = null;
workbook.Close(Missing.Value, Missing.Value, Missing.Value);
workbook = null;
oXL.Quit();
excel.Quit();
//appExl.Quit();
status = true;
}
现在它在我的本地PC上运行正常,它有Interop Excel 12.0
但在托管在具有相同12.0
的服务器机器时却没有。
收到的错误是
由于以下错误,检索CLSID为{00024500-0000-0000-C000-000000000046}的组件的COM类工厂失败:80070005。
在搜索到错误之后,我已经通过其他论坛,他们已经提到了give rights to Network Services to Microsoft Excel Application in dcomcnfg
。我做了同样的事情,但没有用。
它没有成功,我得到了同样的错误。 喜欢 :- Configuration of dcomcnfge
说哪是: -
转到控制面板 - &gt;管理工具 - &gt;组件服务 - &gt;计算机 - &gt; myComputer - &gt; DCOM配置 - &gt; Microsoft Excel应用程序。 - &GT;右键单击以获取属性对话框。转到“安全”选项卡并相应地自定义权限。
我已尽力给予所有可能的权利,但仍然存在错误。!!
请帮助..