我正在尝试将 HTML 页面内容导出到 Word。
我的Html显示页面是:
- 你最喜欢的颜色是什么?
NA
- 列出前三名的学校?
一名国家级
两个开发人员
三个PS
以及一个用于点击事件的按钮。按钮单击事件将打开 MS Word 并将页面内容粘贴到 Word 中。
word页面包含html设计页面的table属性。它仅出现在Word 2003中。但在Word 2007中,Word文档包含不具有表格属性的文本。如何在word 2003中删除该表属性?
我无法添加快照。不然我就让你说清楚。
我正在用aspx设计网页。我通过以下代码导出网页内容。
protected void Button1_Click(object sender, EventArgs e)
{
Response.ContentEncoding = System.Text.Encoding.UTF7;
System.Text.StringBuilder SB = new System.Text.StringBuilder();
System.IO.StringWriter SW = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlTW = new System.Web.UI.HtmlTextWriter(SW);
tbl.RenderControl(htmlTW);
string strBody = "<html>" +
"<body>" + "<div><b>" + htmlTW.InnerWriter.ToString() + "</b></div>" +
"</body>" +
"</html>";
Response.AppendHeader("Content-Type", "application/msword");
Response.AppendHeader("Content-disposition", "attachment; filename=" + fileName);
Response.ContentEncoding = System.Text.Encoding.UTF7;
string fileName1 = "C://Temp/Excel" + DateTime.Now.Millisecond.ToString();
BinaryWriter writer = new BinaryWriter(File.Open(fileName1, FileMode.Create));
writer.Write(strBody);
writer.Close();
FileStream fs = new FileStream(fileName1, FileMode.Open, FileAccess.Read);
byte[] renderedBytes;
// Create a byte array of file stream length
renderedBytes = new byte[fs.Length];
//Read block of bytes from stream into the byte array
fs.Read(renderedBytes, 0, System.Convert.ToInt32(fs.Length));
//Close the File Stream
fs.Close();
FileInfo TheFile = new FileInfo(fileName1);
if (TheFile.Exists)
{
File.Delete(fileName1);
}
Response.BinaryWrite(renderedBytes);
Response.Flush();
Response.End();
}
您正在编写 HTML,声称它的内容类型为“application/msword”,然后希望得到最好的结果。
有更多“正确”的方法来实现你的目标。
有一些项目可以将 (X)HTML 转换为 WordML 内容,其中docx4j-ImportXHTML.NET https://www.nuget.org/packages/docx4j-ImportXHTML.NET/是一。披露:我坚持认为;您可以在 StackOverflow 上的其他地方找到其他人的链接。
或者,您可以使用 Word 的 altChunk 机制,但请注意:
- 您对如何执行导入的控制较少;
- Word 2003 不支持 AltChunk(即使有兼容包)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)