In C#, using Microsoft.Office.Interop.Excel
, you can assign values to an entire row at once like this:
string[] headings = { "Value1", "Value2", "Value3" };
excelSheet.get_Range("A1:C1", Type.Missing).Value2 = headings;
Is there any similar functionality provided in the EPPlus library?
You could use the .LoadFromCollection
method.
So, for example:
var vals = new string[] { "value1", "value2", "value3" };
var rng = sheet.Cells["A1:A3"];
rng.LoadFromCollection(vals);
will produce this output:
A little clunky but here is an example.
// 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 });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With