在Microsoft Excel中显示arraylist

时间:2011-10-18 08:42:02

标签: c# asp.net excel c#-4.0

如何在ms excel中显示创建的arraylist?         请指导我..

1 个答案:

答案 0 :(得分:1)

添加对Microsoft.Office.Interop.Excel程序集的引用 然后尝试这个(只是一个想法,而不是完整和完美的代码):

using Excel = Microsoft.Office.Interop.Excel;

Excel.Application excel = new Excel.Application();
Excel.Workbook wb = excel.Workbooks.Open("filename");
Excel.Worksheet sh = wb.Sheets[1]; // or wb.Sheets["name"]
int row = 2;
foreach (string item in array)
{
    sh.Cells[row,col].Value2 = item;
    row++;
}
wb.Save();
wb.Close();
excel.Quit();