Search code examples
matlabformatxlsxexcel-2011

xlwrite changing font format in Excel


I am currently running MATLAB R2013a on OSX and am attempting to write the contents of a cell array into a specified cell of an .xlsx file in Excel 2011 for Mac. When I first tried using the built-in MATLAB function xlswrite, I was unsuccessful, and after doing a bit of digging, I came to the conclusion that this function would not work as I needed because actxserver is not supported on my Mac. Therefore, I did a bit of research online and found the xlwrite function here.

After downloading the package, I am successfully able to use this code to write the contents of a cell array into a specified cell of my .xlsx file, however, I've run into a problem. How do I get the contents of the cell I am editing to keep the previous .xlsx formatting of the cell? For example, the blank cell I am writing into is set to bold Cambria font size 10, but when I run this code, the contents of the cell change to non-bold Calibri (Body) font size 12. I've tried changing the Excel default font setting, but it always reverts to Calibri (Body) font size 12. Is there a trick to keep the formatting the same? Thanks for the help!


Solution

  • I think this is caused by Excel behavior. I think that the Style "Normal" (or whatever style your data is in) in Excel has automatically formatted new data with font Calibri.. I personally think it is no big deal.

    However if you want to fix, you can try open the Excel file. Select a cell with font Calibri, go to tab Home (Excel 2010), then Cell Styles, right click Normal (or the current style name), then Modify. Then untick the box Font -> ok. And then Save the file and re-run the Matlab script.

    enter image description here