reading tables from .doc word file

22 visualizaciones (últimos 30 días)
vignashwaran s
vignashwaran s el 28 de Ag. de 2019
Comentada: João el 7 de Nov. de 2022
hi ... i can able to read a .doc file but it have some tables when i try to, read all txt in table comes in a single cell ..any one having code for reading table from word file .doc

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 28 de Ag. de 2019
Here's some starter code for you. Be aware that this code assumes that, if there are multiple tables, they are all the same size.
%% open the doc
word = actxserver('Word.Application');
% Open/Select Word file
[filename_in, pathname] = uigetfile({'*.doc;*.docx;*.docm','Word Files (*.doc,*.docx,*.docm)'; ...
'*.*', 'All Files (*.*)'}, 'Select a file');
document = word.documents.Open(fullfile(pathname,filename_in));
r=0;
tbl_cnt = document.Tables.Count;
% Loop through each table in the document
for tbl = 1 : tbl_cnt
row_cnt = document.Tables.Item(tbl).Rows.Count;
col_cnt = document.Tables.Item(tbl).Columns.Count;
for row = 1 : row_cnt
r = r+1;
for col = 1 : col_cnt
% Pull the values from the table
cell_txt = strtrim(document.Tables.Item(tbl).Cell(row, col).Range.Text);
% Add each value to its own cell
tblVals{r,col} = cell_txt;
end
end
end
% Close the document.
document.Close;
% Close Word.
word.Quit;
% delete server object
delete(word);
clear word document
  2 comentarios
vignashwaran s
vignashwaran s el 30 de Ag. de 2019
Thanks Cris.. thanks for repying, it's working.
João
João el 7 de Nov. de 2022
wdmain11.chm dependency , be aware.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by