[feat][docx] One-shot exact table clone: match existing style incl. CJK fonts and asymmetric sz/szCs
Use case
I had a .docx report where one table under "domestic/foreign vendors" was a screenshot image, while the rest of the document used real Table Grid tables. I wanted to replace that single image paragraph with a real 21x2 table that looks exactly like its neighbors.
Existing tables in the file look like this at the XML level:
tblStylecustomTable Grid(w:val="af0"),tblW=8220dxa,layout=fixed,tblLook=04A0- header cell:
jc=center,rFonts eastAsia="黑体" cs="Times New Roman",b,color=000000,sz=21+szCs=24 - body cell:
rFonts cs="Times New Roman"(eastAsia inherited as 宋体),color=000000,sz=20, no explicit alignment
What I tried
query --compact located the image paragraph quickly, and get showed the reference tables. For the build I ended up editing word/document.xml directly (clone a neighbor tblPr, rebuild 21 rows), because doing it purely through the CLI felt like 40+ incremental calls for one table.
What works well today
To be fair, most pieces already exist:
add /body --type table --prop rows/cols/data/colWidths/width/style/tblLook/bordersadd /body --from /body/tbl[N]table clone, plus column--fromcloneset .../tc[C] --prop text/font/size/bold/color/align/width/fill
So this is a feature request, not a "nothing works" bug. My earlier assumption that "OfficeCLI can't replicate tblPr/tcW/rPr" was wrong — it can, just step by step.
Gaps I hit
- No one-shot "clone this table's look, but with different shape/data". I wanted something like: copy
tbl[12]'s style grid, then supply 21x2 data.--fromclones size too, so I still had to reshape row by row. - CJK fidelity: cell
font=seems ASCII-only (readback saysRunFonts.Ascii). I could not seteastAsia="黑体"separately fromascii/cs, which matters for Chinese headers. - Asymmetric
sz/szCs: header neededsz=21+szCs=24. Cellsize=10.5ptpresumably sets both to the same value, with nosizeCs-style knob. - Positional replace:
add tableappends at the end. Replacing an image paragraph in the middle meantadd+move --index+removeof the image para across several calls, each shifting indices.
Rough guesses (not prescriptions)
- Perhaps allow
add --from <table> --prop data=... --prop rows/cols=...to keep style/grid look while reseeding shape and text. - Perhaps expose
fontEastAsia/fontCsandsizeCsalongside the existingfont/size, so CJK + Latin can diverge the way Word stores them. - Perhaps document a short "replace image-para with styled table" recipe, since screenshot-tables are a common cleanup task.
Happy to provide a minimal repro doc if it helps. Thanks for the great help system — it made the gap easy to verify before filing.
Env: officecli 1.0.149, Windows + pwsh. Wiki pages checked: word-table, word-table-add/get/set, word-reference (--from copy).
Source: iOfficeAI/OfficeCLI