Inspect and manage the styles in a document — the CLI equivalent of Word’s Styles pane.
1. Subcommands
| Subcommand | Description |
|---|---|
|
List all styles in a document |
|
Remove styles from a document |
|
Rename a style’s display name |
2. list
List every style in a document with its id, type, and base style. The CLI equivalent of opening Word’s Styles pane.
uniword styles list report.docx
uniword styles list report.docx --type paragraph
uniword styles list report.docx --verbose
Options:
--type-
Filter by style type:
paragraph,character,table,numbering --verbose,-v-
Show font, size, bold/italic for each style
3. remove
Remove one style or every unreferenced style from a document. Word’s
Styles-pane "Remove Style" and "Clean unused styles" as a one-shot command.
Default styles (Normal, Heading1, etc.) are always kept.
# Remove one style by id
uniword styles remove input.docx output.docx --id ObsoleteStyle
# Remove every style no content references
uniword styles remove input.docx output.docx --unused
# Preview the removal without writing
uniword styles remove input.docx output.docx --unused --dry-run
Options:
--id-
Style id (
w:styleId) to remove --unused-
Remove every style no content references
--dry-run-
List what would be removed, do not write
--verbose,-v-
Verbose output
You must specify exactly one of --id or --unused.
4. rename
Rename a style’s display name (w:name). References target the w:styleId,
which is unchanged, so renamed styles stay linked from every paragraph, run,
or numbering definition that uses them.
# Identify the style by id
uniword styles rename input.docx output.docx --id Heading1 --name "Chapter Title"
# Identify the style by its current display name
uniword styles rename input.docx output.docx --from "Old Name" --name "New Name"
Options:
--id-
Style id (
w:styleId) to rename --from-
Current display name of the style
--name-
New display name (required)
--verbose,-v-
Verbose output
You must specify exactly one of --id or --from to identify the style.
5. Ruby API
The same operations are available programmatically:
doc = Uniword::DocumentFactory.from_file("report.docx")
# Inspect
doc.styles_configuration.styles.each do |style|
puts "#{style.styleId} (#{style.type})"
end
# Rename
doc.rename_style("Heading1", "Chapter Title")
# Remove one
doc.remove_style("ObsoleteStyle")
# Remove every unreferenced style
cleanup = Uniword::Wordprocessingml::StyleCleanup.new(doc)
cleanup.remove_unused # => Array<String> of removed ids
doc.save("output.docx")