Cell Data Formatting by Character with Matlab ActiveX
7 views (last 30 days)
Show older comments
I am trying to step through a cell array of strings and format individual characters within the string. This seems possible within Excel 2007 at least and when recording a macro I get the following result:
With ActiveCell.Characters(Start:=1, Length:=2).Font
along with some other code, but this is the only relevant one. I cannot determine how to create the Matlab equivalent of the ' Start:=1, Length:=2' Visual Basic string to be able to access the characters that I want to change.
Yair mentions in an older thread ( http://www.mathworks.com/matlabcentral/newsreader/view_thread/256216 ) that many of the classes are object collections and you must use the Item() method to retrieve them, however this does not seem to be available here. Is this level of detail possible within the Matlab script? Or would it be easier to write a visual basic script and tell Matlab to execute that (which I'd like to avoid since I'd have to package another file with the script).
Answers (1)
Fangjun Jiang
on 25 Oct 2011
I've done Excel COM server extensively but I couldn't seem to figure this out. My suspicion is that not all the Excel VB objects and methods are supported in MATLAB. In the above code, I can get access to the Characters object but couldn't figure out a way to set the font for part of the cell. I can change the font for "This" manually in Excel and try to reverse engineer a way, but still, I couldn't.
I would love to know if there is a way.
ExcelApp=actxserver('excel.application');
ExcelApp.Visible=1;
WorkBook=ExcelApp.Workbooks.Add;
NewSheet=WorkBook.Sheets.Item(1);
NewRange=NewSheet.Range('A1');
NewRange.Value='This is a test.';
C=NewRange.Characters;
get(C.Font)
See Also
Categories
Find more on Use COM Objects in MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!