您的位置:首页 > 其它

winform中 将listview的数据导出至 excel (最简单的方法)

2010-09-15 15:37 471 查看
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();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: