
ExcelWrapper
代碼如下:
/// <summary>
/// 查詢EXCEL電子表格添加到DATASET
/// </summary>
/// <param name="filenameurl">文件路徑</param>
/// <param name="table">dataset中的表名(并不是要和數(shù)據(jù)庫(kù)中的表一樣)</param>
/// <returns></returns>
public static DataSet ExecleDs(string filenameurl, string table)
{
string strConn = "Provider=Microsoft.Jet.OleDb.4.0;"
+ "data source=" + filenameurl + ";Extended Properties='Excel 8.0; HDR=YES; IMEX=1'";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataSet ds = new DataSet();
OleDbDataAdapter odda = new OleDbDataAdapter("select * from [Sheet1$]", conn);
odda.Fill(ds, table);
return ds;
}
.cs
代碼如下:
// 提交按鈕
protected void imgbtnSubmit_Click(object sender, ImageClickEventArgs e)
{
try
{
if (!FileUpload1.HasFile)
{
JsHelper.Alert("請(qǐng)您選擇Excel文件", this);
return;
}
// 取得文件后綴名
新聞熱點(diǎn)
疑難解答
圖片精選