C#将.doc转换为.htm [英] C# convert .doc to .htm

查看:66
本文介绍了C#将.doc转换为.htm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将.doc文件转换为.htm格式,以便在ASP.NET MVC页面中查看.

I am trying to convert .doc file to .htm format to view in an ASP.NET MVC page.

我在C#中使用以下代码:

I am using the following code in C# :

using Microsoft.Office.Core;
using Microsoft.Office.Interop.Word;

....

Microsoft.Office.Interop.Word.Application objWord = new Microsoft.Office.Interop.Word.Application();

            object source = @"C:\Users\XYZ\Desktop\ScreenShot.doc";
            object target = @"C:\Users\XYZ\Desktop\ScreenShot.html";
            object unknown = Type.Missing;
            objWord.Documents.Open(ref source, ref unknown,
                 ref unknown, ref unknown, ref unknown,
                 ref unknown, ref unknown, ref unknown,
                 ref unknown, ref unknown, ref unknown,
                 ref unknown, ref unknown, ref unknown, ref unknown);

            object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatRTF;
            objWord.ActiveDocument.SaveAs(ref target, ref format,
                    ref unknown, ref unknown, ref unknown,
                    ref unknown, ref unknown, ref unknown,
                    ref unknown, ref unknown, ref unknown,
                    ref unknown, ref unknown, ref unknown,
                    ref unknown, ref unknown);

我试图通过Google搜索将.doc(甚至.ppt)转换为.htm格式的方法,并且始终发现与上述代码有些相似的代码.

I have tried to google the way to convert .doc ( even .ppt ) to .htm format and have always found code somewhat similar to the above.

但我不断收到此异常:

由于以下错误,检索具有CLSID {000209FF-0000-0000-C000-000000000046}的组件的COM类工厂失败:80040154未注册类(HRESULT的异常:0x80040154(REGDB_E_CLASSNOTREG)).

Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

在线:

Microsoft.Office.Interop.Word.Application objWord =新的Microsoft.Office.Interop.Word.Application();

Microsoft.Office.Interop.Word.Application objWord = new Microsoft.Office.Interop.Word.Application();

这是由于我安装了Word Starter 2010而不是完整的Office 2010还是有其他解决方案的原因?

Is this due to the reason that I have a Word Starter 2010 installed and not the complete Office 2010, or is there some other solution to it ?

推荐答案

在服务器端使用MS Office中的COM对象不是一个好主意.第一个问题是技术问题-流程存在多个陷阱(例如,有时,在调用Quit()之后excel/word不会退出).这不容易,但是可以解决.

Using COM objects from MS Office on server side is not good idea. The frist problem is technical - there are several pitfalls with processes (i.e. sometimes excel/word does not quit after calling Quit()). It is not easy, but it is solvable.

但是第二个问题是许可.您需要为将要使用MS Office的每个用户提供许可证.因此,如果您想在互联网上使用它,将会遇到严重的财务问题.

However the second problem is licensing. You need license for every user who will be using the MS Office. So, if you want use it on internet web, you will have serious financial issues.

有几个库可以打开(保存,转换等)MS Office格式,而无需安装MS Office.我曾与Aspose 图书馆,但还有其他几个.

There are several libraries which can open (save, convert, etc...) MS Office formats without having MS Office installed. I worked once with Aspose library, but there are several others.

这篇关于C#将.doc转换为.htm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆