本帖最后由 bnuzjm 于 2013-8-7 20:39 编辑
把excel.au3修改了下,加上dbf类型判断。测试了下,xp系统,只支持dbf4类型,dbf2和dbf3都不支持。
win7系统,三个都不支持,所以这个方案还是有挺多问题的_export("d:","文件名1","xls")
_export("d:","文件名2","dbf")
Func _export($targetPath,$fileName,$fileType)
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path)
$sQuery="select * from datahsd"
$RS =ObjCreate("ADODB.Recordset")
$RS.ActiveConnection =$addfld
$RS.open($sQuery)
Local $intCount = $RS.Fields.Count
$oExcel = _ExcelBookNew(0) ; 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
_ExcelBookSaveAs($oExcel, $targetPath&$fileName&"."&$fileType, $fileType, 0, 1)
If $fileType="xls" Then
_ExcelBookClose($oExcel)
$oExcel=0
Else
ProcessClose("excel.exe")
EndIf
EndFunc
|