We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

在範本檔中有四個不同位置的書籤,轉換成checkbox時Java程式卻容易出錯

目前的代碼邏輯,是根據書籤的位置,去將範本(共有四組書籤)中的值(ex.1、2、3、4)分別轉換成獨立的4個checkbox,但是到第二組時,程式卻會出現 java.lang.NullPointerException的錯誤訊息,請幫我看一下代碼是哪邊有問題?謝謝!轉換checkbox時容易出錯.7z (61.5 KB)

@lfengh,

您可以使用以下简单的 Java 代码解决此问题:

Document doc = new Document("C:\\Temp\\236004\\Q-4-15-temp.docx");

doc.getMailMerge().execute(
        new String[]{"Checker", "Years", "Months", "Days"},
        new Object[]{"Checker", "Years", "Months", "Days"});

doc.getMailMerge().setFieldMergingCallback(new Q415());

doc.getMailMerge().execute(
        new String[]{"Evaluate1", "Dates1", "Evaluate2", "Dates2", "Evaluate3", "Verify1", "Evaluate4", "Verify2"},
        new Object[]{"Evaluate1", "Dates1", "Evaluate2", "Dates2", "Evaluate3", "Verify1", "Evaluate4", "Verify2"});

doc.save("C:\\temp\\236004\\awjava-21.9.docx");

thanks! it’s works!

1 Like