C Excel匯入資料到資料庫

2021-06-21 15:58:07 字數 1443 閱讀 8879



//專案中用到的乙個小例子,拿出來和大家分享    ,需要引用 

using system.io;

using system.data.oledb;

///

/// excel資料匯入datable

///

///

///

///

public datatable getexceldatatable(string fileurl, string table)

;extended properties='excel 8.0;imex=1';";

//支援.xls和.xlsx,即包括office2010等版本的   hdr=yes代表第一行是標題,不是資料;

const string cmdtext = "provider=microsoft.jet.oledb.4.0;data source=;extended properties=\"excel 8.0; hdr=yes; imex=1;\"";

system.data.datatable dt = null;

//建立連線

oledbconnection conn = new oledbconnection(string.format(cmdtext, fileurl));

trysystem.data.datatable schematable = conn.getoledbschematable(oledbschemaguid.tables, null);

//獲取excel的第乙個sheet名稱

string sheetname = schematable.rows[0]["table_name"].tostring().trim();

//查詢sheet中的資料

string strsql = "select * from [" + sheetname + "a:h]";

oledbdataadapter da = new oledbdataadapter(strsql, conn);

dataset ds = new dataset();

da.fill(ds, table);

dt = ds.tables[0];

return dt;

}catch (exception exc)

finally

}///

/// 從system.data.datatable匯入資料到資料庫

///

///

///

public bool insetdata(system.data.datatable dt)

trycatch (exception ex)

return flag;

datatable dt = getexceldatatable(path, "人才資訊");

bool flag = insetdata(dt);

匯入Excel資料到資料庫

oracle下匯入excel資料 如下 using system.data using system.data.oledb using system.data.oracleclient 根據路徑得到excel檔案資料 public datatable getexceldata string file...

匯入檔案到資料庫

include include include seetime.h include writeoff inc.h db user fee detail db user fee detail connection amsconn char sql 1024 ind user fee detail by...

iView匯入Excel資料到資料庫

1.前端使用的是iview的upload上傳元件 2.後端使用的是excelpackage,當然可以使用npoi 3.效果圖 後端 如下 1 匯入 int rowcounr int math.ceiling decimal decimal worksheet.cells.count 8 所有 數 列...