How can I read a column from a word file?

조회 수: 21 (최근 30일)
SSG_newbiecoder
SSG_newbiecoder 2018년 3월 9일
편집: Akira Agata 2018년 3월 9일
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

답변 (1개)

Akira Agata
Akira Agata 2018년 3월 9일
편집: Akira Agata 2018년 3월 9일
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});

카테고리

Help CenterFile Exchange에서 Text Analytics Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by