html格式转换成doc

ganlanfei 2010-10-13 11:16:44
如何将html格式的文件转换成doc文件



PS:直接改后缀是不行的。


我试过将文件保存为doc格式,好像也不行。!
代码如下:
//打开文件
object fileName = @"c:\1.html";
object objMissing = Missing.Value;
object fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;
Microsoft.Office.Interop.Word.Document dc = word.Documents.Open(ref fileName, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref fileFormat, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing);
//另存为,转换格式
object saveFileName = @"C:\new.doc";
fileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatRTF;
dc.SaveAs(ref saveFileName, ref fileFormat, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing, ref objMissing);

//退出。略。
...全文
491 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2010-10-13
  • 打赏
  • 举报
回复
StringWriter wr = new StringWriter();
Server.Execute("", wr);
this.lit.Text = Server.HtmlEncode(wr.ToString());
File.WriteAllText(Server.MapPath(""), wr.ToString());


Response.AppendHeader("Content-Disposition","attachment;filename=result.doc");
Response.ContentType = "application/ms-word";
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
ganlanfei 2010-10-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 holyplace 的回复:]
C# code

HttpWebRequest hr = (HttpWebRequest)HttpWebRequest.Create(@"http://localhost/test/Error1.htm"); //你请求的地址
hr.KeepAlive = false;
HttpWebResponse hr2 = (H……
[/Quote]

最后响应出来是下载文件的,我要的是直接在本地转换好,保存,在界面上没有任何提示的!
ganlanfei 2010-10-13
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 symbol_bc 的回复:]
你是说简单保存html文本还是要把html上面的图片,样式展现在doc中呢
[/Quote]

富文本格式。图片要!
HolyPlace 2010-10-13
  • 打赏
  • 举报
回复

HttpWebRequest hr = (HttpWebRequest)HttpWebRequest.Create(@"http://localhost/test/Error1.htm"); //你请求的地址
hr.KeepAlive = false;
HttpWebResponse hr2 = (HttpWebResponse)hr.GetResponse();
StreamReader sr = new StreamReader(hr2.GetResponseStream(), Encoding.Default);
string str = "";
while (sr.Peek() != -1)
str += sr.ReadLine();
Response.ContentEncoding = System.Text.Encoding.Default;
StringWriter word = new System.IO.StringWriter();
Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.doc"); //保存的文件名
Response.ContentType = "application/vnd.ms-word";
Response.Write(str);
jayjjwillxjw 2010-10-13
  • 打赏
  • 举报
回复
请说清楚点
symbol_bc 2010-10-13
  • 打赏
  • 举报
回复
你是说简单保存html文本还是要把html上面的图片,样式展现在doc中呢

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧