在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
private void ExportDataToWord(string content) { StringBuilder sbMain = new StringBuilder(); #region 头部分 sbMain.Append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"); sbMain.Append("<?mso-application progid=\"Word.Document\"?>"); sbMain.Append("<w:wordDocument xmlns:aml=\"http://schemas.microsoft.com/aml/2001/core\" xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:dt=\"uuid:C2F41010-65B3-11d1-A29F-00AA00C14882\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.microsoft.com/office/word/2003/wordml\" xmlns:wx=\"http://schemas.microsoft.com/office/word/2003/auxHint\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wsp=\"http://schemas.microsoft.com/office/word/2003/wordml/sp2\" xmlns:sl=\"http://schemas.microsoft.com/schemaLibrary/2003/core\" w:macrosPresent=\"no\" w:embeddedObjPresent=\"no\" w:ocxPresent=\"no\" xml:space=\"preserve\">"); sbMain.Append(" <w:ignoreSubtree w:val=\"http://schemas.microsoft.com/office/word/2003/wordml/sp2\"/>"); sbMain.Append(" <o:DocumentProperties>"); sbMain.Append(" </o:DocumentProperties>"); sbMain.Append(" <w:fonts>"); sbMain.Append(" <w:defaultFonts w:ascii=\"Calibri\" w:fareast=\"宋体\" w:h-ansi=\"Calibri\" w:cs=\"Times New Roman\"/>"); sbMain.Append(" </w:fonts>"); sbMain.Append(" <w:styles></w:styles>"); sbMain.Append(" <w:shapeDefaults>"); sbMain.Append(" <o:shapedefaults v:ext=\"edit\" spidmax=\"1026\"/>"); sbMain.Append(" <o:shapelayout v:ext=\"edit\">"); sbMain.Append(" <o:idmap v:ext=\"edit\" data=\"1\"/>"); sbMain.Append(" </o:shapelayout>"); sbMain.Append(" </w:shapeDefaults>"); sbMain.Append(" <w:docPr></w:docPr>"); sbMain.Append(" <w:body>"); #endregion #region 生成文件流 string width = content.Split('|')[1]; string height =content.Split('|')[2]; string DATA = content.Split('|')[0]; string left=content.Split('|')[3]; string top = content.Split('|')[4]; string path = SAVEPLOT("jpg", DATA, width, height,left,top); Image img = Image.FromFile(@""+path+""); MemoryStream ms = new MemoryStream(); img.Save(ms, ImageFormat.Jpeg); byte[] b = ms.ToArray(); string sss = System.Convert.ToBase64String(b); ms.Close(); sbMain.Append(@"<w:binData w:name='wordml://03000001.png' xml:space='preserve'>" + sss + "</w:binData>"); #endregion #region 图片初始化 sbMain.Append(@"<w:pict><v:shape id='图片 1' o:spid='_x0000_i1025' type='#_x0000_t75' style='width:" + img.Width + @"px;height:" + img.Height + @"px; visibility:visible;mso-wrap-style:square'> <v:imagedata src='wordml://03000001.png' o:title='2012-9-26'/> </v:shape> </w:pict>"); #endregion #region 尾部分 sbMain.Append(" </w:body>"); sbMain.Append(" </w:wordDocument>"); #endregion Response.AddHeader("Content-Disposition", "attachment; filename=VMLChart" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".doc"); Response.Charset = "UTF-8"; Response.Write(Encoding.Default.GetString(Encoding.Default.GetBytes(sbMain.ToString()))); }
|
请发表评论