C#请问如何将word转化为HTML,不适用office组件

 我来答
育知同创教育
2016-02-09 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
展开全部
protected void Upload(object sender, EventArgs e)
{
object missingType = Type.Missing;
object readOnly = true;
object isVisible = false;
object documentFormat = 8;
string randomName = DateTime.Now.Ticks.ToString();
object htmlFilePath = Server.MapPath("~/Temp/") + randomName + ".htm";
string directoryPath = Server.MapPath("~/Temp/") + randomName + "_files";

//Upload the word document and save to Temp folder
FileUpload1.SaveAs(Server.MapPath("~/Temp/") + Path.GetFileName(FileUpload1.PostedFile.FileName));
object fileName = FileUpload1.PostedFile.FileName;

//Open the word document in background
ApplicationClass applicationclass = new ApplicationClass();
applicationclass.Documents.Open(ref fileName,
ref readOnly,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref isVisible,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType);
applicationclass.Visible = false;
Document document = applicationclass.ActiveDocument;

//Save the word document as HTML file
document.SaveAs(ref htmlFilePath, ref documentFormat, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType);

//Close the word document
document.Close(ref missingType, ref missingType, ref missingType);

//Delete the Uploaded Word File
File.Delete(Server.MapPath("~/Temp/") + Path.GetFileName(FileUpload1.PostedFile.FileName));

//Read the Html File as Byte Array and Display it on browser
byte[] bytes;
using (FileStream fs = new FileStream(htmlFilePath.ToString(), FileMode.Open, FileAccess.Read))
{
BinaryReader reader = new BinaryReader(fs);
bytes = reader.ReadBytes((int)fs.Length);
fs.Close();
}
Response.BinaryWrite(bytes);
Response.Flush();

//Delete the Html File
File.Delete(htmlFilePath.ToString());
foreach (string file in Directory.GetFiles(directoryPath))
{
File.Delete(file);
}
Directory.Delete(directoryPath);
Response.End();
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
a六公子
2016-02-09 · TA获得超过1952个赞
知道小有建树答主
回答量:852
采纳率:33%
帮助的人:247万
展开全部
用NPOI , 开源的
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式