|
if (this.FileUpload1.PostedFile != null)
{
string filename = this.FileUpload1.FileName.ToString();
string path = @Server.MapPath("../File/") + filename;
this.FileUpload1.PostedFile.SaveAs(path);
//讀取用戶上傳的Excle文件
string conn="Provider = Microsoft.Jet.OLEDB.4.0 ;Data Source ='"+path+"';Extended Properties=Excel 8.0";
OleDbConnection olecon = new OleDbConnection(conn);
olecon.Open();
//注意表名,打開Excel文件后,最底部分頁的Excle名字,
//默認是$Sheet1,$Sheet2,$Sheet3
string sql = "select * from [$Sheet1]";
OleDbDataAdapter oleda = new OleDbDataAdapter(sql,conn);
oleda.Fill(ds);
olecon.Close();
this.GridView1.DataSource = ds;
this.GridView1.DataBind();
string file_name = "20091126002.xml";
string xml_path = @Server.MapPath("../Reports/xml/") + file_name;
ds.WriteXml(xml_path);
ds.Dispose();
}
AspNet技術:asp.net下將Excel轉成XML檔的實現代碼,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。