How can I read a column from a word file?
21 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I have a word document like this and I want to read only the Type column and save it as a csv file. Is it possible in matlab?
Time Sample # Type Sub Chan Num Aux
0:00.144 52 + 0 0 0 (N
0:00.375 135 N 0 0 0
0:01.017 366 N 0 0 0
0:01.683 606 N 0 0 0
0:02.336 841 N 0 0 0
0:03.006 1082 N 0 0 0
0:03.686 1327 N 0 0 0
0:04.339 1562 N 0 0 0
0:04.983 1794 N 0 0 0
0 comentarios
Respuestas (1)
Akira Agata
el 9 de Mzo. de 2018
Editada: Akira Agata
el 9 de Mzo. de 2018
The better way is to convert your data to text (or CSV) file first by MS Word...
But, anyway, if you have to read from MS Word file, the following code can do that.
% Full path to the MS Word file
filePath = fullfile(pwd,'yourData.docx');
% Read MS Word file using actxserver function
word = actxserver('Word.Application');
wdoc = word.Documents.Open(filePath);
txt = wdoc.Content.Text;
Quit(word)
delete(word)
% Extract 'Type' column and save as CSV file
c = textscan(txt,'%s%f%s%f%f%f%s','HeaderLines',1);
csvwrite('Type.csv',c{2});
If you have Text Analytics Toolbox, you can do this more easily, like:
% Full path to the MS Word file
filePath = fullfile(pwd,'yourData.docx');
% Read MS Word file using extractFileText function
str = extractFileText(filePath)
str = strrep(str,[newline newline],newline);
% Extract 'Type' column and save as CSV file
c = textscan(str,'%s%f%s%f%f%f%s','HeaderLines',1);
csvwrite('Type.csv',c{2});
0 comentarios
Ver también
Categorías
Más información sobre Text Analytics Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!