File Exchange

image thumbnail

The X Collection

version 1.5.0.0 (122 KB) by Yvan Lengwiler
Collection of programs that ease interaction with Excel files.

12 Downloads

Updated 21 Jan 2015

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

The X collection is a set of Matlab programs that make it easier for the user to interact with Excel sheets. Matlab offers already many ways of exchanging data with Excel. For instance 'xlsread' and 'xlswrite' allow the programmer to read data from and write data into Excel worksheets. But these programs are inefficient when a large number of read and write operations have to be repeated because they build a connection to the Excel COM server and then release this connection again with every operation.

The X collection splits that up. The programmer creates a connection to Excel (with XConnect), then does whatever he or she has to do (XWrite, XRead, XOpenBook, XGetSheet, XSaveBook etc), and then releases the Excel connection again (XDisconnect). Depending on the type of work, the gain in speed range from none at all to orders of magnitude.
The following programs are included: XConnect, XDisconnect, XListOpenBooks, XGetBook, XNewBook, XOpenBook, XFetch, XSaveBook, XSaveAllBooks, XCloseBook, XCloseAllBooks, XListSheets, XGetSheet, XAddSheet, XRead, XWrite, XWriteDates, XDateFmt, XRangeAddress.

Their meanings should be more or less obvious. They all come with help, so that you user should be able to figure out how to use these programs fairly easily. There is also a short documentation (PDF file) as well as an example script (examples.m) that demonstrates many of these programs.

Should you need help with this, please contact me. If you find this contribution useful, please comment below.

Comments and Ratings (12)

Martin Wolf

lifuli,

You must be using an older version of the toolbox. If you download the most recent version and reinstall it, it should work.

Cheers, Yvan

lifuli

Its a great tool!
But when i use it to read value of only one cell,such like ‘A1’,it does not work!such as below:
XRead(hSheet,XRangeAddress([1,1],[1,1]));
Error using cellfun
cellfun works only on cells.

Error in XRead (line 97)
isText = cellfun('isclass',xlsRaw,'char');

Frank Chen

This is amazing!
It should be included in Matlab.

Rolf

ok, now I see. The problem arises if the decimal separator inside Excel is set to comma instead of point. Thanks for this excellent submission!

Rolf

very useful and working very well for me under Matlab. However, when compiled to a Matlab standalone the same code is, on some machines (win 7 pro, 64-bit), producing the expected entry values in the generated Excel file. On others the values are by a factor of 1000 too low.
Any ideas what could cause this issue or how to solve it? Thanks, Rolf

Rolf

Charles

Excellent submission, kept up to date with latest MatLab. Much faster than xlsread because it can leave COM connection open, as well as leaving workbook open between calls to different sheets. Easy to use following examples. Note: Example (demo) has one feature that requires financial toolbox. Thanks Yvan!

peter

Alex

Updates

1.5.0.0

Access to online worksheets was possible with XOpenBook already, but XFetch provides even easier access to files on Yahoo Finance, Google Finance, FRED Database of the FRB St.Louis, and Penn World Table 8.0.

1.4.0.0

XOpenBook now handles Excel files that are online and opens them directly

1.3.0.0

XWrite now also handles tables.

1.2.0.0

New support for exporting Matlab figures into Excel worksheets (with XWrite)
Ranges can now be in coordinate form (i.e. [3,2]) or in 'A1'-style (i.e. 'B3')

1.1.0.0

improved error messages in functions,
corrected typos in description in FEX

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux