我有一个包含一些数据的列表数组。目前我可以在控制台中看到输出,现在尝试添加到 excel 文件中。谁能解释我如何做到这一点。这是创建 excel 表并向其写入内容的代码。但是我如何结合这两个代码来查看 excel 中的输出。我尝试了几种组合,但无法写入 excel。我是 c# 的新手。在此先感谢!
foreach (Match m in linkParser.Matches(html))
{
list.Add(m.Value);
Console.WriteLine(m.Value);
}
Excel.Application oApp; // to open excel
Excel.Worksheet oSheet;
Excel.Workbook oBook;
oApp = new Excel.Application();
oBook = oApp.Workbooks.Add();
oSheet = (Excel.Worksheet)oBook.Worksheets.get_Item(1);
string fileTest = "output123.xlsx";
if (File.Exists(fileTest))
{
File.Delete(fileTest);
}
oSheet.Cells[1, 1] = "some value";
oBook.SaveAs(fileTest);
oBook.Close();
oApp.Quit();