把Doc文档转换成HTML等其它格式
2007-03-22 00:23
423 查看
利用microsoft Word 9.0 Object Library可以在页面中对Doc文档进行格式转换。有关Word对象的一些方法可以参考Open和Save。下面是进行转换的代码[C#]:
/// <summary>
/// WordToHtml 的摘要说明。
/// 首先要添加引用:Microsoft Word 9.0 Object Library
/// </summary>
word.applicationclass word = new Word.ApplicationClass();
Type wordType = word.GetType();
Word.Documents docs = word.Documents;
// 打开文件
Type docsType = docs.GetType();
object fileName = "d:\\tmp\\aaa.doc";
Word.Document doc = (Word.Document)docsType.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] {fileName, true, true});
// 转换格式,另存为
Type docType = doc.GetType();
object saveFileName = "d:\\tmp\\aaa.html";
//下面是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);
/// <summary>
/// WordToHtml 的摘要说明。
/// 首先要添加引用:Microsoft Word 9.0 Object Library
/// </summary>
word.applicationclass word = new Word.ApplicationClass();
Type wordType = word.GetType();
Word.Documents docs = word.Documents;
// 打开文件
Type docsType = docs.GetType();
object fileName = "d:\\tmp\\aaa.doc";
Word.Document doc = (Word.Document)docsType.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] {fileName, true, true});
// 转换格式,另存为
Type docType = doc.GetType();
object saveFileName = "d:\\tmp\\aaa.html";
//下面是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);
相关文章推荐
- 把Doc文档转换成HTML等其它格式
- 把Doc文档转换成HTML等其它格式
- Java平台要实现类似豆丁百度文科的文档在线阅读,总体思路是讲doc docx等文件格式利用jcom转换成pdf再用swftools转为swf。再用flexpaper组件显示swf。
- 数据格式转换 (三)Office文档转HTML
- 在线完成DOC等格式文档与PDF文件的相互转换
- 把Doc文档转换成rtf格式
- 把Doc文档转换成rtf格式 (转载)
- Word文档转化为HTML等其它格式
- JAVA:借用OpenOffice将上传的Word文档转换成Html格式
- 如何用C#把Doc文档转换成rtf格式
- DOC 转换给 PDF 格式文档
- 将html转换为chm格式 (主要是将javadoc等文档制作为api.chm)及chm转换html
- Java平台要实现类似豆丁百度文科的文档在线阅读,总体思路是讲doc docx等文件格式利用jcom转换成pdf再用swftools转为swf。再用flexpaper组件显示swf。
- 数据格式转换 (三)Office文档转HTML
- 支持Word文档和其他文件格式间的转换的控件Spire.Doc for .NET
- 数据格式转换 (三)Office文档转HTML
- 如何将eclipse导出的doc文档转换为chm格式
- JAVA:借用OpenOffice将上传的Word文档转换成Html格式
- 记录将文档word2007版本转换为html格式——java代码
- 文档管理系统 之一 doc、xls、ppt文档转换成html及System.Runtime.InteropServices.COMException (0x80004005): 360的问题