How can I set landscape and margins in word using matlab activex

조회 수: 9 (최근 30일)
Andrew Tilmouth
Andrew Tilmouth 2012년 11월 1일
댓글: Jeff Shi 2015년 9월 15일
I am using writetoword.m from the matlab file exchange to print figures and text to a word document but I would also like to make the document landscape orientation and change the right and left margins to 1cm as well.
I tried adding these lines of code at the beginning of the wrtietoword.m file after it creates the word document:-
This line gives no errors but does not seem to do anything and does not change the orientation to lanscape:- actXword.ActiveDocument.Pagesetup.Orientation = 'wdOrientLandscape';
Thesee lines give an error actXword.ActiveDocument.Pagesetup.LeftMargin = 'CentimetersToPoints(1)'; actXword.ActiveDocument.Pagesetup.RightMargin = 'CentimetersToPoints(1)';
Can anyone hep with the right syntax. Is there a good guide anywhere for the matlab activex syntax versions of VBA commands ?
thanks Andrew

채택된 답변

Eric
Eric 2012년 11월 1일
편집: Eric 2012년 11월 1일
wdOrientLandscape is part of an enumeration. It's value is actually 1.
The proper usage for CentimetersToPoints should be
actXword.CentimetersToPoints(1)
but this gives an error. I'm not sure why. However, this is easy enough to set without calling the function as 1 cm is equal to 28.3464567 points.
I'm not sure of a good guide. The command structure for the COM interface to Word is quite similar to the VBA commands - you just have to be careful. Some thoughts that come to mind:
1. You can never assume that the root object is known. For example, in VBA you generally don't have to supply the base "Application" argument. This is why you would need to supply actXword.CentimetersToPoints rather than just CentimetersToPoints when calling the function from Matlab.
2. You have to be careful with collections and how you index into them. In VBA you can often supply a text argument to index into a collection (e.g., reference a worksheet by its name in Excel). This does not work in the COM interface. You have to index into the Item property of the collection.
3. You also have to be careful with enumerations (see above). To get enumeration values, open the VBA editor and go to the Immediate window. To get the value for an enumeration type
?enumerationName
This will show you the actual numerical value to use. You can also look these up on the web.
4. A useful function in Matlab is methodsview(). This can give you information about what methods an object supports.
Good luck,
Eric

추가 답변 (1개)

Andrew Tilmouth
Andrew Tilmouth 2012년 11월 2일
Thanks Eric
so the following lines of code work correctly in word 2010 at least
To set the left and right margins to 1cm:-ActXWord.ActiveDocument.PageSetup.LeftMargin = 28.3464567 ; ActXWord.ActiveDocument.PageSetup.RightMargin = 28.3464567;
To set the doc to landscape:- (because wdOrientLandscape enum = 1) ActXWord.ActiveDocument.PageSetup.Orientation = 1;
Andrew

카테고리

Help CenterFile Exchange에서 ActiveX에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by