zoukankan      html  css  js  c++  java
  • 导出word文档 通过DocX组件

    根据DocX官方描述如下:

      In the application development process, it uses COM libraries and requires MS Word or Office to be installed when generates the word report.

    In an easy and intuitive manor,DocX is fast, lightweight and best of all it does not require MS Word or Office to be installed.

    And you need to install in order to use DocX is the .NET Framework 4.0, and also reference DocX.dll.

    ------------------------------Source Code-----------------------------------------------------------------------------------------------------------------------------

    Dim tmpPath As String = Server.MapPath("~/template.docx")
    Dim outputPath As String = Server.MapPath("~/Output.docx")
    Dim productID As String = "Product I.D." & vbTab & vbTab & "32925" & vbCr
    Dim productName As String = "Product Name." & vbTab & vbTab & "GESAPRIM GrDA 10KG BAG"

    Dim fieldNames As String() =
    New String() {"<<site>>", "<<sitecontact>>", "<<siteaddress1>>", "<<siteaddress2>>", "<<siteaddress3>>", "<<GenName>>", "<<body>>", "<<crop>>"}
    Dim fieldValues As Object() =
    New Object() {"Syngenta Crop Protection LLC", "Dr. Rene Arenas, Quality Manager", "3905 Highway 75", "River Road, St. Gabriel, Louisiana 70776", "E.U.A", "Terrence Zhang", productID, productName}

    Using document As DocX = DocX.Load(tmpPath)

    For index = 0 To fieldNames.Length - 1 Step +1
    document.ReplaceText(fieldNames(index), fieldValues(index))
    Next

    Dim p As Paragraph = document.InsertParagraph("", False)
    Dim img As Novacode.Image = document.AddImage(AppDomain.CurrentDomain.BaseDirectory & "/Images/Tamara Edwards.PNG")
    Dim pic As Picture = img.CreatePicture()
    p.InsertPicture(pic, 0)
    p.Append(vbCr)
    p.Append("I am bold").FontSize(11).Bold().Append("1").Script(Script.superscript)

    document.SaveAs(outputPath)
    End Using
    Response.Redirect("~/Output.docx")

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------

  • 相关阅读:
    第六章类(十一)构造函数4对象初始化器和集合初始化器
    第六章类(十)构造函数3new
    第六章类(九)构造函数2默认构造函数
    Javascript---- 练习八(字符串操作)
    图解CSS3----white-space空白符处理
    图解CSS3----word-break单词断行
    图解CSS3----word-wrap(单词换行)
    图解CSS3----text-overflow(文本溢出属性)
    图解CSS3----vertical-align(文本垂直对齐方式)
    Javascript---- 练习五(函数,事件绑定)
  • 原文地址:https://www.cnblogs.com/TddCoding/p/5641179.html
Copyright © 2011-2022 走看看