gpt4 book ai didi

c# - 使用范围 C# 将字符串列表写入 excel

转载 作者:太空宇宙 更新时间:2023-11-03 22:40:13 24 4
gpt4 key购买 nike

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

最佳答案

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

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

关于c# - 使用范围 C# 将字符串列表写入 excel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52624127/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com