使用范围C#将字符串列表编写为Excel

时间:2018-10-03 09:40:43

标签: c# excel

我有一个出色的范围:

   Excel.Range range = Worksheet.get_Range("A1","A7");

还有一个字符串列表:

// The list contains the same amount of elements as cells in the range
List<string> AcollumnValues = getList(); 

到目前为止,我的代码:

        Excel.Application App = new Excel.Application();
        Excel.Workbook Workbook = App.Workbooks.Open(sourceASettings["file"]);
        Excel._Worksheet Worksheet = Workbook.Sheets[1];


        Excel.Range range = Worksheet.get_Range("A1","A4") userSupliedRangeArray[1]);
        List<string> valuesToWrite = getValuesToWrite();

如何使用范围将字符串列表写入excel?

1 个答案:

答案 0 :(得分:3)

您可能需要对此进行调整并解决一些小问题,但这应该可以解决问题(使用EPPlus):

int counter = 1;
foreach (string str in AcollumnValues) {
   worksheet.Cells["A" + counter].Value = str;
   counter++;
}