请教 如何用C#把.doc文档中的文本转换为字符串,并输出,文本和回车换行等保留,其他如图片等去掉,并别存为.txt文件?请给点资料,谢谢大家.
解决方案 »
- 关于为空的正则表达式
- asp.net如何控制视频排序转换或者控制cpu使用率
- 我想把一个产品结构树呈现出来 怎么做?
- 急求!如何实现大文件分部分存储????
- 找不到文件或程序集名称“CrystalDecisions.Shared”,(懂水晶报表,是高手请进)
- 一个验证码小问题
- iframe的问题,到底错在哪里?
- 水晶报表中的又一个怪现象!!!
- asp.net c#中能不能对mouse事件进行处理
- 如何在asp.net中实现如下刷新的 java函数?
- 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文件当然都要用程序写