4.0

4.0 | 2 ratings Rate this file 101 downloads (last 30 days) File Size: 11.19 KB File ID: #16229

writeexcel

by Peder Axensten

 

04 Sep 2007 (Updated 08 Oct 2007)

Code covered by BSD License  

Writes data to an Excel xml file on any system (NO Excel or ActiveX required!).

Download Now | Watch this File

File Information
Description

Usage: writeexcel(file, varlist)
 
Writes data to an Excel xml file on any system (NO Excel or ActiveX required!).
 
Scalars will end up on a sheet called "Scalars" as name (in the first column) and value (in the second column) pairs. Arrays and cell arrays are saved on individual sheets, named by the variable name.
 
If you find any errors, please let me know at peder at axensten dot se. This is still pretty much work in progress, see 'to do', below.
 
ARGUMENTS:
file File name path. If prefixed with a '>' (see example, below), the data will be added to an existing file (that was generated by this macro!).
varlist List of variables, expressions, and/or strings. Variables and expressions will be written to the file, expressions must be preceded by a '\name', below. A special case is if a variable of type structure is called DocumentProperties, its field names and values will set the document properties (see the example). Strings can be of the following: - '\name' sets the name of the next variable or expression, names must be unique.
 
EXAMPLE:
DocumentProperties= struct('Title','My Title','Author','Me','Subject','very interesting');
astring= 'Hi ya!';
ascalar= pi;
anarray= [1 2 3; 4 5 6];
acellarr= {'abc', 'def'; pi, NaN; -Inf Inf};
writeexcel('Workbook.xml', anarray, ascalar, astring, acellarr, DocumentProperties);
writeexcel('>Workbook.xml', '\another scalar', 2*pi/5);
 
HISTORY:
Version 1.0, first working version, 2007-09-04.
Version 1.1, released 2007-09-06:
- Fixed a bug when saving vectors.
- Fixed a bug when adding scalars when there previously were none.
- Now UTF-8 works.
- Added check for possible fopen problems.
- Added better input argument check.
- Can now add document metadata through structure named DocumentProperties.
- Writing structures too, columns named by fieldnames (the struct class).
- Writing symbolic expressions too (the sym class).
Version 1.2, released 2007-09-18:
- Fixed mlint warnings.
- Fixed problem with certain characters in meta data.
- Removed all regexprep calls for better compatibility.
- Removed automatic .xls suffix.
 
TO DO:
- '%format' or {'%form1', '%form2', etc.} to control how columns will be shown (numbers will be stored with 'all' decimals, but the column formats will be set)
 
COPYRIGHT: (c) 2007 Peder Axensten. Use at own risk.
 
KEYWORDS: save, export, write, Microsoft, Excel, xml
 
REQS: Does NOT require Excel, Active X, or a Windows system!
 
REFERENCE: http://msdn2.microsoft.com/en-us/library/aa140066(office.10).aspx

MATLAB release MATLAB 7.4 (R2007a)
Other requirements Does NOT require Excel, Active X, or a Windows system! Should work on older Matlab versions too.
Zip File Content  
Other Files license.txt,
writeexcel.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
11 Sep 2007 govind rajan

It is nice but there is an Improvement in this will full fill the all the need that we need thank u buddy

16 Sep 2007 Peder Axensten

I don't much understand govind rajan's review, but I welcome all suggestions on improvement.

19 Sep 2007 Albercht Beewahn

Perfect! Simple and quick. No Windows dependencies! Cheers!

19 Sep 2007 Albercht Beewahn

Forgot rating!

Please login to add a comment or rating.
Updates
05 Sep 2007

- Saving vectors and adding scalars now works better.
- UTF-8 works.
- Check for fopen problems.
- Better argument check.
- Document metadata through structure DocumentProperties.
- Structures supported.
- Symbolic expressions.

08 Oct 2007

- Fixed mlint warnings.
- Fixed problem with certain characters in meta data.
- Removed all regexprep calls for better compatibility.
- Removed automatic .xls suffix.

Tag Activity for this File
Tag Applied By Date/Time
data import Peder Axensten 22 Oct 2008 09:25:42
data export Peder Axensten 22 Oct 2008 09:25:42
export Peder Axensten 22 Oct 2008 09:25:42
write Peder Axensten 22 Oct 2008 09:25:42
microsoft Peder Axensten 22 Oct 2008 09:25:42
excel Peder Axensten 22 Oct 2008 09:25:42
xml Peder Axensten 22 Oct 2008 09:25:42
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com