我只是使用一个简单的代码来编写一个字符串列表到 excel 如下
Excel.Application excelApp = new Excel.Application();
string myPath = Environment.CurrentDirectory + path + "\\reselts.xlsx";
excelApp.Workbooks.Open(myPath);
List <string> allterms = new List<string>(alltext.Split(' '));
allterms= allterms.Distinct().ToList();
allterms.RemoveAll(String.IsNullOrEmpty);
for (int i = 1; i < allterms.Count + 1; i++ )
{
excelApp.Cells[i, 1] = allterms[i];
}
excelApp.Visible = true;
但我得到一个错误“索引超出范围”!我的程序有什么问题?请问有什么帮助吗?