private void button1_Click(object sender, EventArgs e)
{
OperateExcel(listView1, "第一章");
}
//导出数据
public void OperateExcel(ListView list, string text)
{
Excel.Application ss = new Excel.Application();
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.ToString();
}
}
}