0
csv export problem.
'Ver Archivo CSV' := null;
let xMd := 'Busqueda por Mes';
let registros := select 'Datos Transferidos' where month(Date) = xMd;
let csvContent := "Cliente,Date,Transferido Dato 1,Transferido Dato 2,Number\n";
for r in registros do
csvContent := csvContent +
text(r.Cliente) + "," +
date(r.Date) + "," +
text(r.'Transferido Dato 1') + "," +
text(r.'Transferido Dato 2') + "," +
number(r.Number) + "\n";
end;
'Ver Archivo CSV' := file(csvContent, "Archivo CSV.csv")
Problem on line 13 (last line)
3 replies
-
'Ver Archivo csv' := null; let xMd := 'Busqueda por Mes'; let registros := (select 'Datos Transferidos' where month(Date) = xMd); let csvContent := "Cliente,Date,Transferido Dato 1,Transferido Dato 2,Monto\n"; for r in registros do csvContent := csvContent + text(r.Cliente) + "," + text(r.Date) + "," + text(r.'Transferido Dato 1') + "," + text(r.'Transferido Dato 2') + "," + text(number(r.Monto)) + "\n" end; 'Ver Archivo csv' := createTextFile(this, csvContent, "Archivo CSV.csv")
Now work, but the output is incorrect, some idea.
It seems to be related to concatenation and the use of line breaks.
-
One thing I see is that you are repeating the header row in each record when you need it only at the top. Try something like:
let csvHeader := "Name,Qnty"; let dataArray := for a in select Article do a.ArticleName + "," + a.Avail end; let csvBody := join(dataArray, " "); let finalCSV := csvHeader + " " + csvBody; createTextFile(this, finalCSV, "test.csv")
Line 1, is my header row for the final csv.
Lines 2 - 4, is where I create the body for the csv. But this returns an array of data.
Lines 5 & 6, is where I change the array in dataArray into a string using join() and setting a carriage return as the divider.
Lines 7 - 9, is where we combine the header and the text body into a new variable.
So I end up with:
Content aside
- Status Answered
- 5 days agoLast active
- 3Replies
- 38Views
-
2
Following