将.doc转换为.html [英] convert .doc to .html

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

问题描述

Hello Team,



我正在将.doc转换为.html。当我右键单击.aspx页面并单击在浏览器中查看时,代码工作正常但当我使用链接或网址时,相同的代码不起作用,如http://10.9.39.65:8888



i尝试重新安装Microsoft Office 2003但仍然无法正常使用不同的代码仍然没有成功





我收到以下错误:



System.Runtime.InteropServices.COMException(0x800A1066):Microsoft.Office.Interop.Word.Documents上的命令失败。 Open(Object&FileName,Object&ConfirmConversions,Object&ReadOnly,Object&AddToRecentFiles,Object&PasswordDocument,Object&PasswordTemplate,Object&Revert,Object&WritePasswordDocument,Object&WritePasswordTemplate,Object&Format,Object&Encoding,Object&Visible,Object&OpenAndRepair,Object&DocumentDirection,Object&NoEncodingDialog,Object&XMLTransform) at upload.Button1_Click(Object sender,EventArgs e)在c:\ Inetpub \wwwroot \ PDf到HTML \ upload.aspx.cs:第59行

Hello Team,

I am working on convert .doc to .html. code works perfectly when i right click on the .aspx page and click on "View in browser" but the same code is not working when i use link or url like "http://10.9.39.65:8888"

i tried reinstalling the Microsoft office 2003 but still not working even try with different code still no success


I am getting the below error :

System.Runtime.InteropServices.COMException (0x800A1066): Command failed at Microsoft.Office.Interop.Word.Documents.Open(Object& FileName, Object& ConfirmConversions, Object& ReadOnly, Object& AddToRecentFiles, Object& PasswordDocument, Object& PasswordTemplate, Object& Revert, Object& WritePasswordDocument, Object& WritePasswordTemplate, Object& Format, Object& Encoding, Object& Visible, Object& OpenAndRepair, Object& DocumentDirection, Object& NoEncodingDialog, Object& XMLTransform) at upload.Button1_Click(Object sender, EventArgs e) in c:\Inetpub\wwwroot\Pdf to HTML\upload.aspx.cs:line 59

推荐答案

添加对OpenXmlPowerTools.dll的引用代码:



using OpenXmlPowerTools;

使用DocumentFormat.OpenXml.Wordprocessing;



byte [] byteArray = File.ReadAllBytes(DocxFilePath);

using(MemoryStream memoryStream = new MemoryStream())

{

memoryStream.Write(byteArray,0,byteArray.Length);

使用(WordprocessingDocument doc = WordprocessingDocument.Open(memoryStream,true))

{

HtmlConverterSettings settings = new HtmlConverterSettings()

{

PageTitle =我的页面标题

};

XElement html = HtmlConverter.ConvertToHtml(doc,settings);



File.WriteAllText(HTMLFilePath,html.ToStringNewLineOnAttributes());

}

}
Add reference to OpenXmlPowerTools.dll Code :

using OpenXmlPowerTools;
using DocumentFormat.OpenXml.Wordprocessing;

byte[] byteArray = File.ReadAllBytes(DocxFilePath);
using (MemoryStream memoryStream = new MemoryStream())
{
memoryStream.Write(byteArray, 0, byteArray.Length);
using (WordprocessingDocument doc = WordprocessingDocument.Open(memoryStream, true))
{
HtmlConverterSettings settings = new HtmlConverterSettings()
{
PageTitle = "My Page Title"
};
XElement html = HtmlConverter.ConvertToHtml(doc, settings);

File.WriteAllText(HTMLFilePath, html.ToStringNewLineOnAttributes());
}
}


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

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