c# 将 WinForm 输出到 Excel
c# Output WinForm to Excel
已研究输出到 Excel 并且可以成功输出。如果我遗漏了一些更简单的东西,我的问题更多。
目前,如果我想设置单个单元格的字体、单元格颜色、大小等,我是这样操作的:
range = (Range)ws.Cells[10, 12];
range.Formula = "=SUM(R10C10:R10C11)";
range.Calculate();
range.Font.Bold = true;
range.Font.Underline = true;
range.Style = wb.Styles["Currency"];
range.Font.Color = Color.Red;
range.Font.Name = "Arial";
range.Font.Size = 26;
borders = range.Borders;
borders.LineStyle = XlLineStyle.xlContinuous;
borders.Weight = 2d;
我是否遗漏了文档中允许我在单个单元格上执行此操作而无需创建 Range
的内容?
不,C# 需要对象限定符(参见 What's the C# equivalent to the With statement in VB?。因此您当前的代码是协议。
已研究输出到 Excel 并且可以成功输出。如果我遗漏了一些更简单的东西,我的问题更多。
目前,如果我想设置单个单元格的字体、单元格颜色、大小等,我是这样操作的:
range = (Range)ws.Cells[10, 12];
range.Formula = "=SUM(R10C10:R10C11)";
range.Calculate();
range.Font.Bold = true;
range.Font.Underline = true;
range.Style = wb.Styles["Currency"];
range.Font.Color = Color.Red;
range.Font.Name = "Arial";
range.Font.Size = 26;
borders = range.Borders;
borders.LineStyle = XlLineStyle.xlContinuous;
borders.Weight = 2d;
我是否遗漏了文档中允许我在单个单元格上执行此操作而无需创建 Range
的内容?
不,C# 需要对象限定符(参见 What's the C# equivalent to the With statement in VB?。因此您当前的代码是协议。