- .doc 未正确创建。使用完整的 html 标签而不是文字创建
像下面的 ms word 文档中的数据
<div id="ctl00_ContentPlaceHolder1_design" style="width:600px">
<table id="ctl00_ContentPlaceHolder1_rpt" border="0" width="600">
如何将 html 标签转换为纯内容?
aspx.cs
protected void btnMail_Click(object sender, EventArgs e)
{
Response.Clear();
try
{
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
design.RenderControl(htmlWrite);
string strBuilder = stringWrite.ToString();
string strPath = Request.PhysicalApplicationPath + "\\Temp\\WeeklyReport of " + Projname + ".doc";
if (File.Exists(strPath))
{
var counter = 1;
strPath = strPath.Replace(".doc", " (" + counter + ").doc");
while (File.Exists(strPath))
{
strPath = strPath.Replace("(" + counter + ").doc", "(" + (counter + 1) + ").doc");
counter++;
}
}
var doc = DocX.Create(strPath,DocumentTypes.Document);
doc.InsertParagraph(strBuilder);
doc.Save();
}
}