How can I read a column from a word file?
21 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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});
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Text Analytics Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!