----------DBF 导入 ACCESS----------
delphi_media
方法一:用ACCESS中“文件”->“获取外部数据”->“导入”
方法二:用ACCESS中“文件”->“获取外部数据”->“导入”,然后文件类型选择ODBC Database(),即用数据源方式导入
*****注:以上两种方法不是完全凑效,有时提示“外部表不是预期的格式”。
方法三:用VFP连接ACCESS,然后用代码把DBF数据一条一条写入ACCESS。就像写入SQL一样
方法四:先把DBF转成EXCEL或TXT,然再用方法一进行导入。
注:DBF表如果不含用备注字段,直接用COPY TO 表名.XLS type xl5 转成EXCEL,如果含用备注型字段,必须用下面方法转成EXCEL:
****DbfToExcel.PRG****
CLOSE DATABASES ALL
SET DATE YMD
SET CENTURY ON
cDbfFile = GETFILE("dbf")
IF EMPTY(cDbfFile)
RETURN
ENDIF
USE (cDbfFile) ALIAS FoxTable IN 0
IF NOT USED("FoxTable")
=MESSAGEBOX("打开表失败,程序将中止!", 16, "Error")
RETURN
ENDIF
cExcelFile = PUTFILE("保存为(&N):",JUSTSTEM(cDbfFile)+".xls","xls")
IF EMPTY(cExcelFile)
CLOSE DATABASES ALL
RETURN
ENDIF
SELECT FoxTable
oExcelSheet = GETOBJECT("","Excel.Sheet") && 产生Excel对象
IF NOT TYPE("oExcelSheet") = "O"
=MESSAGEBOX("Excel对象创建失败,程序将中止!", 16, "Error")
RETURN
ENDIF
oExcelApp = oExcelSheet.APPLICATION
oExcelApp.Workbooks.ADD()
oExcelApp.ActiveWindow.WINDOWSTATE=2
oSheet = oExcelApp.ActiveSheet
nFldCount = AFIELDS(aFldList, "FoxTable")
FOR i = 1 TO nFldCount
oSheet.Cells(1,i).VALUE = aFldList[i, 1]
ENDFOR
cRecc = STR(RECCOUNT("FoxTable"))
SCAN
WAIT WINDOW ALLTRIM(STR(RECNO())) + "/" + cRecc NOWAIT
FOR i = 1 TO nFldCount
vValue = .NULL.
IF AT(aFldList[i, 2], "CDLMNFIBYT") = 0
LOOP
ENDIF
cFldName = aFldList[i, 1]
vValue = EVALUATE(cFldName)
DO CASE
CASE aFldList[i, 2] = "C" && 字符/字符串
vValue = TRIM(vValue)
CASE aFldList[i, 2] = "D" && 日期
vValue = DTOC(vValue)
CASE aFldList[i, 2] = "T" && 日期时间
vValue = TTOC(vValue)
CASE INLIST(aFldList[i, 2], "N", "F", "I", "B", "Y") && 数值
CASE aFldList[i, 2] = "L" && 逻辑
CASE aFldList[i, 2] = "M" && 备注型
OTHERWISE
vValue = .NULL.
ENDCASE
IF VARTYPE(vValue) = "C" AND EMPTY(vValue)
LOOP
ENDIF
IF NOT ISNULL(vValue)
oSheet.Cells(RECNO("FoxTable")+1, i).VALUE = vValue
ENDIF
ENDFOR
ENDSCAN
cChrStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
FOR i = 1 TO nFldCount
cColumn = SUBSTR(cChrStr, INT((i-1)/26), 1) + SUBSTR(cChrStr, IIF(MOD(i, 26)= 0, 26, MOD(i, 26)) , 1)
oSheet.COLUMNS(cColumn + ":" + cColumn).COLUMNWIDTH = 12
IF aFldList[i, 2] = "M"
oSheet.COLUMNS(cColumn + ":" + cColumn).WrapText = .F.
ENDIF
ENDFOR
oExcelApp.ActiveWorkbook.SAVEAS(cExcelFile)
oExcelApp.ActiveWorkbook.CLOSE(.F.)
oExcelApp.ActiveWorkbook.CLOSE(.F.)
oExcelApp.QUIT
oExcelSheet = .NULL.
oExcelApp = .NULL.
WAIT CLEAR
=MESSAGEBOX("转换完毕!", 64, "OK")
delphi appCLOSE DATABASES ALL
----------ACCESS 导出 DBF----------
打开ACCESS库后,右单击要导出的表,
选择“导出”,出现对话诓后,把“保存类型”选为“*.dbf”,
(注意“文件名”不要超过8位,超过8位后系统会自动截取前8位)
然后点击“保存即可”。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论