[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: using xlswrite csvwrite

From: Philip Nienhuis
Subject: Re: using xlswrite csvwrite
Date: Thu, 7 Apr 2011 11:44:16 -0700 (PDT)

forkandwait wrote:
> senator> writes:
>> I need to be able to write and read csv files and csv write and read do
>> work
>> great for me as long as I dont write any text to the file.   I would like
>> to
>> be able to find a way to put a field column on the top of my data in a
>> csv
>> file. It works great writing the data to a csv file, but i want to be
>> able
>> to write the field row on the top row in text. In matlab it works by
>> doing 
>> 2 seperate csv writes (one for data and one for text). I dont know if
>> that
>> would work however because octave seems to erase everything else in a
>> file
>> before it writes.
>> I dont know if xlswrite will let me write to a csv file, but if it does
>> getting xlswrite to work could solve my problem.
> I don't know if it is helpful, but I can't help but get a little "meta" on
> your
> particular problem:
> I would recommend avoiding excel and other binary / proprietary formats
> like the
> plague (which they are).  They generally poorly supported in the Free
> Software
> world, require lots of dependencies (Java, DDE, etc, etc, etc), and won't
> be
> portable outside of a Windows environment. 

Just to set the record straight:

xls format *is* supported outside Windows environment: gnumeric,, , can read & write xls files. Yep, even Octave can
read/write xls / xlsx files on any platform where Java runs. Ironically,
Matlab can't ...  
(... officially yet, that is, as I also have made (GPL-ed) ML versions of
Octave's spreadsheet scripts to help colleagues who run ML on their

You are right about dependencies. But they are not too bad: there's OpenJDK
(maybe not completely "free" I've heard) and there are several GPL-ed or
GPL-compatible options for xls I/O.

Beside, I have the impression (from this and earlier threads) that the OP
isn't quite interested in other platforms than Windows.

>    CSV files will ALWAYS be importable,

Not completely true.
Octave can neither import nor write csv files with mixed text and numerical
(For that matter, ML can't either.)

> human readable/ editable, and will require the bare minimum of
> infrastructure to
> use.  If you need to get fancy, look into CDF or HDF (which I don't know
> much
> about, or I would try to say something intelligent...)
> I suggest you use dlmwrite to output CSV files, or perhaps write a
> function that
> adds a header line using dlmwrite in conjunction with printf.  (csvwrite
> is a
> nonstandard wrapper to dlmwrite, as far as I understand.)  

The same limitation (heterogeneous text/numeric) goes for dlmread /

> Octave has enough built in I/O functions you should be able to do anything
> you want with a little
> bit of coding (which is good for you anyway ;) )  dlmwrite has lots of
> useful
> options, including an "append" flag for putting data after a header row,
> which
> you can learn about here:

That's one of the first things the OP wrote - exacly that is his wish. The
"append" flag may solve his problems.

dlmread has a similar option (starting row) which may help out.

But I get the impression that the OP imports csv files back into Excel.
That's why I still try to help him to get the spreadsheet I/O operational.

> If you just need to save files and communicate between octave scripts,
> simply
> use "save" and "load", which can be found on the same page.
> I would ONLY use xlswrite and friends if you MUST communicate with a
> (L)user who
> insists on opening only files that end in ".xls"; even then, some patient
> explaining about the virtues of simple, non-proprietary CSV formats can
> save you
> both 100s of wasted man-hours in the future.
> If your data is heterogeneous in its columns (some text, some number
> columns),
> that is another problem altogether -- if so, please let us know.

I had a go at writing a csvwrite() replacement for heterogeneous data; it
works (somewhat) but upon closer inspection I found there are several sneaky
gotchas involved. Maybe later I'll have time to make a more reliable
A csvread replacement might be even more tricky.

> My apologies if my rant/ tangent is too tangential or vague to be useful.

I doubt whether your "rant" will hit target ....  ;-)

But it is useful as it gives an opportunity to clarify on misperceptions
like "xls is poorly supported outside M$" etc.
Au contraire, it *is* widely supported. When I did my research before making
the Excel/OpenOffice scripts, I hit upon loads and loads of cross-platform
options, potential and/or immediately usable - unfortunately many were
proprietary/closed source or in some other way of limited use for Octave. If
there is so much available, you can bet that there is much demand and -as a
consequence- much support.


View this message in context:
Sent from the Octave - General mailing list archive at

reply via email to

[Prev in Thread] Current Thread [Next in Thread]