<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Excel &#8211; Undocumented Matlab</title>
	<atom:link href="https://undocumentedmatlab.com/articles/tag/excel/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Thu, 02 Aug 2012 09:44:35 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>xlswrite for Mac, Linux</title>
		<link>https://undocumentedmatlab.com/articles/xlswrite-for-mac-linux?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=xlswrite-for-mac-linux</link>
					<comments>https://undocumentedmatlab.com/articles/xlswrite-for-mac-linux#comments</comments>
		
		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 02 Aug 2012 09:44:35 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Low risk of breaking in future versions]]></category>
		<category><![CDATA[ActiveX]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[File Exchange]]></category>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=3041</guid>

					<description><![CDATA[<p>Several Matlab utilities enable reading/writing spreadsheet data (including XLS files) in Macs, Linux. </p>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/xlswrite-for-mac-linux">xlswrite for Mac, Linux</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/jfreechart-graphs-and-gauges" rel="bookmark" title="JFreeChart graphs and gauges">JFreeChart graphs and gauges </a> <small>JFreeChart is an open-source charting library that can easily be integrated in Matlab...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/fixing-matlabs-actxserver" rel="bookmark" title="Fixing Matlab&#039;s actxserver">Fixing Matlab&#039;s actxserver </a> <small>Matlab's COM (ActiveX) server behavior can be fixed in a couple of useful manners. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jboost-integrating-an-external-java-library-in-matlab" rel="bookmark" title="JBoost &#8211; Integrating an external Java library in Matlab">JBoost &#8211; Integrating an external Java library in Matlab </a> <small>This article shows how an external Java library can be integrated in Matlab...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-line-position-in-edit-box-uicontrol" rel="bookmark" title="Setting line position in an edit-box uicontrol">Setting line position in an edit-box uicontrol </a> <small>Matlab uicontrols have many useful features that are only available via Java. Here's how to access them....</small></li>
</ol>
</div>
]]></description>
										<content:encoded><![CDATA[<p>Numerous Matlab users have <a target="_blank" rel="nofollow" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/152206">expressed frustration</a> over the years at the fact that the <i><b>xlswrite</b></i> function, used for saving/updating Excel files, is only supported on the Windows platform. Matlab uses Excel COM to implement <i><b>xlswrite</b></i> functionality, and since COM is a Windows-specific technology, <i><b>xlswrite</b></i> does not work on non-Windows platforms.<br />
In such cases, Matlab users normally save the data into a CSV (comma-separated values) file, using the built-in <i><b>csvwrite</b></i> or <i><b>dlmwrite</b></i> functions, or File-Exchange utilities such as <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/19149-any2csv">Any2CSV</a>. This enables saving the data, but does not enable saving formatting information or graphic objects (e.g., plots or images). As a side note, <i><b>xlswrite</b></i> also does not allow saving formatting information or graphic objects, but at least on Windows we can use direct COM to add them (or use my <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/15192-officedoc">OfficeDoc</a> utility).</p>
<h3 id="Java">Java solutions for spreadsheet access</h3>
<p>Luckily, the community of Java developers, which is an order of magnitude larger than the Matlab community, has developed several utilities that we can easily use in Matlab to implement <i><b>xlswrite</b></i>&#8216;s functionality on Macs, Linux, and wherever else Matlab may run &#8211; even Windows, if we really wish. Most articles on this website that deal with Java focus on its GUI aspects, i.e., how to use Java to improve Matlab&#8217;s plain-vanilla appearance/behavior. But Java is in fact a very broad programming platform that has an enormous repository of non-GUI solutions: networking, database support, data structures, computational algorithms, etc. etc. &#8211; and a huge number of them are open-source. Unlike Java&#8217;s GUI goodies, these Java packages, being non-GUI in nature, are fully supported by Matlab.<br />
The Excel spreadsheets support, and Office support in general, is just another example of the wide range of non-GUI packages available in Java. In fact there are full-fledged Office lookalikes written in Java (most notably the open-source <a target="_blank" rel="nofollow" href="http://www.openoffice.org">OpenOffice</a>). We can either use these applications directly, or interact with them from Matlab (via Java), just as we can interact with Excel on Windows.<br />
There are several Java packages that enable reading and writing spreadsheet data, without the full-blown Office support. One such open source project is the <a target="_blank" rel="nofollow" href="http://incubator.apache.org/odftoolkit/">ODF (Open Document Foundation) Toolkit</a>, which has plenty of online resources. In 2010 a Matlab user contributed a <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/28411">utility</a> to use the ODF Java package for reading and writing ODF-format spreadsheets (*.ods). Other users have also <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/18222-load-open-document-spreadsheets">provided</a> ODF utilities for Matlab.<br />
Using ODF is excellent and cross-platform, but does not solve the Excel problem directly, because the ODF format is incompatible with the XLS format. We can use another open-source Java package, <a target="_blank" rel="nofollow" href="http://jexcelapi.sourceforge.net/">JExcelApi</a>, for this. JExcelApi is relatively easy to use and has several online tutorials (<a target="_blank" rel="nofollow" href="http://www.vogella.com/articles/JavaExcel/article.html">example1</a>, <a target="_blank" rel="nofollow" href="http://www.andykhan.com/jexcelapi/tutorial.html">example2</a>), although it is not as widely used as ODF.<br />
Another open-source Java package that can be used to directly read and write XLS files is <a target="_blank" rel="nofollow" href="http://poi.apache.org/">Apache POI</a>. An informal comparison of POI and JExcelApi can be found <a target="_blank" rel="nofollow" href="http://stackoverflow.com/questions/4752456/memory-efficient-java-library-to-read-excel-files">here</a>.</p>
<h3 id="xlwrite"><i><b>xlwrite</b></i></h3>
<p>Very recently, <a target="_blank" rel="nofollow" href="http://aaaic.com/Our_People.html">Marin Deresco</a> has posted a Matlab utility called <a target="_blank" rel="nofollow" href="http://www.mathworks.com/matlabcentral/fileexchange/37560-xlwrite"><i><b>xlwrite</b></i></a> that uses JExcelApi for implementing an <i><b>xlswrite</b></i> variant that can be used on all Matlab platforms.<br />
<span id="more-3041"></span><br />
After downloading <i><b>xlwrite</b></i>, we need to add its two contained JAR files (<i>jxl.jar, MXL.jar</i>) to the Java classpath:</p>
<pre lang='matlab'>
javaaddpath('C:/Yair/Utils/JExcelAPI/jxl.jar')
javaaddpath('C:/Yair/Utils/JExcelAPI/MXL.jar')
</pre>
<p>We can now use <i><b>xlwrite</b></i> to store data in a real *.xls file:</p>
<pre lang='matlab'>xlwrite('my_data.xls', magic(3))</pre>
<p><i><b>xlwrite</b></i> has similar syntax and inputs to Matlab&#8217;s <i><b>xlswrite</b></i>. It can also write 3-d arrays (which <i><b>xlswrite</b></i> cannot), of cell and double type (the third dimension is simply stored in separate worksheets).<br />
Note: Matlab&#8217;s decimal separator is &#8216;.&#8217; &#8211; in order to be able to work with exported data on Macs, Mac users may need to change Mac decimal separator preferences. To do so you need to go to System Preferences &gt; International &gt; Formats and click on Customize button in the number zone, then type &#8216;.&#8217; in the required field.<br />
<i><b>xlwrite</b></i> is a real working solution. However, it may need further refinements, that will hopefully be added in future updates to this utility:</p>
<ul>
<li>automatically add the <i><b>javaaddpath</b></i> commands to <i><b>xlwrite</b></i> so that users won&#8217;t need to do them</li>
<li>manage Java heap space, as Java heap memory saturates for large arrays exported many times (possible memory leak)</li>
<li>format dates and strings, as all numbers appear as text in Excel</li>
<li>optimize performance (the culprit appears to be a non-vectorized <i>Cell2JavaString</i> function)</li>
<li>include formatting and other goodies that the current <i><b>xlswrite</b></i> does not</li>
</ul>
<p>The post <a rel="nofollow" href="https://undocumentedmatlab.com/articles/xlswrite-for-mac-linux">xlswrite for Mac, Linux</a> appeared first on <a rel="nofollow" href="https://undocumentedmatlab.com">Undocumented Matlab</a>.</p>
<div class='yarpp-related-rss'>
<h3>Related posts:</h3><ol>
<li><a href="https://undocumentedmatlab.com/articles/jfreechart-graphs-and-gauges" rel="bookmark" title="JFreeChart graphs and gauges">JFreeChart graphs and gauges </a> <small>JFreeChart is an open-source charting library that can easily be integrated in Matlab...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/fixing-matlabs-actxserver" rel="bookmark" title="Fixing Matlab&#039;s actxserver">Fixing Matlab&#039;s actxserver </a> <small>Matlab's COM (ActiveX) server behavior can be fixed in a couple of useful manners. ...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/jboost-integrating-an-external-java-library-in-matlab" rel="bookmark" title="JBoost &#8211; Integrating an external Java library in Matlab">JBoost &#8211; Integrating an external Java library in Matlab </a> <small>This article shows how an external Java library can be integrated in Matlab...</small></li>
<li><a href="https://undocumentedmatlab.com/articles/setting-line-position-in-edit-box-uicontrol" rel="bookmark" title="Setting line position in an edit-box uicontrol">Setting line position in an edit-box uicontrol </a> <small>Matlab uicontrols have many useful features that are only available via Java. Here's how to access them....</small></li>
</ol>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://undocumentedmatlab.com/articles/xlswrite-for-mac-linux/feed</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
			</item>
	</channel>
</rss>
