Aspose.words Java基於模板產生word之循環圖表片

來源:互聯網
上載者:User

標籤:模板   調用   pat   system   info   顯示   test   except   math   

1.建立一個word文檔

2.給插入圖片的地方設定書籤

 

 3,設定書籤

二,項目

1,2步的引入依賴以及載入授權檔案同上一篇

3,擷取圖片路徑插入到word中並產生新的word文檔

新文檔中,每行顯示兩張圖片

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);        //圖片路徑        List<String> pathList = new ArrayList<>();        pathList.add("E:\\test\\image1.jpg");        pathList.add("E:\\test\\image2.jpg");        pathList.add("E:\\test\\image3.jpg");        pathList.add("E:\\test\\image4.jpg");        pathList.add("E:\\test\\image5.jpg");        DocumentBuilder builder = new DocumentBuilder(doc);
     //定位到指定位置 builder.moveToBookmark("pics"); double length = pathList.size(); for (int i = 0; i < Math.ceil(length/2.0); i++){ for (int j = 0; j < 2; j++){ int index = i*2 + j; if (index < pathList.size()){ if (i == 0){ if (j == 0){ builder.insertImage(pathList.get(index), RelativeVerticalPosition.MARGIN,1, RelativeHorizontalPosition.MARGIN,130,200,220,WrapType.INLINE); }else { builder.insertImage(pathList.get(index),RelativeVerticalPosition.MARGIN,230,RelativeHorizontalPosition.MARGIN,130,200,220,WrapType.INLINE); } }else { if (j == 0){ builder.insertImage(pathList.get(index),RelativeVerticalPosition.MARGIN,1,RelativeHorizontalPosition.MARGIN,(130+220*i+10*i),200,220,WrapType.INLINE); }else { builder.insertImage(pathList.get(index),RelativeVerticalPosition.MARGIN,230,RelativeHorizontalPosition.MARGIN,(130+220*i+10*i),200,220,WrapType.INLINE); } } } builder.write(" "); } builder.writeln(); } //調用介面 doc.save(destdoc); System.out.println("完成"); }

 

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.