先引用 中添加.net: Microsoft.Office.Interop.Excel
再添加在文件头添加: using Excel = Microsoft.Office.Interop.Excel;
然后使用下面代码可写入Excel
var excelApp = new Excel.Application();
excelApp.Visible = true;
excelApp.Workbooks.Add();
Excel._Worksheet workSheet = (Excel.Worksheet)excelApp.ActiveSheet;
for (int i = 1; i < 9; i++)
for (int j = 1; j < 9; j++)
workSheet.Cells[i, j] = i + " " + j;