无法加载文件或程序集'Microsoft.Office.Interop.Excel,Version = 12.0.0.0,Culture = neutral,PublicKeyToken = 71e9bce111e9429c'

时间:2012-08-14 14:17:53

标签: c# sql-server-2005 import-from-excel

当我添加foll时代码但在服务器上显示错误。 代码 -

 object oMissing = System.Reflection.Missing.Value;
                        Microsoft.Office.Interop.Excel.ApplicationClass xl = new Microsoft.Office.Interop.Excel.ApplicationClass();
                        Microsoft.Office.Interop.Excel.Workbook xlBook;
                        Microsoft.Office.Interop.Excel.Worksheet xlSheet;
                        xlBook = (Workbook)xl.Workbooks.Open(docPath, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
                        xlSheet = (Worksheet)xlBook.Worksheets.get_Item(1);
                        xlSheet.Name = "Sheet1";
                        xlBook.Save();
                        xl.Application.Workbooks.Close();

错误 -

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.

我在webApplication中添加了“Microsoft.Office.Interop.Excel”dll的引用。 在当地它的工作正常。 注意:在服务器中,未安装Microsoft Office。 任何人都可以在服务器上没有任何安装的情况下解决这个问题。

1 个答案:

答案 0 :(得分:2)

如果不安装excel,则无法使用 Microsoft.Office.Interop.Excel 。但您可以在服务器上使用EPPlus