Aspose Word常用操作
使用Aspose Word操作模版
刚好最近学到Aspose Word,有些心得,记录下来。下面的知识主要是如何使用Asopse Word,根据word模版插入数据,生成Word。
创建Document对象
Document doc = new Document(path);
Document有几个构造器,可以传Stream,路径,以及一些参数,可以看一下提示。
常用方法
下面是一些模版操作是,常用到的方法,如果你的版本没有这个方法,又或者参数不对,问题不大,主要是版本不对,按照你当前的版本修改一下就可以用了。
//根据NodeType返回同类型的元素,特别是在替换字符,搜索字符串的时候,需要用到。
Document.GetChildNodes(NodeType)
//获取Cell字符串
Cell cell = table.Rows[0].Cell[0];
cell.ToString(SaveFormat.Text)
//获取Paragraph的字符串
Paragraph paragraph = node as Paragraph;
var paragraphTxt = paragraph.ToString(SaveFormat.Text);
//这个是替换字符串的方法
`Document.Range.Replace(oldStr,newStr)`
//书签操作,bmName是书签名
Document doc = new Document(path);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToBookmark(bmName);
//根据书签写入字符串
builder.Write(val);
//根据书签写入电子签章,InsertImage三个参数,图片路径,宽度,高度
var qianzhangPath= "C:/img/img.png";
builder.InsertImage(qianzhangPath, 105, 28);