Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dates in excel 2010
Message
De
30/11/2012 18:07:09
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2003
Database:
MS SQL Server
Divers
Thread ID:
01558464
Message ID:
01558510
Vues:
45
>>>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
*-- dn 2012/11/26
		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.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform