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

Home » Public Forums » archive » Re: exporting table data to a CSV file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: exporting table data to a CSV file [message #36462 is a reply to message #36445] Wed, 17 September 2003 06:49 Go to previous messageGo to previous message
K. Bowman is currently offline  K. Bowman
Messages: 330
Registered: May 2000
Senior Member
In article <faf44c99.0309170518.45b76bff@posting.google.com>,
timothy.williams@nvl.army.mil (Tim Williams) wrote:

> 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.

It is probably easier to simply write the output file using free-form
output. When you want to import into Excel, use the Excel
Text-to-columns tool to split the input lines into columns. You can
select, 'Space' as a delimiter when splitting the columns.

If you have strings in your output, it can cause problems. If the
strings do not contain internal blanks, pad them with blanks at the
beginning and end of each string. If they do have internal blanks, try
adding quotes (") at the beginning and end.

Ken Bowman
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: What does an optimal scientific programming language/environmentneed?
Next Topic: Re: lens distortion

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

Current Time: Fri Oct 10 14:18:46 PDT 2025

Total time taken to generate the page: 0.63353 seconds