DOCX Report Figures
Add data-grounded tables and figures to an existing Chinese/English research report or paper in DOCX, keeping every number traceable to the source text. Use when the user uploads a .docx report and asks to 补充图表 / 插入表格 / 配图 / 数据可视化 / "看看哪里可以加图表", or asks to turn passages with statistics into 三线表 or matplotlib charts. Covers planning which passages deserve exhibits, designing three-line tables, drawing publication-style charts with exact values from the text, inserting captions/notes/in-text references, and verifying pagination. Do NOT use for rewriting text or for generating illustrative photos (that is an image-generation task).
DOCX Report Figures
Insert tables and data figures into an existing report without altering its text, so that every number in every exhibit can be traced back to a sentence in the report. The deliverable is the original document plus exhibits, not a rewritten document.
Non-negotiables
- Never invent data. Every value, unit, year, rating, and country name in a table or chart must come from the report, or be an explicit arithmetic result of values that do (difference, ratio, sum) — and derived values get a note saying so.
- Never change body text except adding in-text references such as
(见表1), inserted before the final。of the paragraph that the exhibit supports. - Data figures are drawn programmatically (matplotlib), never generated by an image model. Image models cannot guarantee ticks, labels, or values. Only photos/illustrations may come from image generation, and then the caption says 示意图.
- Number exhibits in document order and use one series per kind (表1…表N, 图1…图N). Renumber pre-existing captions if they were unnumbered, and keep their images.
Workflow
1. Inventory the document
python scripts/extract_report.py report.docx --out dump.txt
Read the dump (paragraph index, style, text; page setup; existing tables and images). Read the whole report before planning anything — the exhibits must follow the argument, not decorate it.
2. Measure the existing typography
python scripts/inspect_format.py report.docx --out format.txt
Record: page size and margins, usable text width, body font/size/line spacing/first-line indent, how section headings are formatted, how existing figure captions look, whether a table style exists. All inserted content must match these numbers.
3. Plan the exhibits
Walk the report section by section and list candidate passages that contain: multi-country or multi-year comparisons, quantitative targets vs. actuals, price/tariff structures, capacity or grid statistics, financing terms, or a mechanism described as a chain/cycle. For each candidate decide:
- Table when 3+ attributes must align across 2+ subjects (countries, years, technologies).
- Figure when magnitude comparison (bars), shares (horizontal bars), or a supply/demand balance (bars + reference line) reads faster.
- Schematic when the passage describes causal transmission between factors.
- Nothing when the passage is qualitative with no numbers — do not force an exhibit.
Write the plan as JSON (schema in references/plan-schema.md), and for each exhibit keep a one-line provenance note: 表1 ← P4“23%…15.75%…15.63 GW…4.37 万 MW…”. If you cannot cite the source paragraph, drop the exhibit.
Copy every anchor character-for-character out of dump.txt. Do not retype it and do not add spaces: Chinese reports usually write 截至2025年6月底, and the gap you see on screen is Word's automatic CJK–Latin spacing, not a space. A wrong anchor aborts the build.
4. Draw the figures
Charts go to figs/, width exactly the usable text width (typically 14.5 cm ≈ 5.71 in at 1× scale), matplotlib rcParams with a Times New Roman + SimSun fallback so digits and Chinese both look right. Follow references/sci-report-style.md for sizes, colors, axis and label conventions. Compute derived values in the script and print them, so the numbers in the note can be checked.
5. Build the document
python scripts/build_figures.py plan.json
The builder copies the source file, inserts in-text references, then each table (caption above, three-line borders, 9 pt body, header repeat, rows that do not split) and each figure (image + caption below + 9 pt note), and finally normalizes oversized legacy images to the text width when asked. It never edits existing text.
6. Verify
Export a PDF (Word COM on Windows, else soffice --convert-to pdf) and render pages:
# Windows + Word
powershell -File scripts/export_pdf.ps1 -Source preview.docx -Pdf preview.pdf
python scripts/verify_layout.py preview.pdf --pages-dir pages --out pages.txt
Then look at the page images for every exhibit: caption on the same page as its table/figure, table not split across pages, no overlong cell wraps (country names must not break mid-word), no text overlapping in charts, numbering in order, references present. Fix and rebuild until clean. Do not deliver unseen output.
7. Report
Deliver the DOCX and a PDF preview. List each exhibit with its number, placement, and the paragraph values it came from; call out every derived number and its arithmetic. State what you did not add (e.g. no generative photos for data) and why.
Scripts
| Script | Purpose |
|---|---|
scripts/extract_report.py | Dump indexed paragraphs, sections, tables, images, page setup to a UTF-8 text file |
scripts/inspect_format.py | Report fonts, spacing, indents, caption style, table borders, image widths |
scripts/build_figures.py | Apply a JSON plan: refs, tables, figures |
scripts/fig_style.py | matplotlib publication style, palette, save(), value labels |
scripts/verify_layout.py | Render PDF pages to PNG and map captions to pages |
scripts/export_pdf.ps1 | Windows: Word COM export to PDF (tolerates the Close() RPC error) |
References
references/plan-schema.md— JSON plan format with a complete examplereferences/sci-report-style.md— table/figure typography, chart design, caption and note wording
- Downloads
- 166All time
- Security audit
- Review
- Last updated
- 2w ago
- Current version
- v1.0.0
- License
- MIT-0
