和前面一篇用oledb的方法類似,我們可以用ado從recordset物件向excel批量插入資料,這個方法無法自動複製欄位名。
我們需要引用ado和excel的com物件
參考**:
c# code
usingblog同步更新system;
using
system.collections.generic;
using
system.text;
using
system.reflection;
using
excel
=microsoft.office.interop.excel;
namespace
static
void
exportdatatoexcel(
string
connectionstring,
string
sql,
string
filename,
string
sheetname)
;"+connectionstring,"",
"",0);
adodb.recordset rs
=new
adodb.recordsetclass();
rs.open(sql, conn, adodb.cursortypeenum.adopenstatic, adodb.locktypeenum.adlockreadonly, 0);
excel.range range
=ws.get_range("a2
", missing.value);
range.copyfromrecordset(rs,
65535
, 65535
); }
catch
(exception ex)
finally}}
}
我的歷史攢分帖子
希望大家支援我的blog
用ADO向Excel批量匯入資料
和前面一篇用oledb的方法類似,我們可以用ado從recordset物件向excel批量插入資料,這個方法無法自動複製欄位名。我們需要引用ado和excel的com物件 參考 如下 using system using system.collections.generic using system...
用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...