首页 > 解决方案 > 使用范围 C# 将字符串列表写入 excel

问题描述

我有一个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?

标签: c#excel

解决方案


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

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

推荐阅读