如何使用DOCX.JS设置列大小

时间:2019-12-15 02:50:36

标签: javascript reactjs ms-word electron docx

我正在使用电子创建一个应用程序并进行反应,我将需要动态创建Word文本文档,我找到了一个很好的包DOCX,但是我需要创建一些表,而且我无法设置其大小在列中,我需要帮助来设置列的大小,并遵循代码摘录和文档链接https://docx.js.org/#/

    2019-12-15 11:37:59.005 22791-22791/org.techtown.worddbpractice E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.techtown.worddbpractice, PID: 22791
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.techtown.worddbpractice/org.techtown.worddbpractice.WordActivity}: java.lang.NullPointerException: Attempt to read from field 'java.lang.String org.techtown.worddbpractice.WordDBRecord.category' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2849)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
        at android.app.ActivityThread.-wrap14(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6776)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
     Caused by: java.lang.NullPointerException: Attempt to read from field 'java.lang.String org.techtown.worddbpractice.WordDBRecord.category' on a null object reference
        at org.techtown.worddbpractice.WordActivity.<init>(WordActivity.java:17)
        at java.lang.Class.newInstance(Native Method)
        at android.app.Instrumentation.newActivity(Instrumentation.java:1086)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2839)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045) 
        at android.app.ActivityThread.-wrap14(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6776) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386) 

1 个答案:

答案 0 :(得分:1)

您可能已经解决了。但是对于寻找答案的其他人,这是我所做的:

检查ITableCellOptions.width.WidthType以获得更多选项

const columnTitles = ["Title1", "Title2", "Title3"];

const columnTitleRow = new TableRow({
  children: columnTitles.map((title) => {
    return new TableCell({
      // Make all cells the same with over 100% of the available page width
      width: { size: 100 / columnTitles.length, type: WidthType.PERCENTAGE },
      children: [new Paragraph({ text: title })],
    });
  }),
});