");sbMain.Append("");s" />

C# 导出图片到Word (通过XML实现)

系统 1424 0
       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())));

    }


    

C# 导出图片到Word (通过XML实现)


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论