如何运行DataSet并插入Excel(不是.csv文件)?
我在C#,Visual-studio 2008,Excel 2007上工作
提前谢谢
答案 0 :(得分:3)
您需要查看Office Interop Libraries,请参阅此示例来自here。
Microsoft.Office.Interop.Excel.Application xl =
new Microsoft.Office.Interop.Excel.Application();
xla.Visible = true;
Workbook wb = xla.Workbooks.Add(XlSheetType.xlWorksheet);
Worksheet ws = (Worksheet)xla.ActiveSheet;
int i = 1;
int j = 1;
foreach (ListViewItem comp in lvwResults.Items)
{
ws.Cells[i, j] = comp.Text.ToString();
//MessageBox.Show(comp.Text.ToString());
foreach (ListViewItem.ListViewSubItem drv in comp.SubItems)
{
ws.Cells[i, j] = drv.Text.ToString();
j++;
}
j = ;1;
i++;
}
这当然要求您在运行该程序的机器上安装了Excel。
答案 1 :(得分:2)