2016-08-04 52 views
0

我写了一个程序来做到这一点,但有一个例外,说使用未安装Microsoft Office的C#着色Excel工作表单元格?

Retrieving the COM class factory for component with 
CLSID {00024500-0000-0000-C000-000000000046} 
failed due to the following error: 80040154 
Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). 

如何解决这个例外,我该如何使用C#来颜色的Excel工作表细胞?

下面是代码:

using Excel = Microsoft.Office.Interop.Excel; 
using System.Reflection; 
using System.Windows; 
using System.Drawing; 
using Microsoft.Office.Interop.Excel; 
using System; 

namespace Project32 
{ 
    public class Class1 
    { 
     static void Main() 
     { 
      Application excel = new Application(); 
      Workbook wb = excel.Workbooks.Open(@"C:\Users\mvmurthy\Downloads\IDBDeviceReport.rdlc"); 
      Worksheet ws = wb.Worksheets[1]; 
      ws.Cells[1, 1].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red); 
     } 
    } 
} 
+0

有什么问题吗?这是关于你得到的例外或你的文章的标题? –

+0

有没有解决这个异常的解决方案,否则解决方案标题会很好 – manvitha

回答

3

当您使用Microsoft.Office.Interop命名空间为“自动” Excel中通过COM那么相应的微软Office产品,必须在计算机上安装。

否则,您将不得不切换到某种第三方库,使您能够直接读取/写入文件而不依赖于Microsoft Office软件。

库可能要考虑到:

  • EPPlus
  • 的OpenXML
  • ClosedXML
相关问题