请问.doc文档如何才能转换为.txt文档 : ) 请教 如何用C#把.doc文档中的文本转换为字符串,并输出,文本和回车换行等保留,其他如图片等去掉,并别存为.txt文件?请给点资料,谢谢大家. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用word的组件,以下代码不完整,但主要的都有了.using Word = Microsoft.Office.Interop.Word;//?aê?word′|àí Word.Application app = null; object missingValue = Type.Missing; object newTextFileName = filename+".txt"; try { app = new Word.Application(); Word.Document doc = null; // C# object fileName = filename; object saveTextFormat = Word.WdSaveFormat.wdFormatText; doc.SaveAs2000(ref newTextFileName,ref saveTextFormat, ref missingValue, ref missingValue,ref missingValue, ref missingValue,ref missingValue,ref missingValue, ref missingValue,ref missingValue,ref missingValue ); doc.Close(ref missingValue,ref missingValue,ref missingValue); }____________________________(2005年04月25日 17时25分19秒) 以下是转成html的代码,根据不同的选项,可换成不同的输出private string Get_Html(string FileName){ //FileName 绝对路径 Word.ApplicationClass word = new Word.ApplicationClass(); Type wordType = word.GetType(); Word.Documents docs = word.Documents; // 打开文件 Type docsType = docs.GetType(); string newFileNamePath = this.Server.MapPath(FileName); Word.Document doc = (Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] {newFileNamePath, true, true}); // 转换格式,另存为 Type docType = doc.GetType(); object saveFileName = newFileNamePath.Replace(".doc",".htm"); //下面是Microsoft Word 9 Object Library的写法,如果是10,可能写成: /* docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML}); */ ///其它格式: ///wdFormatHTML ///wdFormatDocument ///wdFormatDOSText ///wdFormatDOSTextLineBreaks ///wdFormatEncodedText ///wdFormatRTF ///wdFormatTemplate ///wdFormatText ///wdFormatTextLineBreaks ///wdFormatUnicodeText docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatHTML}); // 退出 Word wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null); string newFileName = FileName.Replace(".doc",".htm"); return(newFileName);} hchxxzx(NET?摸到一点门槛)成星星了啊,恭喜恭喜:)哪位再给我点资料,或者教教我怎么找资料,谢谢^!^ 应该不难你使用word组件打开这个doc文件然后调用另存为接口,保存成txt文件就可以了吧或者你选择doc的所有字符然后保存成txt文件当然都要用程序写 好心人请指教SQL导出Excel表格问题!!一生平安! 谁会一次上传多张照片给100分 如何实现这样的功能? 请教关于用户控件传值到aspx页 前台页面代码和后台代码是怎样联系的啊? 怎样用CSS自定义CALENDAR的TOOLTIP啊?? 图片在站点外的文件夹下,可以读取吗? 如何传递参数? 如何做一个在线预览图片的按钮 如何获取控件的clientname(不是clientid) asp.net Cookie问题,这个小甜饼还真是可爱啊 如何启动客户端的一个程序(Asp.net+c#),例如启动Window2000的附件中的图像处理文件kodakimg.exe?
Word.Application app = null;
object missingValue = Type.Missing;
object newTextFileName = filename+".txt";
try {
app = new Word.Application();
Word.Document doc = null;
// C#
object fileName = filename;
object saveTextFormat = Word.WdSaveFormat.wdFormatText;
doc.SaveAs2000(ref newTextFileName,ref saveTextFormat,
ref missingValue, ref missingValue,ref missingValue,
ref missingValue,ref missingValue,ref missingValue,
ref missingValue,ref missingValue,ref missingValue
);
doc.Close(ref missingValue,ref missingValue,ref missingValue);
}
____________________________
(2005年04月25日 17时25分19秒)
{
//FileName 绝对路径
Word.ApplicationClass word = new Word.ApplicationClass();
Type wordType = word.GetType();
Word.Documents docs = word.Documents; // 打开文件
Type docsType = docs.GetType();
string newFileNamePath = this.Server.MapPath(FileName);
Word.Document doc = (Word.Document)docsType.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] {newFileNamePath, true, true}); // 转换格式,另存为
Type docType = doc.GetType();
object saveFileName = newFileNamePath.Replace(".doc",".htm");
//下面是Microsoft Word 9 Object Library的写法,如果是10,可能写成:
/*
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML});
*/
///其它格式:
///wdFormatHTML
///wdFormatDocument
///wdFormatDOSText
///wdFormatDOSTextLineBreaks
///wdFormatEncodedText
///wdFormatRTF
///wdFormatTemplate
///wdFormatText
///wdFormatTextLineBreaks
///wdFormatUnicodeText
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatHTML}); // 退出 Word
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,
null, word, null); string newFileName = FileName.Replace(".doc",".htm");
return(newFileName);
}
哪位再给我点资料,或者教教我怎么找资料,谢谢^!^
你使用word组件打开这个doc文件
然后调用另存为接口,保存成txt文件就可以了吧或者你选择doc的所有字符
然后保存成txt文件当然都要用程序写