找回密码
 加入
搜索
查看: 2324|回复: 2

[系统综合] mdb导出到excel有时候只有表单!

[复制链接]
发表于 2014-4-17 21:07:36 | 显示全部楼层 |阅读模式
$SaveExcel = FileSaveDialog("选择保存Excel路径", "", "Excel文件 (*.xls)", 2 + 16, "报价单.xls")
        If @error Then
        Else
                $addfld = ObjCreate("ADODB.Connection")
                $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
                $sQuery = "SELECT * FROM " & $tblname
                $RS = ObjCreate("ADODB.Recordset")
                $RS.ActiveConnection = $addfld
                $RS.open($sQuery)
                Local $intCount = $RS.Fields.Count
                $oExcel = _ExcelBookNew(1) ; Create an Excel Object
                $oExcel.WorkBooks.Add ; Add a new workbook
                For $i = 1 To $intCount Step +1
                        $oExcel.ActiveWorkBook.ActiveSheet.Cells(1, $i).value = $RS.Fields($i - 1).name
                Next
                $oExcel.ActiveWorkBook.ActiveSheet.Cells(2, 1).CopyFromRecordset($RS) ; Fill a cell
                $oExcel.Columns.AutoFit
                $oExcel.ActiveWorkBook.Saved = 1 ; Simulate a save of the Workbook
;~                 _ExcelColumnDelete($oExcel, 1, 1) ;删除第 1 列, 且仅删除 1 列
                _ExcelBookSaveAs($oExcel, $SaveExcel, "xls", 0, 1)
                _ExcelBookClose($oExcel)
                $oExcel = 0
                If MsgBox(64 + 1, "导出成功!", "是否打开报表?") = 1 Then ShellExecute($SaveExcel)
        EndIf
导出之后有时候正常,有时候就只有表单,如图

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2014-4-19 14:38:02 | 显示全部楼层
$oExcel = _ExcelBookNew(1) ; Create an Excel Object
改为试试
$oExcel = _ExcelBookNew(0) ; Create an Excel Object
 楼主| 发表于 2014-4-19 18:01:02 | 显示全部楼层
回复 2# chzj589


    一样的,这个试过了。现在解决了。。
$oExcel.WorkBooks.Add ; Add a new workbook
把这行删了。每次都成功
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 09:33 , Processed in 0.077200 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表