首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >【c#搬砖记】用Docx导出word格式的docx文件

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

作者头像
阿炬
发布于 2018-05-11 14:31:25
发布于 2018-05-11 14:31:25
2.2K0
举报
文章被收录于专栏:阿炬.NET阿炬.NET

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

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

代码语言:javascript
复制
using (DocX docx = DocX.Load(fileDemo))
            {
                docx.ReplaceText("@某某某", tester.name);
                docx.ReplaceText("@110101198101010001", tester.IdCode);

                docx.SaveAs(fileSave);

            }

2、插入图片形状。

引入 Aspose.Words 组件

代码语言:javascript
复制
            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);
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2014-12-28 ,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档