c 讀寫Excel及資料匯入SQLServer

2021-09-09 05:14:47 字數 1501 閱讀 7049

c++ 讀寫excel及資料匯入sqlserver

c++操作excel ,網上的資料還是比較多的,寫這篇文章也是分享給初學者一些經驗。                 

本人 覺得cspreadsheet.h這個類封裝的還不錯。下面我就如何使用這個類介紹一下,

main.cpp/

#include #include#include#include "cspreadsheet.h"

using std::string;

#pragma warning(disable:4146)

#pragma warning(disable:4786)

#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("eof","adoeof")

//插入到資料庫

bool insertexcel(cstring str1,cstring str2)

cstring sql("insert into students(myname,age) values('"+ str1+"','"+str2+"')");

m_db.executesql(sql);

if(m_db.isopen())

return true;

}

catch(_com_error e)

}//獲取路徑

cstring getaddr()

//得到驅動

cstring getexceldriver()

pszbuf = strchr(pszbuf, '\0') + 1;

}while (pszbuf[1] != '\0');

return sdriver;

}

//讀取excel

void readfromexcel()

; for (int i = 2; i < ss.gettotalrows()+1; i++)

printf("\n");

if(!insertexcel(sitem[1],sitem[2]))

}}

}catch(cdbexception, e)

end_catch;

}//寫excel

void writefromexcel(int num,cstring str1,cstring str2,cstring str3)

}//查詢

bool selectexcel()

m_precordset->close();

// 關閉資料庫連線

if(m_pconnection!=null)

}

catch(_com_error e)

}int main()

mian.cpp

讀寫Excel資料

獲取odbc中excel驅動 include include cstring cxxdlg getexceldriver pszbuf strchr pszbuf,0 1 while pszbuf 1 0 return sdriver 寫入excel void cxxdlg onwriteexcel...

Excel資料匯入

excel資料匯入 你hold住麼 一 在本篇將帶領大家一同了解 匯入excel流程和問題解決方案 需要注意的是在server端的web config 中新增這幾行 ps 中value 是根據自己的專案中的資料夾的命名而定,可參考以下截圖 由於在server的配置檔案的檔名不一致。找不excel的x...

Excel資料匯入

private void button3 click object sender,eventargs e 連線excel的連線字串,excel2007版本以上的 hdr yes代表第一行是列名 string strconn provider microsoft.ace.oledb.12.0 data...