iOfficeAI / iOfficeAI/OfficeCLI

Missing ability to clear explicit paragraph/run formatting

Open
#274 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
30.7k
Forks
2.1k
Avg merge
9d 8h
Merged PRs (30d)
5

Description

# unset: clear explicit paragraph/run formatting to restore style inheritance

## Summary

`set --prop key=value` writes explicit formatting onto paragraphs and runs — but there is **no inverse**: no way to clear an explicit property so the element falls back to style or document-default inheritance.

We hit this building a 26-page math-modeling paper with 70+ body paragraphs. Every paragraph was created via `batch` with `size=11pt, indent=24pt, spaceAfter=6pt`. Later we redefined `Normal` style to `size=12pt, lineSpacing=23pt, firstLineIndent=480`. The style change had **no visible effect** — every paragraph's explicit formatting masked the style.

The only workaround is per-paragraph `set` overwrites or raw XML surgery. `set --prop size=""` throws a validation error. No `unset` / `clear` / `inherit` verb exists.

## Environment

- OfficeCLI: MCP-resident (`main`), Windows 11, PowerShell 5.1
- Agent: deepseek-v4-pro in opencode

## Reproduction

```bash
officecli create repro.docx
officecli add repro.docx /body --type paragraph \
--prop text="Should inherit style size" \
--prop size=11pt --prop indent=24pt

officecli set repro.docx /styles/Normal \
--prop size=12pt --prop lineSpacing=23pt --prop firstLineIndent=480

# Paragraph STILL shows size=11pt, indent=24pt
officecli get repro.docx "/body/p[1]" --depth 1
# → paragraph "..." size=11pt indent=24pt

# The style DID change
officecli get repro.docx /styles/Normal
# → style Normal size=12pt lineSpacing=23pt firstLineIndent=24pt

# Attempting to "unset" fails
officecli set repro.docx "/body/p[1]" --prop size=""
# → Error: Invalid font size: ''. Expected a finite number (e.g., '12', '10.5', '14pt').
```

## OOXML root cause

Word's style cascade is `docDefaults < style < paragraph-explicit < run-explicit`. When `add` emits `w:rPr/w:sz w:val="22"` (11pt) on the run, that explicit tier always wins over the style definition.

The corresponding XML nodes that need to be removed for inheritance to take effect:

| Prop | Node to remove |
| ------ | --------------- |
| `size` | `w:rPr/w:sz` on each child run |
| `indent` | `w:pPr/w:ind` |
| `spaceAfter` | `w:pPr/w:spacing` (or `w:after` attr) |
| `bold` / `color` / etc. | `w:rPr/w:b`, `w:rPr/w:color`, ... |

Today the only way to delete these is `raw-set` — not practical for batch-built documents.

## Real-world timeline

1. Build document structure with `batch` (explicit formatting on every paragraph)
2. Establish design specs (styles, type scale, spacing)
3. Update style definitions
4. **Cannot** make existing paragraphs adopt the new styles

Our concrete case: after step 3, every one of 70+ body paragraphs still rendered at 11pt with block indent — the style redefinition was fully invisible. We also had equation paragraphs (`oMathPara`) inheriting `lineSpacing=23pt` from Normal, which compressed the equation display. Each equation paragraph had to be individually `set` to `lineSpacing=1x`.

## Validation proposal (if a fix lands)

1. Clear `size` on a paragraph with explicit sizing → `get` output no longer shows `size=11pt`; effective size comes from the style
2. Clear a key that has no explicit value → no-op, not an error
3. Works on runs directly (`/body/p[1]/r[1]`)
4. `batch` with clear commands → atomic semantics
5. Round-trip: clear then `set` the same key → explicit value restored

Contributor guide

Open the contributing guide

Research direction

Start by tracing the existing set, add, and batch command paths, then compare their handling with raw-set and the listed OOXML nodes for paragraph and run properties. Run the reproduction and validation proposal: clearing should remove explicit values, be a no-op when absent, work on runs, preserve batch atomicity, and allow clear-then-set round trips.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.