How does one set the number format of an excel cell using activex?

16 views (last 30 days)
I have an excel spreadsheet that contains the current date in cell A1. How can I ensure that the date format is set to ISO 8601 ( that is, 'yyyy-mm-dd') so that I can be sure that the date is unambiguous across different user settings?
I have successfully written the date using xlswrite, but to set the format of the cell to a specific format, I assume I have to use activex commands.
This is what I have tried: (xlfn is the file name of the spreadsheet).
Excel = actxserver('Excel.Application');
set(Excel,'Visible',1)
Workbook = Excel.Workbooks.Open(xlfn);
Sheets = Workbook.Sheets;
Sheet = invoke(Sheets, 'Item', 1);
Sheet.Name='Test';
Sheet.Range('A1').NumberFormat = 'yyyy-mm-dd';
Any suggestions?

Answers (1)

Image Analyst
Image Analyst on 11 Dec 2014
Or, you can record a macro in Excel, then you can format some cell the way you want in Excel, then stop recording and look at (edit) the macro to see what commands and format strings it used. Then replicate those in your MATLAB code. This is a very handy method for figuring out what ActiveX commands you need to use.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!