using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Word;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//Word 转 Html
//前提:请先引用 Microsoft.Office.Interop.Word
Microsoft.Office.Interop.Word.ApplicationClass w_app = new Microsoft.Office.Interop.Word.ApplicationClass();
Type wordType = w_app.GetType();
Microsoft.Office.Interop.Word.Documents w_docs = w_app.Documents;
Type docsType = w_docs.GetType();
object p_file_nm = @"d:\abcd.docx"; //请在d分区下先新建好这个文件
object saveFileName = @"d:\abcd.html";
Microsoft.Office.Interop.Word.Document w_doc = (Microsoft.Office.Interop.Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, w_docs, new Object[] { p_file_nm, true, true }); new UnknownWrapper(null);
Type docType = w_doc.GetType();
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, w_doc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML });
wordType.InvokeMember("Quit",
System.Reflection.BindingFlags.InvokeMethod,
null,
w_app,
null
);
}
}
}
Word转Html ( Microsoft.Office.Interop.Word )
最新推荐文章于 2024-07-17 18:00:00 发布