How do I copy an Array to an Excel Range in C#?
Why does the below code not work?
If I assign it like this, then in each cell is the same value
Workbook workbook;
Worksheet worksheet;
List<double> flow = new List<double>();
workbook = excel.Workbooks.Open(filename);
worksheet = workbook.Worksheets.Add();
worksheet.Range[$"$A$1:$A{flow.count}"].Value = flow.ToArray();
Of course the list is filled with values. I have omitted this part here.
CodePudding user response:
replace your last line with
Excel.Range range = sheetSource.UsedRange.Columns[columnIndx];
range.Value = application.WorksheetFunction.Transpose(flow.ToArray());