360 Secure SkillHub
360 安全技能中心

DOCX Report Figures

读取上传的 DOCX 报告与格式,定位含数据的段落并规划图表,使用 matplotlib 生成数据图,按既有版式插入三线表、题注与正文引用,最后导出 PDF 检查分页和编号;不改写正文,也不编造数据。

分类:数据
wang-shuanglin
wang-shuanglin
热度 7.13
最近更新 2026-11-07 19:24:05

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add wang-shuanglin/docx-report-figures
兼容性
通用兼容
联网要求
不联网
数据出网
数据不出本机
Metadata
name
docx-report-figures
description
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

  1. 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.
  2. Never change body text except adding in-text references such as (见表1), inserted before the final 。 of the paragraph that the exhibit supports.
  3. 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 示意图.
  4. 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 example
  • references/sci-report-style.md — table/figure typography, chart design, caption and note wording