Friday, December 4, 2015

Adding xlwrite to Matlab Static Path

Disclaimer: I'm not sure if the following steps going to mess up your system. This is what works for me, atm. Use at your own risk.

In my earlier post, I added the xlwrite and its needed 6 jar files to Matlab dynamic path. However every time I restart Matlab, I have have to re-do this setting again. I hate going back to my own post and checking out the steps, spending another 1 min to set up the system to use xlwrite. I know 1 min is nothing, but I like things automated. To go about this, add the jar files to Matlab static path. Check here for more about Static Path vs Dynamic Path.

I look everywhere on how to add jar files to static path. I didn't find any clear instructions on how to edit the classpath.txt, anyway this is what works for me.

Steps:

1. In Matlab command window:
>> edit classpath.txt
2. M-file will open. MATLAB reads the static class path only at startup. You can see these are all the files loaded at startup. Eg:
$matlabroot/java/jar/zh_CN/web_connectivity_res.jar

3. We want Matlab to load our desired jar files at startup too. So put your jar files (poi_library) in matlabroot/java/jar/. Where on earth is this place? I'm using Mac, so that place is
Applications> Matlab>right-click>Show Package Contents>Java>jar

matlabroot/java/jar

4. Back to Matlab, append the following at classpath.txt
$matlabroot/java/jar/poi_library/poi-3.8-20120326.jar
$matlabroot/java/jar/poi_library/poi-ooxml-3.8-20120326.jar
$matlabroot/java/jar/poi_library/poi-ooxml-schemas-3.8-20120326.jar
$matlabroot/java/jar/poi_library/xmlbeans-2.3.0.jar
$matlabroot/java/jar/poi_library/dom4j-1.6.1.jar
$matlabroot/java/jar/poi_library/stax-api-1.0.1.jar

Append classpath.txt
 5. Save and restart Matlab.


Note: If you have warning regarding 'undefined xlwrite function', means you haven't set the path to xlwrite yet. To set the path:


No comments:

Post a Comment