c#中的工作表
本文关键字:工作 | 更新日期: 2023-09-27 17:54:55
我使用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)).
你试过用NativeExcel这样做吗?
我认为它很有用。
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");
}
}