<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/155929</link>
    <title>MATLAB Central Newsreader - xlswrite?</title>
    <description>Feed for thread: xlswrite?</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 11 Sep 2007 10:06:34 -0400</pubDate>
      <title>xlswrite?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/155929#391593</link>
      <author>Cooky Monster</author>
      <description>Dear All&lt;br&gt;
&lt;br&gt;
I have a matrix M of three columns and 100 rows. I like to &lt;br&gt;
export it to Excel. I have to add the lables also. &lt;br&gt;
&lt;br&gt;
I am using &lt;br&gt;
&lt;br&gt;
Titles = {'Number of Cycles', 'Crack Length','Crack Growth &lt;br&gt;
Rate'}&lt;br&gt;
Labels = {'Cycles', 'a','da/dN'}&lt;br&gt;
Units = {'[Cycles]', '[mm]','[mm/Cycles]'}&lt;br&gt;
[newmatfile, newpath] = uiputfile('*.xls', 'Save As');&lt;br&gt;
filename = [newpath,newmatfile];&lt;br&gt;
if isempty(findstr([newpath,newmatfile],'.xls')) &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;filename = [filename,'.xls'];&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
xlswrite(filename, Titles, 1, 'A2')&lt;br&gt;
xlswrite(filename, Labels, 1, 'A3')&lt;br&gt;
xlswrite(filename, Units, 1, 'A4')&lt;br&gt;
xlswrite(filename, M,1, 'A6')&lt;br&gt;
&lt;br&gt;
I like to ask if I can auto width the columns in Excel &lt;br&gt;
sheet using any matlab command and also to change the font &lt;br&gt;
size.&lt;br&gt;
&lt;br&gt;
Thanks in Advance&lt;br&gt;
&lt;br&gt;
Regards</description>
    </item>
    <item>
      <pubDate>Tue, 11 Sep 2007 10:44:44 -0400</pubDate>
      <title>Re: xlswrite?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/155929#391598</link>
      <author>Yair Altman</author>
      <description>&quot;Cooky Monster&quot; &amp;lt;sharif.uk@gmail.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;snip&amp;gt;&lt;br&gt;
&amp;gt; I like to ask if I can auto width the columns in Excel &lt;br&gt;
&amp;gt; sheet using any matlab command and also to change the font &lt;br&gt;
&amp;gt; size.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
You cannot do this with xlswrite. However, you can do this&lt;br&gt;
by directly accessing the Excel COM server and running&lt;br&gt;
column-width and font-size VB commands on that server. The&lt;br&gt;
same applies to any other formating you may wish to do on&lt;br&gt;
the data. To see how to do this, you can edit xlswrite.m:&lt;br&gt;
It's a relatively long function, but if you ignore the&lt;br&gt;
error-checking parts, you'll see that the actual skeleton is&lt;br&gt;
pretty small.&lt;br&gt;
&lt;br&gt;
An alternative is to use the OfficeDoc submission on the&lt;br&gt;
File Exchange:&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=15192&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=15192&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
Yair Altman&lt;br&gt;
&lt;a href=&quot;http://ymasoftware.com&quot;&gt;http://ymasoftware.com&lt;/a&gt;</description>
    </item>
    <item>
      <pubDate>Fri, 06 Aug 2010 15:30:23 -0400</pubDate>
      <title>Re: xlswrite?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/155929#769192</link>
      <author>Gina Stuessy</author>
      <description>&amp;gt; You cannot do this with xlswrite. However, you can do this&lt;br&gt;
&amp;gt; by directly accessing the Excel COM server and running&lt;br&gt;
&amp;gt; column-width and font-size VB commands on that server. The&lt;br&gt;
&amp;gt; same applies to any other formating you may wish to do on&lt;br&gt;
&amp;gt; the data. To see how to do this, you can edit xlswrite.m:&lt;br&gt;
&amp;gt; It's a relatively long function, but if you ignore the&lt;br&gt;
&amp;gt; error-checking parts, you'll see that the actual skeleton is&lt;br&gt;
&amp;gt; pretty small.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; An alternative is to use the OfficeDoc submission on the&lt;br&gt;
&amp;gt; File Exchange:&lt;br&gt;
&amp;gt; &lt;a href=&quot;http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=15192&quot;&gt;http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=15192&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Yair Altman&lt;br&gt;
&amp;gt; &lt;a href=&quot;http://ymasoftware.com&quot;&gt;http://ymasoftware.com&lt;/a&gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Can you tell me specifically how to edit the xlswrite file to set the column widths for each column separately? (Not just 1 width that applies to the whole document.)&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
Gina</description>
    </item>
    <item>
      <pubDate>Fri, 06 Aug 2010 15:50:08 -0400</pubDate>
      <title>Re: xlswrite?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/155929#769208</link>
      <author>Andy </author>
      <description>% sample code&lt;br&gt;
&lt;br&gt;
e=actxserver('excel.application');&lt;br&gt;
eW=e.Workbooks;&lt;br&gt;
eF=eW.Open(filename); % your filename here&lt;br&gt;
eS=eF.ActiveSheet;&lt;br&gt;
eS.Range('A1').EntireColumn.AutoFit; % autofit column A&lt;br&gt;
eS.Range('A1').EntireColumn.Font.Name = 'Times'; % changes font to Times</description>
    </item>
    <item>
      <pubDate>Fri, 06 Aug 2010 16:59:06 -0400</pubDate>
      <title>Re: xlswrite?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/155929#769240</link>
      <author>Gina Stuessy</author>
      <description>&quot;Andy &quot; &amp;lt;myfakeemailaddress@gmail.com&amp;gt; wrote in message &amp;lt;i3havg$gkf$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; % sample code&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; e=actxserver('excel.application');&lt;br&gt;
&amp;gt; eW=e.Workbooks;&lt;br&gt;
&amp;gt; eF=eW.Open(filename); % your filename here&lt;br&gt;
&amp;gt; eS=eF.ActiveSheet;&lt;br&gt;
&amp;gt; eS.Range('A1').EntireColumn.AutoFit; % autofit column A&lt;br&gt;
&amp;gt; eS.Range('A1').EntireColumn.Font.Name = 'Times'; % changes font to Times&lt;br&gt;
&lt;br&gt;
I'm sorry, I was unclear. I meant I would like to save some data to an excel file through Matlab and save also the widths that the columns should be when the file is opened by someone else who has only Excel. I do not want to open the file through Matlab and then format the columns.&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
Gina</description>
    </item>
    <item>
      <pubDate>Fri, 06 Aug 2010 17:10:08 -0400</pubDate>
      <title>Re: xlswrite?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/155929#769244</link>
      <author>Andy </author>
      <description>&quot;Gina Stuessy&quot; &amp;lt;gstuessy@gmail.com&amp;gt; wrote in message &amp;lt;i3hf0q$3ve$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Andy &quot; &amp;lt;myfakeemailaddress@gmail.com&amp;gt; wrote in message &amp;lt;i3havg$gkf$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; % sample code&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; e=actxserver('excel.application');&lt;br&gt;
&amp;gt; &amp;gt; eW=e.Workbooks;&lt;br&gt;
&amp;gt; &amp;gt; eF=eW.Open(filename); % your filename here&lt;br&gt;
&amp;gt; &amp;gt; eS=eF.ActiveSheet;&lt;br&gt;
&amp;gt; &amp;gt; eS.Range('A1').EntireColumn.AutoFit; % autofit column A&lt;br&gt;
&amp;gt; &amp;gt; eS.Range('A1').EntireColumn.Font.Name = 'Times'; % changes font to Times&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I'm sorry, I was unclear. I meant I would like to save some data to an excel file through Matlab and save also the widths that the columns should be when the file is opened by someone else who has only Excel. I do not want to open the file through Matlab and then format the columns.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks,&lt;br&gt;
&amp;gt; Gina&lt;br&gt;
&lt;br&gt;
Right, so after writing your data with xlswrite, this code shows you exactly how to autofit the columns (and change the font if you wish) so that when somebody opens the spreadsheet later, the columns will be the correct width.  I'm not sure what more you're asking for right now.</description>
    </item>
    <item>
      <pubDate>Fri, 06 Aug 2010 17:49:04 -0400</pubDate>
      <title>Re: xlswrite?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/155929#769254</link>
      <author>Gina Stuessy</author>
      <description>For some reason when I use that script, I get an error message saying the document is already open. If I choose to reopen it, it does have the column width set and the font changed, but then when I close the file and try to open it again, it doesn't. It appears this only works the first time it's opened.</description>
    </item>
    <item>
      <pubDate>Fri, 06 Aug 2010 18:07:04 -0400</pubDate>
      <title>Re: xlswrite?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/155929#769260</link>
      <author>Andy </author>
      <description>&quot;Gina Stuessy&quot; &amp;lt;gstuessy@gmail.com&amp;gt; wrote in message &amp;lt;i3hhug$bnf$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; For some reason when I use that script, I get an error message saying the document is already open. If I choose to reopen it, it does have the column width set and the font changed, but then when I close the file and try to open it again, it doesn't. It appears this only works the first time it's opened.&lt;br&gt;
&lt;br&gt;
Well, if you already have the document open when doing this, then replace the first line with:&lt;br&gt;
&lt;br&gt;
e=actxGetRunningServer('excel.application');&lt;br&gt;
&lt;br&gt;
Also, if you want to programmatically save and close the file after changing the width, add to the end:&lt;br&gt;
&lt;br&gt;
eF.Save;&lt;br&gt;
eF.Close; % close the file&lt;br&gt;
e.Quit; % close Excel entirely&lt;br&gt;
&lt;br&gt;
But it is probably a bad idea to use actxGetRunningServer to edit Excel files while they're already open.  It is much safer to do this when Excel is closed.</description>
    </item>
    <item>
      <pubDate>Fri, 06 Aug 2010 18:25:27 -0400</pubDate>
      <title>Re: xlswrite?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/155929#769266</link>
      <author>Gina </author>
      <description>This is what I have so far:&lt;br&gt;
&lt;br&gt;
[FileName,PathName,FilterIndex] = uiputfile(TableFilename);&lt;br&gt;
xlswrite([PathName, FileName], SliceData);&lt;br&gt;
e=actxserver('excel.application');&lt;br&gt;
eW=e.Workbooks;&lt;br&gt;
eF=eW.Open(FileName); % your filename here&lt;br&gt;
eS=eF.ActiveSheet;&lt;br&gt;
eS.Range('B1').EntireColumn.AutoFit; % autofit column A&lt;br&gt;
eS.Range('A1').EntireColumn.Font.Name = 'Times'; % changes font to Times&lt;br&gt;
eF.Save;&lt;br&gt;
eF.Close; % close the file&lt;br&gt;
e.Quit; % close Excel entirely&lt;br&gt;
&lt;br&gt;
I'm getting an error that says the Open function doesn't work because the filename cannot be found, even though the file saves correctly.</description>
    </item>
    <item>
      <pubDate>Fri, 06 Aug 2010 18:29:06 -0400</pubDate>
      <title>Re: xlswrite?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/155929#769271</link>
      <author>Gina </author>
      <description>Nevermind my previous message, that worked when I put the path name and file name in as inputs instead of just the filename.&lt;br&gt;
&lt;br&gt;
Thanks for all the help!</description>
    </item>
    <item>
      <pubDate>Sat, 12 Mar 2011 16:48:04 -0500</pubDate>
      <title>Re: xlswrite?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/155929#824637</link>
      <author>Brad Z</author>
      <description>&quot;Andy&quot; wrote in message &amp;lt;i3hflg$f40$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Gina Stuessy&quot; &amp;lt;gstuessy@gmail.com&amp;gt; wrote in message &amp;lt;i3hf0q$3ve$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &quot;Andy &quot; &amp;lt;myfakeemailaddress@gmail.com&amp;gt; wrote in message &amp;lt;i3havg$gkf$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; % sample code&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; e=actxserver('excel.application');&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; eW=e.Workbooks;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; eF=eW.Open(filename); % your filename here&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; eS=eF.ActiveSheet;&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; eS.Range('A1').EntireColumn.AutoFit; % autofit column A&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; eS.Range('A1').EntireColumn.Font.Name = 'Times'; % changes font to Times&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; I'm sorry, I was unclear. I meant I would like to save some data to an excel file through Matlab and save also the widths that the columns should be when the file is opened by someone else who has only Excel. I do not want to open the file through Matlab and then format the columns.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Thanks,&lt;br&gt;
&amp;gt; &amp;gt; Gina&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Right, so after writing your data with xlswrite, this code shows you exactly how to autofit the columns (and change the font if you wish) so that when somebody opens the spreadsheet later, the columns will be the correct width.  I'm not sure what more you're asking for right now.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Just to be super clear, it works if you insert this after line 238 in xlswrite:&lt;br&gt;
Excel.selection.EntireColumn.AutoFit;&lt;br&gt;
&lt;br&gt;
So, the new code should look like this:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;% Export data to selected region.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;set(Excel.selection,'Value',A);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Excel.selection.EntireColumn.AutoFit;  % This is the new part&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ExcelWorkbook.Save&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ExcelWorkbook.Close(false)  % Close Excel workbook.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Excel.Quit;&lt;br&gt;
&lt;br&gt;
You might want to rename it before the save. I has worked for me, but that doesn't mean there isn't some bug lurking around.</description>
    </item>
  </channel>
</rss>

