C#读取word模版并对指定域写入数据保存为新word
2015-06-23 10:57
603 查看
引用:
获取模版路径:
将数据放在list<string>中:
将list转换为string数组,使用Document.MailMerge.Excute(string1,string2)方法;string1是域,string2是数据
保存到某个文件夹下新建newdoc.doc文档:
using System; using System.Collections.Generic; using System.Aspose.Words; using System.Windows.Forms;
获取模版路径:
string = "路径"; //如:string = "e:\\word\\word1.doc" Document dm = new Document();
将数据放在list<string>中:
List<string> list1 = new List<string>; //保存的是域 List<string> list2 = new List<string>; //保存的是要插入的数据 list1.Add("Name"); list2.Add("messege"); //在域名为Name的位置给值messege
将list转换为string数组,使用Document.MailMerge.Excute(string1,string2)方法;string1是域,string2是数据
string[] s1 = list1.ToArry(); string[] s2 = list2.ToArry(); dm.MailMerge.Excute(s1,s2); //给域赋值
保存到某个文件夹下新建newdoc.doc文档:
string savePath = @"e:\word\newdoc.doc"; SaveFileDialog sfd = new SaveFileDialog(); sfd.FileName = "newdoc.doc"; sfd.InitialDirectory = @"e:\word"; sfd.Filter = "Word 文档(*.doc)|*.doc"; sfd.show(); dd.Save(sfd.FileName);
相关文章推荐
- 算法练习-- C# DFS 全排列算法
- C#调用摄像头的几种方式
- c#自带的数学运算函数
- C#调用WPS的两种方式
- [翻译]利用C#获取终端服务(Terminal Services)会话的闲置时间
- C#生成PDF总结
- C#TextBox自动提示、自动补全、自动完成功能
- C#中缓存的基本用法总结
- 编写更好的C#代码
- C#发送邮件代码
- C# 发送邮件源码
- C# 3DES加密解密,差点要了命
- 运行一个简单的C#程序
- [转载]C#时间函数
- C#中ini文件操作
- 一个简单方法完成C#时间间隔的计算
- C#获取根目录的方法集合
- C#实现任意大数的计算和简单逻辑命题的证明——前言
- 学习笔记《C#入门经典(第6版)》C#语言:第6章
- 【温故知新】c#抽象类abstract与接口interface