How to read MS word file(*.doc/docx).

32 views (last 30 days)
kevin levin
kevin levin on 14 Jul 2017
Commented: Ioonut on 30 Apr 2020
I have to import data from MS word file and consider the imported file as 'string' but in some case, their are many pictures, images, table etc have into the file. Is it possible to do that in MATLAB or I could have to switch to any other language? Thank YOU

Answers (1)

Guillaume
Guillaume on 14 Jul 2017
Edited: Guillaume on 14 Jul 2017
The issue is not matlab. You'll have to go through exactly the same difficulties whichever language you use. The issue is more that a Word document is not a simple string. You can certainly extract the various sections of text from a word document in any language but you'll have to work for it.
All the functions to navigate a Word document are documented on MSDN. The most important object for you is the Document object.
This could be a start:
word = actxserver('Word.Application');
wdoc = word.Documents.Open('C:\somewhere\somefile.docx');
%wdoc is the Document object which you can query and navigate.
sometext = wdoc.Content.Text;
  3 Comments
Tobias Huth
Tobias Huth on 26 Nov 2018
Thanks for the help!
One should not forget to close the objects:
wdoc.Close; % close document
word.Quit; % end application
Greetings,
Tobias
Ioonut
Ioonut on 30 Apr 2020
do you know how to extract the pictures from a doc file that has for example 10 pictures inserted?
I understood from MSDN that wdoc.InlineShapes should contain this,but I dont know how I could get a variable like 'picture' or how to index it
picture = wdoc.something(index)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!