Code covered by the BSD License  

Highlights from
Read and Write Open Document Format (ODF) Spreadsheet (.ods)

4.66667

4.7 | 3 ratings Rate this file 26 Downloads (last 30 days) File Size: 4.94 KB File ID: #28411

Read and Write Open Document Format (ODF) Spreadsheet (.ods)

by Paul

 

07 Aug 2010 (Updated 12 Jun 2012)

Wrappers for the matlab xlsread / xlswrite commands that read ODF Spreadsheet files (.ods).

| Watch this File

File Information
Description

On a pc the wrapper will simply call xlsread / xlswrite, but on a mac or unix platform will read an Open Document Format (ODF) spreadsheet, for example as saved by Open Office.

The wrapper uses java commands from the ODFDOM project which provides java libraries for reading Open Document Format files. The library is not provided here, to download see:

http://incubator.apache.org/odftoolkit/

Once the odfdom.jar file is download it must be added to the javaclasspath (see Matlab documentation on importing java libraries).

This wrapper was developed and tested only on a Mac platform (OSX 10.6.4) with Matlab 2010b using ODFDOM version 0.8.6 (only slight testing with 0.8.7), but should work on other platforms. It could be easily modified to read .ods on a pc or accept variable number of input arguments as xlsread does (currently all xlsread inputs must be specified).

Required Products MATLAB
MATLAB release MATLAB 7.11 (R2010b)
Tags for This File  
Everyone's Tags
mac, ods(2), open document format, open office, xlsread, xlswrite
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
11 Jun 2012 Paul

Thanks Beat. Turns out both row_col_to_cellID and cellID_to_row_col in myxlswrite were not correct. I fixed and verified them more thoroughly (update just submitted). Also updated the link to ODFDOM in Description.

09 Jun 2012 Beat Birkhofer

Great idea. I guess the URL for the jar changed to

http://incubator.apache.org/odftoolkit/

To make it work with the rng start cell given and a number of columns > 26 I had to change row_col_to_cellID() to calculate the column name via num2abc() (see file exchange submission). The original code results e.g. in BH instead of AH.

15 May 2012 Paul

Typo in last comment... I have NOT tested extensively on pc, but simply verified that it basically works.

15 May 2012 Paul

Hi Claire,
hmmm, it should work on PC with the ispc commented as you did. Are you sure that you edited classpath.txt (the one that Matlab is using, you can tell with 'which classpath.txt') and added the odfdom.jar location to that file? See my comment on 13 Aug 2010. If not, can you step through and figure out which try block specifically the error is coming from and then maybe I can help? I have tested extensively on PC, but I have verified that it basically works.

Also, I'm updating the package again with a couple more bug fixes since this most recent update, so try the new files also (after they post).

15 May 2012 claire lauvernet

Hi Paul, in fact I work on a pc BUT with openoffice documents. I commented the option ispc but the error is now
'Can not read HyetoHydro_v5.ods MATLAB:undefinedVarOrClass'

Does it mean that this great tool is not usable on a windows PC to work with openoffice documents?

thanks!

Claire

19 Apr 2011 Felix

Thx a lot,
you've made work much easier for me!

06 Nov 2010 Alex Bockman

This tool is indispensible, keep up the good work!
I notice one difference between the unix and pc implementations:
On a pc, when a spreadsheet uses the first row for column names, the num output starts with row two. The unix version inserts a row of NaNs. This requires wrapping the wrapper in conditionals for dual platform implementations. Just thought I'd plug for a minor fix. Again, thanks!

13 Sep 2010 Guillaume Majeau-Bettez

Hey Paul, this is GREAT! Always reading csv files was getting old. Do you think that without too much work we could reverse this and have an odswrite? I'd be happy to help.

13 Aug 2010 Paul

Hmm, I can't reproduce this error. You'll need to define the other arguments also, but your error is before this. You can change the error line in the m file to:

error(['Can not read ' infile ' ' ME.identifier]);

and see what the error is. I'm guessing that you don't have the javaclasspath set correctly. If this is the case, the error will say something like 'MATLAB:undefinedVarOrClass' To fix this:

edit classpath.txt

and add the full directory and name of the odfdom.jar file to the bottom of this file, for example:

/Users/name/Documents/MATLAB/lib/odfdom.jar

10 Aug 2010 Jacques Vernin

Thanks, it's geat. But ...!
I put on my directory a file test.ods with OpenOffice
When I want to read it:
>> NUMERIC=myxlsread('test')
??? Error using ==> myxlsread at 39
Can not read test.ods

Whereis the mistake?

Thanks

Updates
15 May 2012

The package has finally been updated with myxlswrite for writing .ods files. Also myxlsread now defaults to the same behavior as xlsread which ignores column and row headers in the numeric output (bug pointed out by Alex in comments, thanks).

15 May 2012

Fixed a bug introduced to xlsread with header option, added document close calls to end of xlsread and xlswrite, this most likely was the source of a "memory leak" problem for read.

12 Jun 2012

Fixed bugs in myxlswrite with row_col_to_cellID and cellID_to_row_col internal functions that map integer row and column numbers to spreadsheet row and column string identifiers.

Contact us