1个回答
展开全部
测试成功,分享给你
先添加COM引用:
Microsoft Word 12.0 Object Library
示例代码
using System;
using System.Collections.Generic;
using System.Text;
using MSWord = Microsoft.Office.Interop.Word;
using System.IO;
using System.Reflection;
namespace WordProcesser
{
class Program
{
static void Main(string[] args)
{
MSWord.Application wordApp;
MSWord.Document wordDoc;
Object Nothing = Missing.Value;
Console.WriteLine("Input path:");
Object path = Console.ReadLine();
path = @"E:\mobile.docx";
wordApp = new MSWord.ApplicationClass();
wordDoc = wordApp.Documents.Add(ref path, ref Nothing, ref Nothing, ref Nothing);
object format = MSWord.WdSaveFormat.wdFormatFilteredHTML;
Object newPath = @"E:\mobile.html";
wordDoc.SaveAs(ref newPath, ref format, ref Nothing, ref Nothing, ref Nothing,
ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
Console.WriteLine("Created!");
}
}
}
这里实现了把word转成html的功能,要显示的话直接调用浏览器或者写个winform里面加个webbrowser控件来显示网页页面。
先添加COM引用:
Microsoft Word 12.0 Object Library
示例代码
using System;
using System.Collections.Generic;
using System.Text;
using MSWord = Microsoft.Office.Interop.Word;
using System.IO;
using System.Reflection;
namespace WordProcesser
{
class Program
{
static void Main(string[] args)
{
MSWord.Application wordApp;
MSWord.Document wordDoc;
Object Nothing = Missing.Value;
Console.WriteLine("Input path:");
Object path = Console.ReadLine();
path = @"E:\mobile.docx";
wordApp = new MSWord.ApplicationClass();
wordDoc = wordApp.Documents.Add(ref path, ref Nothing, ref Nothing, ref Nothing);
object format = MSWord.WdSaveFormat.wdFormatFilteredHTML;
Object newPath = @"E:\mobile.html";
wordDoc.SaveAs(ref newPath, ref format, ref Nothing, ref Nothing, ref Nothing,
ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
Console.WriteLine("Created!");
}
}
}
这里实现了把word转成html的功能,要显示的话直接调用浏览器或者写个winform里面加个webbrowser控件来显示网页页面。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询