Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否在未安装Microsoft Office的情况下使用C#为Excel表格单元格着色?_C#_Excel_Visual Studio_Exception_Exception Handling - Fatal编程技术网

是否在未安装Microsoft Office的情况下使用C#为Excel表格单元格着色?

是否在未安装Microsoft Office的情况下使用C#为Excel表格单元格着色?,c#,excel,visual-studio,exception,exception-handling,C#,Excel,Visual Studio,Exception,Exception Handling,我写了一个程序来做这件事,但得到了一个例外,说 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)

我写了一个程序来做这件事,但得到了一个例外,说

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); 
        }
    }
}

当您使用
Microsoft.Office.Interop
命名空间通过COM“自动化”Excel时,必须在计算机上安装相应的Microsoft Office产品

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

可能需要考虑的图书馆:

  • 艾普拉斯
  • OpenXML
  • ClosedXML

当您使用
Microsoft.Office.Interop
命名空间通过COM“自动化”Excel时,必须在计算机上安装相应的Microsoft Office产品

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

可能需要考虑的图书馆:

  • 艾普拉斯
  • OpenXML
  • ClosedXML

问题是什么?是关于你得到的例外还是你文章的标题?有没有解决这个例外的办法,否则标题的办法就好了问题是什么?是关于你得到的异常还是你文章的标题?有没有解决这个异常的方法,否则标题的方法就可以了