在C#中,使用Microsoft.Office.Interop.Excel
,您可以像这样将值立即分配给整行:
string[] headings = { "Value1", "Value2", "Value3" };
excelSheet.get_Range("A1:C1", Type.Missing).Value2 = headings;
EPPlus库中是否提供任何类似的功能?
有点笨拙,但这是一个示例。
// A row of numbers
var numbers = new List<object> {1.1, 2.2, 3.3};
var horizontalRange = sheet.Cells[$"A1:A{numbers.Count}"];
horizontalRange.LoadFromArrays(new List<object[]> {numbers.ToArray()});
// a grid
var colours = new object[] { "red", "green", "blue"};
var range2d = sheet.Cells["A3:C4"];
range2d.LoadFromArrays(new List<object[]> { numbers.ToArray(), colours });