Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CSV with double quotes
Message
De
07/03/2017 13:23:26
 
 
À
07/03/2017 08:14:26
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01648804
Message ID:
01648835
Vues:
45
More polished than my 1liner for sure ;-) Quick nosy question - did you compare your approach of writing out to file and concatenating header line with that file to _clip to inserting header line and then inserting one row down directly fro .DataToClip(,,3)? On current SSD probably irrelevant, but it perked my "find best way" character deficit ;-)

Quickscanned vfp2Excel, but have not done enough with .RS to form opinion. Most of the time our data is costly enough to be saved in import format as well in case of problems/questions months later best in a pure ASCII format, so no troubles from different excel versions come into play. Most of the time delimited with character ";" is good enough, although the same problems with special characters in text fields apply.

"Best" way IMO is output via Copy to type sdf accompanied by an easy to parse field description from copy structure extended piped to file.
Char fields need to be handled with a additional effort like with .RS for embedded CR and/or LF, but as there are no field delimiter chars no further problems besides defining a length for memo fields.

Reading that fixed length file best done by some vba script reading the field definitions - Dunno if there is also a way to save things set in import wizard, but we are programmers ;-)

The only thing missing then is a documented way to handle null if found in the data ;-)

While having two programs in use or at least to import ASCII is a downside, the easy to check intermediate step/text file was often very helpful in pointing to the exact point in production when data "enriched" by many cooks was made erroneous: some step either eliminated rows or added/joined false data. As soon as more than insignificant figures are paid for data, finger pointing in case of error is nearly unavoidable...

So sometimes we code VBA import if cost of data and # of steps/cooks in the process is both high ;-)


>>never tried for sizes past int2, but you could do a quick test if _vfp.datatoclip(,,3) plus insert/ctrl-v in excel works with your data - perhaps you need to check for tabs in your data first. Automating the insert if ok should be a piece of cake ;-)
>>
>>
>
>Yes, that is also one of the fastest way to transport data to excel. I wouldn't suggest using datatoclip for that (it creates extra column for example) and here is a sample instead that I published long ago:
>
>
>clear
>Clear All
>* Create a test cursor
>Create Cursor testcursor (Rcno i,cType c(10), nType i, dType d)
>Rand(-1)
>For ix = 1 To 200000 && Create 200000 recs cursor
>	Insert Into testcursor Values ;
>		(Recco()+1,Sys(2015), Int(Rand()*1000), Date()-Int(Rand()*100))
>Endfor
>lcHeader = Chrtran('Rcno,cType,nType,dType',',',Chr(9))+Chr(13)+Chr(10)
>
>#Define xlDelimited  1
>Set Sysformats On
>Set Safety Off
>
>lnTotal = Reccount()
>locate
>Wait Window Nowait "Pls wait sending data to Excel..."
>Start = Seconds()
>oExcel = Createobject("Excel.application")
>With oExcel
>	.workbooks.Add && Add a new workbook
>	lnMaxRows = .ActiveWorkBook.ActiveSheet.Rows.Count && Get max row count
>	lnNeededSheets = Ceiling( lnTotal / (lnMaxRows - 1) ) && 1 row header
>	? "Total Pages : "+Padr(lnNeededSheets,3," ")
>	.Visible = .T.
>	With .ActiveWorkBook
>		lnCurrentSheetCount = .sheets.Count
>		If lnNeededSheets > lnCurrentSheetCount
>			.sheets.Add(,.sheets(lnCurrentSheetCount),;
>				lnNeededSheets - lnCurrentSheetCount) && Add new sheets after old ones
>		Endif
>		For ix = 1 To m.lnNeededSheets
>			With .sheets.Item(ix)
>				.Name = "Page "+Padl(ix,3,"0")
>				.Activate
>				lcTempFile = Sys(2015)+".txt"
>				Copy Next m.lnMaxRows-1 To (m.lcTempFile) Delimited With Tab 
>				_Cliptext = m.lcHeader + Filetostr(m.lcTempFile)
>				Erase (lcTempFile)
>				.Range("A1").PasteSpecial()
>				IF !EOF()
>					SKIP
>				endif
>				? "Page no : "+;
>					padl(m.ix,3)+;
>					"/"+;
>					padr(m.lnNeededSheets,3)+ ;
>					"   Elapsed : ",Seconds() - Start
>			Endwith
>		Endfor
>		.sheets.Item(1).Activate
>	Endwith
>Endwith
>? "Total Elapsed : ",Seconds() - Start
>
>
>I would however suggest using VFP2Excel function.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform