This is the Excel Range we want to import to dbf.
This is the structure of the dbf.
aStruct := { { "NAME", "C", 15, 0 }, ;
{ "DATE", "D", 8, 0 }, ;
{ "ADDRESS", "C", 15, 0 }, ;
{ "AMOUNT", "N", 12, 0 } }
Names of the dbf fields are different.
Also the order of the fields is different from the Excel sheet.
We want to import these columns from the Excel:
Excel column "ID" --> Ignore
Excel column "FIRST" --> dbf field "NAME"
Excel column "HIREDATE" --> dbf field "DATE"
Excel column "CITY" --> dbf field "ADDRESS"
Excel column "SALARY" --> dbf field "AMOUNT"
This is the way to use the function:
function ImportXLS()
local oRange, aStruct
local cXls := "c:\tests\import.xlsx"
local cDbf := "c:\tests\import.dbf"
aStruct := { { "NAME", "C", 15, 0 }, ;
{ "DATE", "D", 8, 0 }, ;
{ "ADDRESS", "C", 15, 0 }, ;
{ "AMOUNT", "N", 12, 0 } }
DBCREATE( cDBF, aStruct, "DBFCDX", .T., "DST" ) // Create and keep open
// or open an existing DBF
oRange := GetExcelRange( cXls, "Sheet1", "B1:E6" )
FW_ExcelToDBF( oRange, "NAME,ADDRESS,AMOUNT,DATE", .t. )
XBROWSER
return nil
Imported DBF:
If the dbf already exists, the records are appended to the existing data.