how to insert data into excel sheet using C#?

前端 未结 2 1338
無奈伤痛
無奈伤痛 2021-01-14 14:24

i want to create new excel sheet and insert data into it, from string array. i used the following code to create, now i want to insert data.

    Excel.Applic         


        
2条回答
  •  悲&欢浪女
    2021-01-14 15:03

    Calling COM methods is very slow. If you plan to insert a lot of data, I recommend you fetch the entire range you need, set all values, and add it back:

    var range = xlWorkSheet.get_Range[firstCell, lastCell]; // or string range
    var data = (object[,])range.get_Value(XlRangeValueDataType.xlRangeValueDefault);
    // Set data here. Remember it's 1 based index, and row (y component) first
    range.set_Value(data);
    

提交回复
热议问题