exporting table data to a CSV file [message #36465] |
Wed, 17 September 2003 06:18 |
timothy.williams
Messages: 20 Registered: October 2001
|
Junior Member |
|
|
Hi.
I want to output the contents of a table to a CSV file for import to
Excel, or perhaps something else. I don't know in advance the data
type of the cells, so I can't use the FORMAT= keyword. I've coded up
something, but I know FOR loops are "bad" and was wondering if there
is a better way.
Here's what I have (coding from memory here)
widget_control, table, get_value=values
labels=tag_names(values)
;write header
printf, lun, strjoin(labels, ', ')
outarr=strarr(n_tags(values))
;write out each row
for i=0, n_elements(values)-1 do begin
for j=0, n_tags(values)-1 do outarr[j]=values[i].(j)
printf, lun, strjoin(outarr, ', ')
endfor
Is there a better way to do this?
I also saw David Fannings code about writing CSV files, and learned
about the WIDTH keyword to OPEN. What's a good way to get the max
width of the table so my output won't get truncated?
Thanks.
|
|
|