zoukankan      html  css  js  c++  java
  • word模板导出的几种方式:第三种:标签替换(DocX组件读取与写入Word)

    dll文件下载地址:https://files-cdn.cnblogs.com/files/daizhipeng/DocX.rar

    DocX wordDocumentOld = DocX.Load(System.Web.HttpContext.Current.Request.MapPath(templateName));//加载已有的word模板
    DocX wordDocument = wordDocumentOld;  //复制加载的word模板,以免污染原始模板
    //标签替代
    wordDocument.InsertAtBookmark(info.Name, "Name");//向模板中的书签Name中写入数据

    //加入图片,插入到表格中
    try
    {
    Novacode.Image pImag = wordDocument.AddImage(System.Web.HttpContext.Current.Request.MapPath(info.zdImg));
    Picture SourceImage = ChangeSize(pImag.CreatePicture(), 120, 140);
    //表格位置插入
    Table wordTable = wordDocument.Tables[0];//获取模板中的第一个表格
    Paragraph paragraph = wordTable.Rows[3].Cells[3].Paragraphs[0].InsertPicture(SourceImage);
    }
    catch(Exception ex){}
    //签名
    var bookMark = get_BookMarkByName(wordDocument, "AutographImg");
    Novacode.Image qmImag = wordDocument.AddImage(System.Web.HttpContext.Current.Request.MapPath(info.AutographImg));
    Picture AutographImg = ChangeSize(qmImag.CreatePicture(), 180, 40);
    bookMark.Paragraph.InsertPicture(AutographImg);
    //申请日期
    wordDocument.InsertAtBookmark(DateTime.Now.ToString("yyyy年MM月dd日"), "ApplyTime");
    wordDocument.SaveAs(System.Web.HttpContext.Current.Request.MapPath(savePath));     //将写好的word另存到指定路径    
    Path = savePath;

  • 相关阅读:
    JAVA——俄罗斯方块
    JAVA——简单科学计算器设计
    标准9*9数独破解器
    k短路算法(A*)
    洛谷2939 分层图模板
    PCA算法
    coursera-斯坦福-机器学习-吴恩达-笔记week4
    coursera-斯坦福-机器学习-吴恩达-笔记week3
    coursera-斯坦福-机器学习-吴恩达-笔记week2
    coursera-斯坦福-机器学习-吴恩达-笔记week1
  • 原文地址:https://www.cnblogs.com/daizhipeng/p/10685195.html
Copyright © 2011-2022 走看看