zoukankan      html  css  js  c++  java
  • 【c#搬砖记】用Docx导出word格式的docx文件

    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);
  • 相关阅读:
    div3--C. Pipes
    Problem F Free Weights
    H
    Problem C Careful Ascent
    Problem L. World Cup
    Problem E. Bet
    Problem D. Ice Cream Tower
    A. Number Theory Problem
    A
    软考知识点梳理--项目评估
  • 原文地址:https://www.cnblogs.com/quejuwen/p/csharp_docx.html
Copyright © 2011-2022 走看看