C#读取word模版并对指定域写入数据保存为新word

引用:

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);

 

转载于:https://www.cnblogs.com/RedSky/p/4594930.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值