How to retrieve CustomDocumentProperties from Microsoft Word?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Antworten (1)
Andrea Carignano
am 10 Mär. 2021
Bearbeitet: Andrea Carignano
am 10 Mär. 2021
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');
0 Kommentare
Siehe auch
Kategorien
Mehr zu Use COM Objects in MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!