Aspose.words Java基於模板產生word之純文字內容

來源:互聯網
上載者:User

標籤:color   catch   template   電動   驗證   temp   文檔   定義   nbsp   

一,建立word模板

1.建立一個word文檔

2.分別給四個參數設定域

(1)將滑鼠置於想要設定域的地方

(2)設定網域名稱

(3)設定好之後如所示

二,項目

1,引入maven依賴

<dependency>            <groupId>com.aspose</groupId>            <artifactId>aspose-words</artifactId>            <version>18.5</version>            <classifier>jdk16</classifier>        </dependency>

2,載入授權檔案

public static boolean getLicense() {        boolean result = false;        try {            InputStream is = AsposeToWordTest.class.getClassLoader().getResourceAsStream("license-word.xml");            License aposeLic = new License();            aposeLic.setLicense(is);            result = true;        } catch (Exception e) {            e.printStackTrace();        }        return result;    }

3,擷取值以及插入到模板中並產生新的文檔

public static void main(String[] args) throws Exception {        // 驗證License        if (!getLicense()) {            return;        }        //模板word        String template = "E:\\test\\temp.docx";        //目標word        String destdoc = "E:\\test\\edit.docx";        //定義文檔介面        Document doc = new Document(template);        //文本域        String[] Flds = new String[]{"caseIssue","policeName", "caseName", "caseTime"};        String caseIssue = "001";        String policeName = "XX派出所";        String caseName = "0727電動車盜竊案";        String caseTime = "2018-07-26 12:20:22";        //值        Object[] Vals = new Object[]{caseIssue,policeName, caseName, caseTime};        //調用介面        doc.getMailMerge().execute(Flds, Vals);        doc.save(destdoc);        System.out.println("完成");    }

4,結果

其中設定域的圖片引用於http://www.xiaoguo123.com/p/aspose_words_java_template/

 

Aspose.words Java基於模板產生word之純文字內容

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.