zoukankan      html  css  js  c++  java
  • C# 使用Aspose.Words在Word模板中的MergeField插入界面控件截图

    在Word模板中添加MergeField,如图:

    后台代码:

     1 var sfd = new SaveFileDialog();
     2 //设置保存的文件的类型,注意过滤器的语法
     3 sfd.Filter = "word文档|*.docx";
     4 //调用ShowDialog()方法显示该对话框,该方法的返回值代表用户是否点击了确定按钮
     5 if (sfd.ShowDialog() != true)
     6      return;
     7 var reporttemp = AppDomain.CurrentDomain.BaseDirectory + "Report\\报告.docx";
     8 //读取doc文档
     9 var doc = new Document(reporttemp);
    10 //获取基础信息
    11 var bmp = new RenderTargetBitmap((int)chart.ActualWidth, (int)chart.ActualHeight, 96d, 96d, PixelFormats.Pbgra32);
    12 //从控件获取Bitmap
    13 bmp.Render(chart);
    14 //Bitmap转换成图片格式
    15 var encoder = new PngBitmapEncoder();
    16 encoder.Frames.Add(BitmapFrame.Create(bmp));
    17 using (var memoryStream = new MemoryStream())
    18  {
    19      //图片转换成内存流
    20     encoder.Save(memoryStream);
    21     //在模板中找到位置
    22     var builder = new DocumentBuilder(doc);
    23     builder.MoveToMergeField("MergeFieldName");//MergeFieldName是word文档中定义的用于替换内容的锚点
    24     //将内存流作为图片插入文档
    25     builder.InsertImage(memoryStream);
    26 }
    27 doc.Save(sfd.FileName);
  • 相关阅读:
    B-Suffix Array
    1 or 2
    Boundary
    Fake Maxpooling
    Cover the Tree
    Omkar and Circle
    20.5.31
    Yet Another Yet Another Task
    Codeforces Round #373 (Div. 2)E. Sasha and Array +线段树+矩阵快速幂
    2018 Multi-University Training Contest 2(Naive Operations ) hdu6315
  • 原文地址:https://www.cnblogs.com/lionwang/p/15620678.html
Copyright © 2011-2022 走看看