Reputation: 183
I wrote a program to do this but got an exception saying
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)).
How do I resolve this exception and how can I use C# to color Excel sheet cells?
Below is the code:
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);
}
}
}
Upvotes: 0
Views: 154
Reputation: 1356
When you are using the Microsoft.Office.Interop
namespace to "automate" Excel via COM then the respective Microsoft Office product has to be installed on the computer.
Otherwise you'll have to switch to some kind of third party library that enables you to read/write the files directly without depending on the Microsoft Office software.
Possible libraries to take into consideration:
Upvotes: 3