docx icon indicating copy to clipboard operation
docx copied to clipboard

Lists numbers not rendered in online word

Open tripodsan opened this issue 4 years ago • 5 comments

I have simple doc, that looks find in word, but misses the list numbers in online word.

word:

image

online word:

image

note that the indents are correct, i.e. the ones I set in the numbering config.

tripodsan avatar Apr 03 '21 05:04 tripodsan

when I reapply the numbering to the paragraphs and save, then I see the following diff:

--- ori/word/numbering.xml	2021-04-03 13:39:42.000000000 +0900
+++ new/word/numbering.xml	2021-04-03 13:39:42.000000000 +0900
@@ -1,3 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
 <w:numbering xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
              xmlns:o="urn:schemas-microsoft-com:office:office"
@@ -103,7 +104,9 @@
         <w:multiLevelType w:val="hybridMultilevel"/>
         <w:lvl w:ilvl="0" w15:tentative="1">
             <w:start w:val="1"/>
-            <w:lvlJc w:val="start"/>
+            <w:numFmt w:val="decimal"/>
+            <w:lvlText w:val="%1."/>
+            <w:lvlJc w:val="left"/>
             <w:numFmt w:val="decimal"/>
             <w:lvlText w:val="%1."/>
             <w:pPr>
@@ -112,7 +115,9 @@
         </w:lvl>
         <w:lvl w:ilvl="1" w15:tentative="1">
             <w:start w:val="1"/>
-            <w:lvlJc w:val="start"/>
+            <w:numFmt w:val="lowerLetter"/>
+            <w:lvlText w:val="%2."/>
+            <w:lvlJc w:val="left"/>
             <w:numFmt w:val="lowerLetter"/>
             <w:lvlText w:val="%2"/>
             <w:pPr>
@@ -221,20 +226,14 @@
     </w:num>
     <w:num w:numId="3">
         <w:abstractNumId w:val="1"/>
-        <w:lvlOverride w:ilvl="0">
-            <w:startOverride w:val="1"/>
-        </w:lvlOverride>
+        <w:lvlOverride w:ilvl="0"/>
     </w:num>
     <w:num w:numId="4">
         <w:abstractNumId w:val="1"/>
-        <w:lvlOverride w:ilvl="0">
-            <w:startOverride w:val="1"/>
-        </w:lvlOverride>
+        <w:lvlOverride w:ilvl="0"/>
     </w:num>
     <w:num w:numId="5">
         <w:abstractNumId w:val="1"/>
-        <w:lvlOverride w:ilvl="0">
-            <w:startOverride w:val="1"/>
-        </w:lvlOverride>
+        <w:lvlOverride w:ilvl="0"/>
     </w:num>
 </w:numbering>

It somehow added the lvlText attribute twice!

tripodsan avatar Apr 03 '21 05:04 tripodsan

indeed, when I rearrange the order of the attributes, it works!

            <w:numFmt w:val="decimal"/>
            <w:lvlText w:val="%1."/>
            <w:lvlJc w:val="start"/>

tripodsan avatar Apr 03 '21 05:04 tripodsan

I patched https://github.com/dolanmiu/docx/blob/0788b1010637f00534b342f9ff8f774f7b2c4d8e/src/file/numbering/level.ts#L121-L132 and moved the LevelJc to the end, and now it works! (unbelievable)

        this.root.push(new Start(start));
        if (format) {
            this.root.push(new NumberFormat(format));
        }
        if (text) {
            this.root.push(new LevelText(text));
        }
        this.root.push(new LevelJc(alignment));

tripodsan avatar Apr 03 '21 05:04 tripodsan

Very interesting that the ordering matters, will make a fix soon

dolanmiu avatar Apr 03 '21 21:04 dolanmiu

I have the same issue. Not on online word, but on office 2007, the list numbers are not rendered. I extracted the generated docx file, in numbering.xml i replaced 'hybridMultilevel' with 'multilevel' and zip the files to docx, the list numbers appeared.

wxydev1 avatar Dec 02 '21 07:12 wxydev1