C#导入导出EXCLE

时间:2014-09-29 15:59:37
【文件属性】:

文件名称:C#导入导出EXCLE

文件大小:23KB

文件格式:DOC

更新时间:2014-09-29 15:59:37

C# 导入 导出 EXCLE

private void ToExcel() { Excel.ApplicationClass MyExcel = new Excel.ApplicationClass(); MyExcel.Visible = true; if (MyExcel == null) { MessageBox.Show("EXCEL无法启动!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Workbook wbook = MyExcel.Application.Workbooks.Add(Type.Missing); Worksheet worksheet = (Worksheet)wbook.Worksheets[1]; //worksheet.Name = "aa"; int rowcount = 0; //行号 int columncount = 0; //列号 //MyExcel.Application.Workbooks.Add(true); //加入表 columncount = this.dataGridView1.ColumnCount; //等于DATA表里行的总数 rowcount = this.dataGridView1.RowCount; //等于DATA表里列的总数 rowcount--; //因为打开dataGridView1时是默认新增的,所以要-1条记录数 //MessageBox.Show(rowcount.ToString()); //Excel文件的格式是从1开始,不是0开始 for (int m = 1; m < columncount; m++) //去除dataGridView1的编号列,即m=1,如m=0出错 {


网友评论