How to retrieve CustomDocumentProperties from Microsoft Word?

조회 수: 9 (최근 30일)
Marcel Geers
Marcel Geers 2019년 7월 2일
편집: Andrea Carignano 2021년 3월 10일
Matlab provides the means to interact with Microsoft Office programs via several interfaces. I'm currently trying to interact with MS Word via the ActiveX or .Net interfaces. Specifically, I'm trying to retrieve and edit CustomDocumentProperties. These are basically properties the user has added themselves in the MS Word application.
ActiveX approach:
%% Connect to word
Word = actxserver('word.application');
%% Open a template file
WordObj = Word.Documents.Open(fullfile(pwd,'test.docx'));
%% "Unlock" the CustomDocumentProperties
CDP = WordObj.CustomDocumentProperties;
So far so good. I can retrieve the correct number of Custom properties that have been added in the template Word file:
CDP.Count
However, I'm stuck this point onwards. It seems I cannot go further than this. What syntax should I use to get or set one of these properties? The properties are approachable via VBA, but not via Matlab or so it seems.
.NET approach:
WordDocObj = mlreportgen.utils.WordDoc("test.docx") % Note, .docm not allowed
Document = netobj(WordDocObj);
Document.CustomDocumentProperties
This produces the following error:
ans =
__ComObject with no properties.

답변 (1개)

Andrea Carignano
Andrea Carignano 2021년 3월 10일
편집: Andrea Carignano 2021년 3월 10일
Hi Marcel,
Suppose you have a custon property "MyCustomProperty".
You can use this code to get the property object
PropertyObject = get(CDP,'Item','MyCustomProperty');
To get the propery value
PropertyValue = get(PropertyObject,'Value');
To set the property value
set(PropertyObject,'Value','Your property value');

카테고리

Help CenterFile Exchange에서 Use COM Objects in MATLAB에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by