婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > asp.net讀取excel中的數據并綁定在gridview

asp.net讀取excel中的數據并綁定在gridview

熱門標簽:電銷機器人 數據 地圖標注多少錢一張 ai電銷機器人對貸款有幫助嗎 宿遷智能外呼系統排名 廣州銷售外呼系統定制 怎樣給陜西地圖標注顏色 400電話辦理信任翰諾科技 云狐人工智能電話機器人 福州人工智能電銷機器人加盟
前臺label,DropDownList,gridview控件

aspx.cs核心代碼:
復制代碼 代碼如下:

using System.Data.OleDb;//需要引入命名
public void Excel_Click(object sender, EventArgs e)
{
if (this.AttachmentFile.Value == "" this.Label1.Text == "" DropDownList2.SelectedValue == "")
{
Response.Write("script>window.alert('請選擇要導入的文件')/script>");
}
if (this.AttachmentFile.Value != "" this.DropDownList2.SelectedValue == "")
{
HttpFileCollection files = HttpContext.Current.Request.Files;
HttpPostedFile postedFile = files[0];
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
postedFile.SaveAs("\\\\localhost\\文件夾\\" + fileName);
}
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "\\\\localhost\\文件夾\\" + fileName + ";Extended Properties=Excel 8.0;";//this.AttachmentFile.Value.ToString()
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataTable sheetNames = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
foreach (DataRow dr in sheetNames.Rows)
{
DropDownList2.Items.Add(dr[2].ToString());
}
this.Label1.Text = "\\\\localhost\\文件夾\\" + fileName;//this.AttachmentFile.Value.ToString();
conn.Close();
}
if (this.Label1.Text.ToString() != "" this.DropDownList2.SelectedValue != "")// this.DropDownList1.SelectedValue.ToString() != "全部"
{

//綁定到gridview
GridView1.DataSource = createDataSource(DropDownList2.SelectedValue.ToString(), this.Label1.Text.ToString());//, this.DropDownList1.SelectedValue.ToString()
GridView1.DataBind();


}


}
//以Excel為數據源獲取數據集
private DataSet createDataSource(string select, string lable)

{
string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + lable + ";Extended Properties=Excel 8.0;";
string strsql = "select 登記號碼,姓名,日期,簽到時間,簽退時間,部門 from [" + select + "] order by 部門,日期,姓名";//excel表格的字段
OleDbConnection conn = new OleDbConnection(strCon);
OleDbDataAdapter da = new OleDbDataAdapter(strsql, conn);
try
{
conn.Open();
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
return ds;
}
catch (Exception e)
{
Response.Write("script>window.alert('沒有數據,或者" + e.Message + "')/script>");
return null;
}
}

以上是插入07以前版本excel

如果07版本以后只需要做小小修改
復制代碼 代碼如下:

string strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + lable + ";Extended Properties=Excel 12.0;";
您可能感興趣的文章:
  • asp.net gridview代碼綁定
  • asp.net ListView 數據綁定
  • asp.net中將數據庫綁定到DataList控件的實現方法與實例代碼
  • asp.net中綁定TextBox回車事件的解決方法
  • asp.net中ListBox 綁定多個選項為選中及刪除實現方法
  • ASP.NET中ListView(列表視圖)的使用前臺綁定附源碼
  • asp.net數據綁定DataBind使用方法
  • Asp.net中的數據綁定Eval和Bind應用示例
  • ASP.NET MVC數組模型綁定詳解

標簽:焦作 大興安嶺 綿陽 曲靖 延安 新疆 黃南 宜春

巨人網絡通訊聲明:本文標題《asp.net讀取excel中的數據并綁定在gridview》,本文關鍵詞  asp.net,讀取,excel,中的,數據,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《asp.net讀取excel中的數據并綁定在gridview》相關的同類信息!
  • 本頁收集關于asp.net讀取excel中的數據并綁定在gridview的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 涞源县| 洛隆县| 建昌县| 库伦旗| 南陵县| 大田县| 湘西| 白河县| 洪湖市| 新昌县| 浮山县| 黑河市| 建平县| 福鼎市| 腾冲县| 武邑县| 唐河县| 霍城县| 长宁县| 承德市| 兴海县| 广河县| 水富县| 石城县| 富阳市| 安陆市| 太仆寺旗| 呈贡县| 肇庆市| 聂拉木县| 大安市| 中阳县| 金寨县| 潜山县| 教育| 舟山市| 逊克县| 垦利县| 古交市| 山丹县| 广平县|