vb 实现 数据快速导入excel
***********************************************************************/
* function name: toexcel */
* input arguments: */
* out arguments : */
* : */
* description : */
* author : by yarno qq:84115357 */
* date : 2005-11-25 */
***********************************************************************/
public function toexcel()
on error goto errorhandler
dim exlapp as excel.application
dim exlbook as excel.workbook
set exlapp = createobject(“excel.application”)
set exlbook = exlapp.workbooks.add
exlapp.caption = “数据正在导出……”
exlapp.visible = true
exlapp.displayalerts = false
dim exlsheet as excel.worksheet
set exlsheet = exlbook.worksheets.add
exlsheet.activate
set exlsheet = exlsheet
exlsheet.name = “我导出的数据”
设置列宽
exlapp.activesheet.columns(1).columnwidth = 10
exlapp.activesheet.columns(2).columnwidth = 20
strsql = “你的sql语句”
set exl_rs = pubsyscn.execute(strsql)
exlsheet.range(“a2”).copyfromrecordset exl_rs
exl_rs.close
set exl_rs = nothing
exlapp.worksheets(“sheet1”).delete
exlapp.worksheets(“sheet2”).delete
exlapp.worksheets(“sheet3”).delete
exlapp.displayalerts = true
exlapp.caption = “数据导出完毕!!”
exlapp.visible = true
set exlapp = nothing
set exlbook = nothing
set exlsheet = nothing
exit function
errorhandler:
msgbox “excel : ” & err.number & ” : ” & err.description
end function