引用 using Microsoft.Office.Interop.Excel;
加入參考
private void SaveAsExcel(ListView list, string text)
{
//text为些Excel的标题
Microsoft.Office.Interop.Excel.Application ss = new Microsoft.Office.Interop.Excel.Application();//开启Excel
ss.Application.Workbooks.Add(true);
ss.Visible = true;
ss.Cells[1, 4] = text;
for (int x = 1; x <= list.Columns.Count; x++)
{
ss.Rows.Cells[2, x] = list.Columns[x - 1].Text;
}
for (int i = 3; i <= list.Items.Count + 2; i++)
{
for (int j = 1; j <= list.Columns.Count; j++)
{
ss.Rows.Cells[i, j] = list.Items[i - 3].SubItems[j - 1].Text + ",";
}
}
}
//listview不得有空白
沒有留言:
張貼留言