C# c语言工作表#

C# c语言工作表#,c#,worksheet,C#,Worksheet,我正在使用c#写入excel文件并为特定单元格着色。 我将代码用作: Workbook wbook = new Workbook(); Worksheet sheet1 = wbook.Worksheets[0]; sheet1.Columns[j].Style.BackgroundColor = System.Drawing.Color.DeepPink; wbook.SaveAs("E:\\new.xls"); System.Diagnostics.Proces

我正在使用c#写入excel文件并为特定单元格着色。 我将代码用作:

    Workbook wbook = new Workbook();
   Worksheet sheet1 = wbook.Worksheets[0];
  sheet1.Columns[j].Style.BackgroundColor = System.Drawing.Color.DeepPink;
   wbook.SaveAs("E:\\new.xls");
   System.Diagnostics.Process.Start("E:\\new.xls");
   wbook.Close();
但工作簿抛出了一个错误:

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

有人能帮忙吗?

你有没有试过这样做

我认为这很有用

using System; 
using NativeExcel; 

 class Program { 
     static void Main(string[] args) { 
         //Create a new empty workbook. 
         IWorkbook book = NativeExcel.Factory.CreateWorkbook(); 

         //Create a new sheet in the workbook. 
         IWorksheet sheet = book.Worksheets.Add(); 

         //Set a value for cell A1
         sheet.Cells["A1"].Value = 300;  
         //Set a value for cell A2
         sheet.Cells[2,1].Value = 200;  
         //Set a formula for cell A3
         sheet.Cells["A3"].Formula = "=SUM(A1:A2)";  

         //Save workbook
         book.SaveAs("book.xls");                
     } 
 }