与 COM 交互

动态类型

using System;

//创建简单的 Excel 表格
var excelType = Type.GetTypeFromProgID("Excel.Application");
dynamic excel = Activator.CreateInstance(excelType);
excel.workbooks.Add();
dynamic worksheet = excel.ActiveSheet;

worksheet.Cells[1, 1] = 3;
worksheet.Cells[2, 1] = 5;
worksheet.Cells[3, 1] = "=sum(R[-2]C[0]:R[-1]C[0])";

excel.Visible = true;