62,243
社区成员




StringBuilder sb = new StringBuilder();
sb.AppendLine("<html xmlns:v=\"urn:schemas-microsoft-com:vml\"");
sb.AppendLine("xmlns:o=\"urn:schemas-microsoft-com:office:office\"");
sb.AppendLine("xmlns:w=\"urn:schemas-microsoft-com:office:word\"");
sb.AppendLine("xmlns:m=\"http://schemas.microsoft.com/office/2004/12/omml\"");//ns0
sb.AppendLine("xmlns=\"http://www.w3.org/TR/REC-html40\">");
// html代码
sb.AppendLine("<head>");
sb.AppendLine("<meta http-equiv=Content-Type content=\"text/html; charset=utf-8\">");
sb.AppendLine("<meta name=ProgId content=Word.Document>");
sb.AppendLine("<meta name=Generator content=\"Microsoft Word 11\">");
sb.AppendLine("<meta name=Originator content=\"Microsoft Word 11\">");
sb.AppendLine("<title></title>");
sb.AppendLine("<!--[if !mso]>");
sb.AppendLine("<style>");
sb.AppendLine("v\\:* {behavior:url(#default#VML);}");
sb.AppendLine("o\\:* {behavior:url(#default#VML);}");
sb.AppendLine("w\\:* {behavior:url(#default#VML);}");
sb.AppendLine(".shape {behavior:url(#default#VML);}");
sb.AppendLine("</style type=\"text/css\">");
sb.AppendLine("<![endif]-->");
//使导出的word以页面模式显示
sb.AppendLine("<!--[if gte mso 9]><xml>");
sb.AppendLine(" <w:WordDocument>");
sb.AppendLine(" <w:View>Print</w:View>");
sb.AppendLine(" <w:SpellingState>Clean</w:SpellingState>");
sb.AppendLine(" <w:GrammarState>Clean</w:GrammarState>");
sb.AppendLine(" <w:ValidateAgainstSchemas/>");
sb.AppendLine(" <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>");
sb.AppendLine(" <w:IgnoreMixedContent>false</w:IgnoreMixedContent>");
sb.AppendLine(" <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>");
sb.AppendLine(" <w:Compatibility>");
sb.AppendLine(" <w:UseFELayout/>");
sb.AppendLine(" </w:Compatibility>");
sb.AppendLine(" <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>");
sb.AppendLine(" </w:WordDocument>");
sb.AppendLine("</xml>");
sb.AppendLine("<![endif]-->");
sb.AppendLine("<!--[if gte mso 9]>");
sb.AppendLine("<xml>");
sb.AppendLine(" <w:LatentStyles DefLockedState=\"false\" LatentStyleCount=\"156\">");
sb.AppendLine(" </w:LatentStyles>");
sb.AppendLine("</xml>");
sb.AppendLine("<![endif]-->");
//样式
sb.AppendLine("<style type=\"text/css\">");
sb.AppendLine(" html, body{font-size: 12px;padding: 0;margin: 0;border: 0;height: 100%;}");
//sb.AppendLine(" .showtable {border-left:1px #000000 solid;border-top:1px #000000 solid;}");
//sb.AppendLine(" .showtable td{border-right:1px #000000 solid;border-bottom:1px #000000 solid;}");
sb.AppendLine(" .showtable,.showtable td,.showtable th{border:1px solid #000000;border-collapse:collapse;}");
sb.AppendLine(" .showtable tr{height:19px;}");
sb.AppendLine(" .showtable tb{border:1px solid #000000;border-collapse:collapse;font-size: 14px;}");
sb.AppendLine(" .showtable2,.showtable2 td,.showtable2 th{border:1px solid #000000;border-collapse:collapse;}");
sb.AppendLine(" .showtable2 tr{height:22px;}");
sb.AppendLine(" .showtable2 tb{border:1px solid #000000;border-collapse:collapse;font-size: 17px;}");
sb.AppendLine(" td{text-align:left;}");
//WORD页面设置
sb.AppendLine(" @page Section1");
sb.AppendLine(" {size:595.3pt 841.9pt;");
sb.AppendLine(" margin:72.0pt 70.9pt 72.0pt 70.9pt;");
sb.AppendLine(" mso-header-margin:42.55pt;");
sb.AppendLine(" mso-footer-margin:49.6pt;");
sb.AppendLine(" mso-paper-source:0;}");
sb.AppendLine(" div.Section1");
sb.AppendLine(" {page:Section1;}");
sb.AppendLine("</style>");
sb.AppendLine("<!--[if gte mso 9]>");
sb.AppendLine("<xml>");
sb.AppendLine(" <o:shapedefaults v:ext=\"edit\" spidmax=\"2050\"/>");
sb.AppendLine("</xml>");
sb.AppendLine("<![endif]-->");
sb.AppendLine("<!--[if gte mso 9]>");
sb.AppendLine("<xml>");
sb.AppendLine(" <o:shapelayout v:ext=\"edit\">");
sb.AppendLine(" <o:idmap v:ext=\"edit\" data=\"1\"/>");
sb.AppendLine(" </o:shapelayout>");
sb.AppendLine("</xml>");
sb.AppendLine("<![endif]-->");
sb.AppendLine("</head>");
//文档内容开始
sb.AppendLine("<body lang=ZH-CN style='tab-interval:21.0pt'>");
sb.AppendLine("<div class=Section1>"); //页面设置样式
sb.AppendLine(htmltext);
sb.AppendLine("</div>");
sb.AppendLine("</body>");
sb.AppendLine("</html>");
Encoding encoding = Encoding.GetEncoding("utf-8");//
StreamWriter sw = null;
string path = "/uploads/swfupload/" + fileName + ".doc";
string OutPutPath = HttpContext.Current.Server.MapPath(path);
if (System.IO.File.Exists(OutPutPath))
{
System.IO.File.Delete(OutPutPath);
}
sw = new StreamWriter(OutPutPath, false, encoding);
sw.Write(sb);
sw.Flush();
sw.Close();