mdb导出到excel有时候只有表单!
$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导出之后有时候正常,有时候就只有表单,如图
$oExcel = _ExcelBookNew(1) ; Create an Excel Object
改为试试
$oExcel = _ExcelBookNew(0) ; Create an Excel Object 回复 2# chzj589
一样的,这个试过了。现在解决了。。
$oExcel.WorkBooks.Add ; Add a new workbook
把这行删了。每次都成功
页:
[1]