首页 > 学院 > 开发设计 > 正文

【c#搬砖记】用Docx导出word格式的docx文件

2019-11-14 16:16:31
字体:
来源:转载
供稿:网友

DocX开源网址:http://docx.codeplex.com/

1、引入DocX.dll 调用ReplaceText()方法替换模板中的字符。只支持docx格式的Word文档

using (DocX docx = DocX.Load(fileDemo))            {                docx.ReplaceText("@某某某", tester.name);                docx.ReplaceText("@110101198101010001", tester.IdCode);                docx.SaveAs(fileSave);            }

 

2、插入图片形状。

引入 aspose.Words 组件

            Document doc = new Document(fileSave);            DocumentBuilder builder = new DocumentBuilder(doc);            Shape shape = new Shape(doc, ShapeType.Rectangle);            //shape.ImageData.SetImage(fileImage);            shape.Width = width;            shape.Height = height;            shape.FillColor = Color.Red;            //shape.HorizontalAlignment = HorizontalAlignment.Left; //靠右对齐            builder.MoveToBookmark(bookmark);            builder.InsertNode(shape);            //Bookmark myname = doc.Range.Bookmarks["myname"];            //myname.Text = "";            //doc.Range.Bookmarks["myname"].Remove();            doc.Save(fileSave, SaveFormat.Docx);

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表