M_File='test.xlsx'
IF FILE(M_File)
myexcel=createobject('excel.application')
myexcel.visible=.f.
bookexcel=myexcel.workbooks.open(M_File)
o_SheetName=myexcel.application.ActiveSheet.Name
UsedRange =bookexcel.worksheets(o_SheetName).UsedRange
o_rows=UsedRange.rows.count
o_cols=UsedRange.columns.count
cFields="("+ALLTRIM(myexcel.cells(1,1).value)+" C(100)"
&&假设各列均为字符型,具体根据实际而定;也可先定义DBF结构。记得也有自动判断的,不过代码一时找不到了
FOR i=2 TO o_cols
cFields=cFields+","+ALLTRIM(myexcel.cells(1,i).value)+" C(100)"
ENDFOR
cFields=cFields+")"
SELECT 0
CREATE TABLE test &cFields
FOR i=2 TO o_rows
APPEND BLANK
FOR j=1 TO o_cols
cField=FIELD(j)
REPLACE &cField WITH myexcel.cells(i,j).value
ENDFOR
ENDFOR
myexcel.workbooks.close
myexcel.quit
BROWSE
ELSE
=MESSAGEBOX("指定文件不存在!",0+16,"提示")
ENDIF