Aspose.Words使用模板导出数据库中图片内容
来源:互联网 发布:php yield 编辑:程序博客网 时间:2024/05/22 10:34
做模板
图片字段,前面加上一个Image:
然后看上去就像这样:
合并
代码:其中有一个doc.MailMerge.FieldMergingCallback = new HandleMergeFieldInsertDocument();,是合并的事件,自己定义的
SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "Word97-2003文件(*.doc)|*.doc|Word文件2007版(*.docx)|*.docx"; dialog.RestoreDirectory = true; //点了保存按钮进入 string filename = ""; if (dialog.ShowDialog() == DialogResult.OK) { filename = dialog.FileName; Document doc = new Document(Program.docTemplate); //字段合并时的处理事件 doc.MailMerge.FieldMergingCallback = new HandleMergeFieldInsertDocument(); DataTable dt = (DataTable)dataGridView1.DataSource; dt.TableName = "CardInfo"; doc.MailMerge.ExecuteWithRegions(dt); //执行区域合并,重复区域而不是整个文档 doc.Save(filename, filename.EndsWith("x") ? SaveFormat.Docx : SaveFormat.Doc); if (MessageBox.Show("文件已经保存到:" + filename + "\n\n是否查看?", "保存成功", MessageBoxButtons.YesNo) == DialogResult.Yes) { System.Diagnostics.Process.Start(filename); } }
合并事件
就是一个类
class HandleMergeFieldInsertDocument : IFieldMergingCallback { //文本处理在这里,如果写在这一块,则不起作用 void IFieldMergingCallback.FieldMerging(FieldMergingArgs e) { } //图片处理在这里 void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs args) { if (args.DocumentFieldName.Equals("Pic"))//如果是Pic字段则处理图片 { // 使用DocumentBuilder处理图片的大小 DocumentBuilder builder = new DocumentBuilder(args.Document); builder.MoveToMergeField(args.FieldName); Image img = ImageHelper.ImageFromBytes((byte[])args.FieldValue); img = ImageHelper.ResizeImageToAFixedSize(img, 200, 25, ImageHelper.ScaleMode.MaxHW); Shape shape = builder.InsertImage(img); // 设置x,y坐标和高宽. shape.Left = 0; shape.Top = 0; } } }
阅读全文
0 0
- Aspose.Words使用模板导出数据库中图片内容
- Aspose.Words使用word模板中的书签插入图片(导出含有图片的word)
- Aspose.Words导出带图片人员信息到Word中
- java SSM框架中使用aspose-words导出数据
- 根据word模板导出数据(Aspose.Words)
- 利用Aspose.Words按模板导出Word
- Aspose.Words使用模板导出会出现表格行高变形的情况
- Aspose.Words图片水印
- Aspose.Words把DataTable 中的数据导出到word中
- Aspose.Words导出主从表格
- Aspose.cell 导出到Excell 模板(带图片)
- itextsharp、Aspose.Words、Aspose.Cells联合使用
- Asp.net开发经验-利用Aspose.Words按模板导出Word
- Aspose.Words使用教程大全
- Aspose.Words使用教程大全
- Aspose.Words使用教程大全
- 使用Aspose.BarCode 和 Aspose.Words从Word文档中识别条码
- WinForm使用Aspose.cells利用模板导出Excel
- QT工程打包发布
- Python-小习题-NO.2
- 快速了解友盟统计使用流程
- Segmentation fault (core dumped) --段错误
- ruby计算相差时间(秒)
- Aspose.Words使用模板导出数据库中图片内容
- 基于Quartus II和MATLAB的FIR滤波器设计与仿真(二)
- Intellij Idea免费激活方法
- 男程序员思维VS女程序员思维
- 字符串每四位隔一个空格
- 免费天气API接口,全国天气免费接口,2017年5月测试OK
- linux下安装redis
- Spark Streaming中并行运行任务
- HTML5+CSS3