comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » exporting table data to a CSV file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
exporting table data to a CSV file [message #36465] Wed, 17 September 2003 06:18
timothy.williams is currently offline  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.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL 6.0 for Win 9x?
Next Topic: Co-Linear Contour Points

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 18:41:33 PDT 2025

Total time taken to generate the page: 0.00460 seconds