我正在用c#编写一个ASP.NET应用程序,并且正在尝试将一个表写入word文档。
我目前使用以下代码来写入word文档:
string strContent = "This content goes to the word document";
string attach = "attachment; filename=wordtest.doc";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/msword";
HttpContext.Current.Response.AddHeader("content-disposition", attach);
HttpContext.Current.Response.Write(strContent);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();现在,我的问题是,是否有人知道如何将表写入word文档?
第二个问题是,是否有人知道如何在word文档中编写复选框(就像你从网站上复制并粘贴到word中一样)
提前感谢!
杀人狂
发布于 2011-03-19 17:05:43
Word可以识别HTML。因此您可以使用Response.Write();方法简单地将任何超文本标记语言写入MS WORD。以下是代码示例。
string strBody = "<html>" +
"<body>" +
"<div>Your name is: <b>" + txtName.Text + "</b></div>" +
"<table width="100%" style="background-color:#cfcfcf;"><tr><td>1st Cell body data</td><td>2nd cell body data</td></tr></table>" +
"Ms Word document generated successfully." +
"</body>" +
"</html>";
string fileName = "MsWordSample.doc";
// You can add whatever you want to add as the HTML and it will be generated as Ms Word docs
Response.AppendHeader("Content-Type", "application/msword");
Response.AppendHeader ("Content-disposition", "attachment; filename="+ fileName);
Response.Write(strBody);https://stackoverflow.com/questions/5360761
复制相似问题