如何一次在同一行的5个单元格中添加值?
这就是现在添加它们的方法:
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";
答案 0 :(得分:3)
使用范围和数组:
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