Reputation: 4630
How can I add values to 5 cells on the same row at once?
This is how add them right now:
ws.Cells[1, 1] = "1";
ws.Cells[1, 2] = "2";
ws.Cells[1, 3] = "3";
ws.Cells[1, 4] = "4";
ws.Cells[1, 5] = "5";
Upvotes: 3
Views: 1449
Reputation: 14537
Use a range and an array :
var rng = (Excel.Range)ws.Range[ws.Cells[1, 1], ws.Cells[1, 5]];
rng.Value = new int[] { 1, 2, 3, 4, 5 }; // one dimensional array
Upvotes: 4