以下是我转载得来,有待于继续实践,因为全是代码,而没有语言叙述的流程,所以比较乱
1using System;
2using System.Collections;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Web;
7using System.Web.SessionState;
8using System.Web.UI;
9using System.Web.UI.WebControls;
10using System.Web.UI.HtmlControls;
11//*************************************
12public class DataSetToExcel
13 {
14 public DataSetToExcel(){}
15 public void Convert(DataSet oDS,HttpResponse Response)
16 {
17 Response.Clear();
18 Response.Charset = "";
19 Response.ContentType = "application/vnd.ms-excel";
20 System.IO.StringWriter oSW = new System.IO.StringWriter();
21 HtmlTextWriter oHW = new HtmlTextWriter(oSW);
22 DataGrid oDG = new DataGrid();
23 oDG.DataSource = oDS.Tables[0];
24 oDG.DataBind();
25 oDG.RenderControl(oHW);
26 Response.Write(oSW.ToString());
27 Response.Flush();
28 Response.Close();
29 }
30 }
31//*********************************************************
32调用这个类就OK了
33
34
35
36(2)
37
38using System;
39using System.Data;
40using System.Data.OleDb;
41namespace GRIS.ExcelReprot
42{
43 /** <summary>
44 /// ImportExportToExcel 的摘要说明。
45 /// </summary>
46 public class ImportExportToExcel
47 {
48 private string strConn ;
49
50 private System.Windows.Forms.OpenFileDialog openFileDlg=new System.Windows.Forms.OpenFileDialog();
51 private System.Windows.Forms.SaveFileDialog saveFileDlg=new System.Windows.Forms.SaveFileDialog();
52
53 public ImportExportToExcel()
54 {
55 //
56 // TODO: 在此处添加构造函数逻辑
57 //
58 this.openFileDlg.DefaultExt = "xls";
59 this.openFileDlg.Filter = "Excel文件 (*.xls)|*.xls";
60
61 this.saveFileDlg.DefaultExt="xls";
62 this.saveFileDlg.Filter= "Excel文件 (*.xls)|*.xls";
63
64 }
65
66从Excel文件导入到DataSet#region 从Excel文件导