如何读取word文档中的文字然后将他写到一个TXT文件中

时间:2022-09-29 21:56:00
如何读取word文档中的文字然后将他写到一个TXT文件中

7 个解决方案

#1


建议使用ole的variant,集成office比较方便

#2


读取word 文档中的文字放入RichEdit中,然后从RichEdit 中放入Txt中.
RichEdit->Lines->LoadFromFile("note.rtf");//从Word中读出放入RichEdit中
RichEdit->Lines->SaveToFile("note.txt");  //写到Txt文件中

#3


qiushenwei88(山亭):不对啊,从word中读出来的是乱玛?

#4


012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
测试一下,嘻嘻!

#5


rtf的话;可以自己分析以下格式即可

{\rtf1\ansi\ansicpg936\uc2 \deff15\deflang1033\deflangfe2052{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f15\fnil\fcharset134\fprq2{\*\panose 02010600030101010101}\'cb\'ce\'cc\'e5;}
{\f20\fnil\fcharset134\fprq2{\*\panose 02010600030101010101}@\'cb\'ce\'cc\'e5;}{\f23\froman\fcharset238\fprq2 Times New Roman CE;}{\f24\froman\fcharset204\fprq2 Times New Roman Cyr;}{\f26\froman\fcharset161\fprq2 Times New Roman Greek;}
{\f27\froman\fcharset162\fprq2 Times New Roman Tur;}{\f28\froman\fcharset186\fprq2 Times New Roman Baltic;}{\f115\fnil\fcharset0\fprq2 \'cb\'ce\'cc\'e5;}{\f145\fnil\fcharset0\fprq2 @\'cb\'ce\'cc\'e5;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;
\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;
\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}{\stylesheet{\qj\nowidctlpar\aspalpha\aspnum\faauto\adjustright \fs21\kerning2\loch\af0\hich\af0\dbch\f15\cgrid \snext0 Normal;}{\*\cs10 \additive Default Paragraph Font;}}{\info
{\title 01234567890123456789012345678901234567890123456789012345678901234567890123456789}{\author chen}{\operator chen}{\creatim\yr2004\mo7\dy16\hr12\min20}{\revtim\yr2004\mo7\dy16\hr12\min22}{\version2}{\edmins1}{\nofpages1}{\nofwords0}{\nofchars0}
{\vern77}}\paperw11906\paperh16838\margl1800\margr1800\margt1440\margb1440\gutter0 {\*\fchars 
!),.:\'3b?]\'7d\'a1\'a7\'a1\'a4\'a1\'a6\'a1\'a5\'a8\'44\'a1\'ac\'a1\'af\'a1\'b1\'a1\'ad\'a1\'c3\'a1\'a2\'a1\'a3\'a1\'a8\'a1\'a9\'a1\'b5\'a1\'b7\'a1\'b9\'a1\'bb\'a1\'bf\'a1\'b3\'a1\'bd\'a3\'a1\'a3\'a2\'a3\'a7\'a3\'a9\'a3\'ac\'a3\'ae\'a3\'ba\'a3\'bb
\'a3\'bf\'a3\'dd\'a3\'e0\'a3\'fc\'a3\'fd\'a1\'ab\'a1\'e9}{\*\lchars ([\'7b\'a1\'a4\'a1\'ae\'a1\'b0\'a1\'b4\'a1\'b6\'a1\'b8\'a1\'ba\'a1\'be\'a1\'b2\'a1\'bc\'a3\'a8\'a3\'ae\'a3\'db\'a3\'fb\'a1\'ea\'a3\'a4}
\deftab425\ftnbj\aenddoc\hyphcaps0\formshade\horzdoc\dgmargin\dghspace180\dgvspace156\dghorigin1800\dgvorigin1440\dghshow0\dgvshow2\jcompress\lnongrid\viewkind1\viewscale100 \fet0\sectd 
\linex0\headery851\footery992\colsx425\endnhere\sectlinegrid312\sectspecifyl {\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang{\pntxta \dbch .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang{\pntxta \dbch .}}{\*\pnseclvl3
\pndec\pnstart1\pnindent720\pnhang{\pntxta \dbch .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang{\pntxta \dbch )}}{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang{\pntxtb \dbch (}{\pntxta \dbch )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang
{\pntxtb \dbch (}{\pntxta \dbch )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang{\pntxtb \dbch (}{\pntxta \dbch )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang{\pntxtb \dbch (}{\pntxta \dbch )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang
{\pntxtb \dbch (}{\pntxta \dbch )}}\pard\plain \qj\nowidctlpar\aspalpha\aspnum\faauto\adjustright \fs21\kerning2\loch\af0\hich\af0\dbch\f15\cgrid {\hich\af0\dbch\af15\loch\f0 01234567890123456789012345678901234567890123456789012345678901234567890123456789
}{\hich\af0\dbch\af15\loch\f0 wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\hich\af0\dbch\af15\loch\f0 wwwwwwwwwwwwwwww
\par }}

#6


你的文件的路径要正确,不能象我那样写,要设置文件的路径.

#7


用 WORD控件吧

#1


建议使用ole的variant,集成office比较方便

#2


读取word 文档中的文字放入RichEdit中,然后从RichEdit 中放入Txt中.
RichEdit->Lines->LoadFromFile("note.rtf");//从Word中读出放入RichEdit中
RichEdit->Lines->SaveToFile("note.txt");  //写到Txt文件中

#3


qiushenwei88(山亭):不对啊,从word中读出来的是乱玛?

#4


012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
测试一下,嘻嘻!

#5


rtf的话;可以自己分析以下格式即可

{\rtf1\ansi\ansicpg936\uc2 \deff15\deflang1033\deflangfe2052{\fonttbl{\f0\froman\fcharset0\fprq2{\*\panose 02020603050405020304}Times New Roman;}{\f15\fnil\fcharset134\fprq2{\*\panose 02010600030101010101}\'cb\'ce\'cc\'e5;}
{\f20\fnil\fcharset134\fprq2{\*\panose 02010600030101010101}@\'cb\'ce\'cc\'e5;}{\f23\froman\fcharset238\fprq2 Times New Roman CE;}{\f24\froman\fcharset204\fprq2 Times New Roman Cyr;}{\f26\froman\fcharset161\fprq2 Times New Roman Greek;}
{\f27\froman\fcharset162\fprq2 Times New Roman Tur;}{\f28\froman\fcharset186\fprq2 Times New Roman Baltic;}{\f115\fnil\fcharset0\fprq2 \'cb\'ce\'cc\'e5;}{\f145\fnil\fcharset0\fprq2 @\'cb\'ce\'cc\'e5;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;
\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;
\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}{\stylesheet{\qj\nowidctlpar\aspalpha\aspnum\faauto\adjustright \fs21\kerning2\loch\af0\hich\af0\dbch\f15\cgrid \snext0 Normal;}{\*\cs10 \additive Default Paragraph Font;}}{\info
{\title 01234567890123456789012345678901234567890123456789012345678901234567890123456789}{\author chen}{\operator chen}{\creatim\yr2004\mo7\dy16\hr12\min20}{\revtim\yr2004\mo7\dy16\hr12\min22}{\version2}{\edmins1}{\nofpages1}{\nofwords0}{\nofchars0}
{\vern77}}\paperw11906\paperh16838\margl1800\margr1800\margt1440\margb1440\gutter0 {\*\fchars 
!),.:\'3b?]\'7d\'a1\'a7\'a1\'a4\'a1\'a6\'a1\'a5\'a8\'44\'a1\'ac\'a1\'af\'a1\'b1\'a1\'ad\'a1\'c3\'a1\'a2\'a1\'a3\'a1\'a8\'a1\'a9\'a1\'b5\'a1\'b7\'a1\'b9\'a1\'bb\'a1\'bf\'a1\'b3\'a1\'bd\'a3\'a1\'a3\'a2\'a3\'a7\'a3\'a9\'a3\'ac\'a3\'ae\'a3\'ba\'a3\'bb
\'a3\'bf\'a3\'dd\'a3\'e0\'a3\'fc\'a3\'fd\'a1\'ab\'a1\'e9}{\*\lchars ([\'7b\'a1\'a4\'a1\'ae\'a1\'b0\'a1\'b4\'a1\'b6\'a1\'b8\'a1\'ba\'a1\'be\'a1\'b2\'a1\'bc\'a3\'a8\'a3\'ae\'a3\'db\'a3\'fb\'a1\'ea\'a3\'a4}
\deftab425\ftnbj\aenddoc\hyphcaps0\formshade\horzdoc\dgmargin\dghspace180\dgvspace156\dghorigin1800\dgvorigin1440\dghshow0\dgvshow2\jcompress\lnongrid\viewkind1\viewscale100 \fet0\sectd 
\linex0\headery851\footery992\colsx425\endnhere\sectlinegrid312\sectspecifyl {\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang{\pntxta \dbch .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang{\pntxta \dbch .}}{\*\pnseclvl3
\pndec\pnstart1\pnindent720\pnhang{\pntxta \dbch .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang{\pntxta \dbch )}}{\*\pnseclvl5\pndec\pnstart1\pnindent720\pnhang{\pntxtb \dbch (}{\pntxta \dbch )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang
{\pntxtb \dbch (}{\pntxta \dbch )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang{\pntxtb \dbch (}{\pntxta \dbch )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang{\pntxtb \dbch (}{\pntxta \dbch )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang
{\pntxtb \dbch (}{\pntxta \dbch )}}\pard\plain \qj\nowidctlpar\aspalpha\aspnum\faauto\adjustright \fs21\kerning2\loch\af0\hich\af0\dbch\f15\cgrid {\hich\af0\dbch\af15\loch\f0 01234567890123456789012345678901234567890123456789012345678901234567890123456789
}{\hich\af0\dbch\af15\loch\f0 wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\hich\af0\dbch\af15\loch\f0 wwwwwwwwwwwwwwww
\par }}

#6


你的文件的路径要正确,不能象我那样写,要设置文件的路径.

#7


用 WORD控件吧