Genexus has the ExcelDocument data type that allows you to read data in a tabular way from an excel file, specifying rows and columns. Is there a way to do the same with a csv file? I can open it and read it like a normal txt, but a structure would be more effective
Asked
Active
Viewed 338 times
2 Answers
2
As ealmeida explained you can use the Delimited ASCII files functions.
Below you can see an example on how to code both read and write operations.
ASCII File sample
1,"Jane Doe",1955-05-21
2,"John Smith",1991-10-15
3,"William Shakespeare",2005-11-30
Setup variables with parameters
&FullFileName = !'Datos.txt'
&RecordLength = 50
&FieldsDelimiter = !','
&StringDelimiter = !'"'
&DateFormat = !'ymd'
&DateSeparator = !'-'
To read Delimited ASCII
&ErrorNbr = DFROpen(&FullFileName, &RecordLength, &FieldsDelimiter, &StringDelimiter)
do while DFRNext() = 0
&ErrorNbr = DFRGNum(&PersonNumber)
&ErrorNbr = DFRGTxt(&PersonName)
&ErrorNbr = DFRGDate(&PersonDOB, &DateFormat, &DateSeparator)
enddo
&ErrorNbr = DFRClose()
To write Delimited ASCII
&ErrorNbr = DFROpen(&FullFileName, &RecordLength, &FieldsDelimiter, &StringDelimiter)
for each Person
&ErrorNbr = DFWPNum(PersonNumber, 0)
&ErrorNbr = DFWPTxt(PersonName)
&ErrorNbr = DFWPDate(PersonDOB, &DateFormat, &DateSeparator)
&ErrorNbr = DFWNext()
endfor
&ErrorNbr = DFWClose()

Pablo
- 51
- 2
1
Yes, it's posible, using Delimited ASCII files functions

ealmeida
- 444
- 3
- 11
-
1Do you have an example of use? I am trying to implement it but it is as if at each "next" it only reads the first column – Nicola May 02 '22 at 06:43
-
Some simple (and old) examples, how to read an write using this functions. http://library.gxtechnical.com/gxdl/pub/GeneXus/Java/Docum/Manuals/7.0/Java70En14.htm – ealmeida May 02 '22 at 14:41