C#创建Excel文件的操作的具体过程是什么呢?那么这里向你介绍了具体的实现实例,是用什么方法可以实现呢,下面我们通过实例的演示向你具体介绍下。
C#创建Excel文件实例操作:
1. private void Button2_Click(object sender, System.EventArgs e)
2. {
3. object missing = System.Reflection.Missing.Value;
4. //Excel.Application myExcel = new Excel.Application() ;
5. myExcel = new Excel.ApplicationClass();
6.
7. Excel._Workbook xBk ;//工作薄
8. Excel._Worksheet xSt;//工作Sheet
9.
10. xBk = myExcel.Workbooks.Add(true);
11.
12. for (inti = 0; i < 5; i ++)
13. {
14.xSt = (Excel._Worksheet)xBk.ActiveSheet;
15.xSt.Name ="chenms_" + i ;
16.myExcel.Cells[2,2]="chenms";
17.if(i < 4)
18.{
19. myExcel.Sheets.Add(missing,missing,1,Excel.XlSheetType.xlWorksheet);
20.}
21. }//C#创建Excel文件
22. myExcel.Visible = true;
23. xBk.SaveAs(@"d:cms.xls",missing,missing,
24.missing,missing,missing,Excel.XlSaveAsAccessMode.xlShared,
25.missing,missing,missing,missing,missing);
26. // myExcel.Save(@"d:cms.xls");C#创建Excel文件
27. myExcel.Quit();
28. Response.ClearContent();
29. Response.ClearHeaders();
30. Response.AppendHeader("Content-Disposition","attachment;filename=d:cms.xls");
31. Response.Buffer = true;
32. Response.ContentType = "application/ms-excel";
33. //将报表文件存入本地
34. Response.WriteFile("d:cms.xls");
35. Response.Flush();
36. Response.Close();
37. //C#创建Excel文件之从磁盘删除导出的文件
38. System.IO.File.Delete("d:cms.xls");
39.
40.}
C#创建Excel文件的基本内容就向你介绍到这里,希望对你了解C#创建Excel文件有所帮助。