`
varsoft
  • 浏览: 2435320 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

把Doc文档转换成HTML等其它格式

阅读更多

利用microsoftWord9.0ObjectLibrary可以在页面中对Doc文档进行格式转换。有关Word对象的一些方法可以参考Open和Save。下面是进行转换的代码[C#]:

///<summary>
///WordToHtml的摘要说明。
///首先要添加引用:MicrosoftWord9.0ObjectLibrary
///</summary>

word.applicationclassword=newWord.ApplicationClass();
TypewordType=word.GetType();
Word.Documentsdocs=word.Documents;

//打开文件
TypedocsType=docs.GetType();
objectfileName="d:\\tmp\\aaa.doc";
Word.Documentdoc=(Word.Document)docsType.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod,null,docs,newObject[]{fileName,true,true});

//转换格式,另存为
TypedocType=doc.GetType();
objectsaveFileName="d:\\tmp\\aaa.html";
//下面是MicrosoftWord9ObjectLibrary的写法,如果是10,可能写成:
//docType.InvokeMember("SaveAs",System.Reflection.BindingFlags.InvokeMethod,null,
//doc,newobject[]{saveFileName,Word.WdSaveFormat.wdFormatFilteredHTML});
///其它格式:
///wdFormatHTML
///wdFormatDocument
///wdFormatDOSText
///wdFormatDOSTextLineBreaks
///wdFormatEncodedText
///wdFormatRTF
///wdFormatTemplate
///wdFormatText
///wdFormatTextLineBreaks
///wdFormatUnicodeText
docType.InvokeMember("SaveAs",System.Reflection.BindingFlags.InvokeMethod,null,
doc,newobject[]{saveFileName,Word.WdSaveFormat.wdFormatHTML});

//退出Word
wordType.InvokeMember("Quit",System.Reflection.BindingFlags.InvokeMethod,null,word,null);

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics