首页 > Windows开发 > 详细

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

时间:2015-06-23 11:26:45      阅读:432      评论:0      收藏:0      [点我收藏+]

引用:

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#读取word模版并对指定域写入数据保存为新word

原文:http://www.cnblogs.com/RedSky/p/4594930.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!