用ADO向Excel批量匯入資料

2021-08-22 18:26:10 字數 917 閱讀 8782

和前面一篇用oledb的方法類似,我們可以用ado從recordset物件向excel批量插入資料,這個方法無法自動複製欄位名。

我們需要引用ado和excel的com物件

參考**如下

using system;

using system.collections.generic;

using system.text;

using system.reflection;

using excel=microsoft.office.interop.excel;

static

void exportdatatoexcel( string connectionstring, string sql, string filename, string sheetname)

;" +connectionstring, "" , "" ,0);

adodb.recordsetrs= new adodb.recordsetclass();

rs.open(sql,conn,adodb.cursortypeenum.adopenstatic,adodb.locktypeenum.adlockreadonly,0);

excel.rangerange=ws.get_range( "a2" ,missing.value);

range.copyfromrecordset(rs,65535,65535);

} catch (exceptionex)

finally }

} }

用ADO向excel批量匯入數

和前面一篇用oledb的方法類似,我們可以用ado從recordset物件向excel批量插入資料,這個方法無法自動複製欄位名。我們需要引用ado和excel的com物件 參考 c code using system using system.collections.generic using sy...

用ADO向Excel批量匯入資料

和前面一篇用oledb的方法類似,我們可以用ado從recordset物件向excel批量插入資料,這個方法無法自動複製欄位名。我們需要引用ado和excel的com物件 參考 如下 using system using system.collections.generic using system...

用QueryTable向excel批量匯入資料

前面寫過兩篇excel操作的文章,有朋友質疑大批量資料下的效能問題,這個時候最好用批量複製的方法,可以用excel的querytable來直接查詢資料庫,但是必須引用com元件。參考 using system using system.collections.generic using system...