>>>PMFJI. I am always looking at how people extract data from excel to VFP. And I am trying to understand your code but it goes over my head. Hopefully, if it is not too much trouble, I can ask you. How do you get the value of 'tn" that you pass to this function? And one more; what is the 'this.oexcel' you use in this function? TIA.
>>
>>Tn is the row with the header, usually 1 but I've seen multiline headers, so I've put it as parameter just in case.
>>
>>"This" is, in my case, a wrapper class that has all the code I'd need that's common to various import scenarios; this.oExcel is an instance of excel that it creates.
>
>Thank you. Do I understand correctly that your code (the segment of which is shown above) connects to an Excel and then copies data from the Excel spreadsheet into some other format (e.g. cursor)?
Yes... basically, there's a method that returns an equivalent of the scatter object, like this:
PROCEDURE RowToObj(tn)
LOCAL loRow, o, i, lcProp, luValue
loRow=THIS.oexcel.ROWS(tn)
o=CREATEOBJECT("empty")
FOR i=1 TO ALEN(THIS.aFld)
lcProp=LOWER(THIS.aFld[i])
llIsValue=lcProp $ THIS.cValueFieldsList
IF llIsvalue and isdigit(loRow.cells(i).TEXT)
luValue=loRow.cells(i).VALUE
ELSE
luValue=loRow.cells(i).TEXT
ENDIF
ADDPROPERTY(o, lcProp, luValue)
ENDFOR
RETURN o
So you pass it a row number and you get an object which has one property per column, assuming that cells in the header are proper property names. I have an alternate method that does the same thing for a row in a csv file, using aliines() on a row string, so the method to populate my cursor looks the same and works the same way, and I don't care if between runs the locations of columns change - as long as their names are consistent.