MATLAB: Fill a table column in word files from matlab

microsoft word

i have 300 word document files ,in each there is a same sized table , i need to fill one column with the same data for all tables in all files, can i do this using matlab ?

Best Answer

It is possible to interact with words document using Word Object Model. The most difficult is probably going to locate the table if its position in the document is arbitrary.
Assuming the table is the first one in the document, then this should get you started:
files = {...}; %list of files to process, obtained any way you want, possibly with dir
word = actxserver('Word.Application'); %instantiate Word
word.Visible = true; %optional, useful to see what is going on when debugging
for fileidx = 1:numel(files)
document = word.Documents.Open(files{fileidx}); %open file
wordtbl = document.Tables.Item(1); %get 1st table
tblcell = wordtbl.CellItem(1, 2); %get reference to cell in row 1, column 2
tblcell.Range.Text = 'fill me'; %write text
document.Save;
end
word.Quit;
delete word;
Note: this is completely untested code. There may be bugs or stuff I've forgotten.