日期:2014-05-18 浏览次数:20802 次
private void button11_Click(object sender, System.EventArgs e) { Excel.Application myExcel = new Excel.Application(); myExcel.Application.Workbooks.Add(true); myExcel.Visible = true; //Object Date[ds.Tables["CurrentTable"].Rows.Count][ds.Tables["CurrentTable"].Columns.Count]; //生成标题 for (int i = 0; i < ds.Tables["gzdw"].Columns.Count; i++) { myExcel.Cells[1, i + 1] = ds.Tables["gzdw"].Columns.Caption; } //填充数据 for (int i = 0; i < ds.Tables["gzdw"].Rows.Count; i++) { for (int j = 0; j < ds.Tables["gzdw"].Columns.Count; j++) { if (ds.Tables["gzdw"].Rows[j].GetType() == typeof(System.String)) { myExcel.Cells[i + 3, j + 1] = "'" + ds.Tables["gzdw"].Rows[j].ToString(); } else { myExcel.Cells[i + 3, j + 1] = ds.Tables["gzdw"].Rows[j].ToString(); } } } this.Cursor = Cursors.Default; MessageBox.Show("导出成功! ", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); }