C#创建Excel文件的操作的具体过程是什么呢?那么这里向你介绍了具体的实现实例,是用什么方法可以实现呢,下面我们通过实例的演示向你具体介绍下。
C#创建Excel文件实例操作:
- private void Button2_Click(object sender, System.EventArgs e)
- {
- object missing = System.Reflection.Missing.Value;
- //Excel.Application myExcel = new Excel.Application() ;
- myExcel = new Excel.ApplicationClass();
- Excel._Workbook xBk ;//工作薄
- Excel._Worksheet xSt;//工作Sheet
- xBk = myExcel.Workbooks.Add(true);
- for (inti = 0; i < 5; i ++)
- {
- xSt = (Excel._Worksheet)xBk.ActiveSheet;
- xSt.Name ="chenms_" + i ;
- myExcel.Cells[2,2]="chenms";
- if(i < 4)
- {
- myExcel.Sheets.Add(missing,missing,1,Excel.XlSheetType.xlWorksheet);
- }
- }//C#创建Excel文件
- myExcel.Visible = true;
- xBk.SaveAs(@"d:cms.xls",missing,missing,
- missing,missing,missing,Excel.XlSaveAsAccessMode.xlShared,
- missing,missing,missing,missing,missing);
- // myExcel.Save(@"d:cms.xls");C#创建Excel文件
- myExcel.Quit();
- Response.ClearContent();
- Response.ClearHeaders();
- Response.AppendHeader("Content-Disposition","attachment;filename=d:cms.xls");
- Response.Buffer = true;
- Response.ContentType = "application/ms-excel";
- //将报表文件存入本地
- Response.WriteFile("d:cms.xls");
- Response.Flush();
- Response.Close();
- //C#创建Excel文件之从磁盘删除导出的文件
- System.IO.File.Delete("d:cms.xls");
- }
C#创建Excel文件的基本内容就向你介绍到这里,希望对你了解C#创建Excel文件有所帮助。
【编辑推荐】