DOCX · direct formatting, headings, empty paragraphs, unused styles

Word Styles Cleaner

Strip the direct fonts, sizes and colours that pasting leaves behind so text follows its styles again, fix skipped heading levels for the table of contents, drop blank-line spacing and delete styles nothing uses. A before-and-after report lists every change.

Word file

.docx up to 50 MB.

Drop a .docx here or click to choose

.docx

What to clean

Open a Word file to choose what to clean.

Word Styles Cleaner

Operator: Abdulla Al Fahad. How tools are built and checked

A document built from pasted emails, PDFs and old templates looks consistent only because each paragraph and run carries its own font, size and colour. Change the Normal style and half the text stays put; generate a table of contents and a Heading 3 appears under a Heading 1. Removing the direct formatting lets text fall back to its styles; the page also repairs the heading sequence a table of contents needs, and lists everything it changed.

Only the document XML is rewritten, and only the properties, empty paragraphs and styles the options select. The result is re-read before you download it, and the page says what that re-reading checked.

Key features

  • Direct run formatting removed by category: fonts, sizes, colours, highlights and shading, underline and other effects, character spacing; superscript, language, hidden text and existing character styles are left alone
  • Bold and italic turned into Strong, Emphasis or a combined Strong Emphasis character style, or removed, or left direct; a bold run inside a bold heading is simply dropped as redundant
  • A rule for every font and size found: remove it, keep it, or turn it into a named character style such as 'Courier New text'; monospace fonts start as styles so code stays recognisable
  • Paragraph formatting removed by category: alignment (paragraphs holding a picture keep theirs), indents, spacing, borders and shading, tab stops
  • Empty paragraphs removed or collapsed to one, heading levels renumbered so none is skipped, bold or oversized short lines optionally promoted to Heading 1 to 4, and custom styles that nothing uses deleted

What is rewritten inside the .docx

In WordprocessingML a run (w:r) can name a character style with w:rStyle and still carry its own properties in w:rPr, such as w:rFonts, w:sz and w:color; a paragraph (w:p) names a paragraph style with w:pStyle and can add w:jc, w:ind or w:spacing in w:pPr. Those direct properties win over the style, which is why editing the style appears to do nothing. Removing them lets the style show through again.

Parts rewritten are word/document.xml, headers, footers, footnotes and endnotes, plus word/styles.xml when styles are added or removed. Comments are not rewritten. A run or paragraph whose properties contain a tracked formatting change (w:rPrChange or w:pPrChange) is skipped and counted, because changing it would alter what the reviewer's change record says.

A run that contains a symbol character keeps its font, and so does text typed in Symbol, Wingdings or Webdings: in Symbol the letter m is shown as μ and in Wingdings the letter þ is a ticked box, so dropping the font would change what the text says. Those fonts start as Keep in the font table, and the report counts the runs it left alone. Everything outside the edited elements, down to attribute order and whitespace, keeps its bytes; parts that are not edited are copied through.

How it works

Each part is read into a tree that remembers where every tag starts and ends. The new property list of a w:rPr or w:pPr is built from the children that stay, and spliced over the old element, so the rest of the file is untouched.

Bold and italic are compared with the style chain first. A run with w:b inside a Heading 1 that is already bold is redundant and is dropped; a w:b with a false value that switches off bold the style turns on is a real instruction and stays. Otherwise a bold run gets rStyle Strong, which is created if the file has no style of that name.

Heading levels are walked in document order. Each heading becomes the smaller of its own level and one more than the previous heading, so Heading 1 followed by Heading 3 becomes Heading 1 and Heading 2; optionally the first heading is forced to level 1. Promotion looks for short lines of at most 90 characters with no style, no list number and no final punctuation, that are bold at body size or at least 2 pt larger, and ranks up to four distinct looks into Heading 1 to 4.

A style is unused when no pStyle, rStyle, tblStyle, numStyleLink or styleLink in any word/*.xml part names it and no used style is based on it, followed by it or linked to it. The check also runs the other way: a style that stays, such as a built-in Heading 2 based on a corporate base style, keeps the styles it is based on, followed by or linked to, even when no paragraph uses them. Default styles are always kept, and built-in styles are only removed if you tick that option and they are outside a protected core list (Normal, headings, Title, TOC, header, footer, footnote, Hyperlink, Strong, Emphasis, Caption, List Paragraph, Table Grid and others).

Common use cases

  • An editor merges chapters from five authors into one 120-page manuscript and finds 14 different body fonts; she sets every font and size to Remove, keeps bold and italic as styles, and changes Normal to 11 pt once.
  • A documentation team exports release notes from a wiki; every code term is Consolas on some runs and Courier New on others, and both are mapped to character styles so a later restyle changes them together.
  • A policy owner generates a table of contents and sees Heading 3 entries directly under Heading 1; fixing skipped levels adds the missing structure without retyping a heading.

How to use this tool

  1. Drop a .docx onto the page, or press Load a messy sample.
  2. Look at the table of fonts and sizes and set each to Remove, Keep or Make a character style.
  3. Tick the run, paragraph and structure options you want; leave Promote bold lines off until you have read the heading list once.
  4. Press Clean document and read the checks: re-opened, well-formed, text identical, untouched parts byte-identical, no dangling styles.
  5. Download the -clean.docx, or the report as CSV.

Example

A twelve-run board report (the messy sample) cleaned with default options and Courier New set to 'Make a character style'

12 of 12 runs carry direct formatting: Comic Sans MS on 6 runs, Arial on 4, Courier New on 1; sizes 10, 11, 12, 13, 16 and 20 pt; one colour. 3 paragraphs have direct alignment, spacing or indents, 5 paragraphs are empty, headings run Heading 1, Heading 3, Heading 2, and 4 custom styles exist.

Report after cleaning

0 runs and 0 paragraphs with direct formatting, 0 empty paragraphs. Fonts removed on 11 runs, sizes on 10, colour on 1, highlight on 1; alignment on 2 paragraphs, spacing on 1, indents on 1. Two bold runs become Strong, two italic runs Emphasis, the Courier New run becomes 'Courier New text', and 3 bold runs inside headings are dropped as redundant. 'Staffing' moves from Heading 3 to Heading 2, so levels read 1, 2, 2. Styles Style12, WW_Num3 and Pasted Label are removed and Strong, Emphasis and Courier New text added (9 styles before and after, custom styles 4 to 2). Only document.xml and styles.xml were rewritten; 3 other parts are byte-identical, and all five checks pass.

Tips for best results

  • If a title or a caption must stay centred, untick Alignment: a centred line with no picture in it loses its direct centring like any other paragraph.
  • Open the font table before cleaning a document that has check boxes or Greek letters: Symbol and Wingdings start as Keep, and a font you set to Remove there is removed even from those runs.
  • Read the Headings list in the report before ticking Promote bold lines: a bold line of up to 90 characters with no final punctuation qualifies even at body size, so a bold label such as 'Total' or 'Note' would be promoted too.

Common pitfalls

Removing a direct font means the text takes the style's font, and a style that is itself based on a theme font will look different from the pasted original; that is the point, but check the first page.

Heading renumbering only follows styles named heading 1 to heading 9. Headings made with a custom style that has an outline level but a different name are not changed.

Comments, text inside tracked formatting changes and runs in a symbol font or with a symbol character are left as they were, so a document can still show a few direct properties after cleaning.

Removing blank paragraphs removes spacing a writer made on purpose; the page keeps one empty paragraph between two tables, at the end of the document after a table and in a cell that holds nothing else, but a blank line used to separate two paragraphs of body text goes.

Common errors and how to fix them

"report.doc" is an old .doc file or a password-protected Word file
Save it from Word as .docx without a password and load that copy.
A part uses the WordprocessingML namespace without a prefix
Word never writes this; re-save the file from Word or LibreOffice as .docx and open that copy.
The file declares a DOCTYPE or an ENTITY
These are refused because they can expand into huge text. Save a fresh .docx from Word.

Best practices

  • Clean first, then restyle: change Normal, Heading 1 and the character styles in Word once, and the whole document follows.
  • Keep the built-in styles when you tick Remove unused styles on a corporate template: a Heading 2 based on the company's base style is kept together with that style, so the template's font and colour are still inherited.

What the checks after cleaning actually test

The page opens the saved bytes again and reports five tests. The output re-opens as a .docx. Every rewritten part parses as well-formed XML. The text of each content part, joined run by run, is identical before and after, so nothing readable was lost with the empty paragraphs. Every part that was not edited is byte-identical to the original after inflating both. And no paragraph, run or remaining style points at a style that was deleted.

These tests do not prove the document looks as you intend, only that nothing was damaged. Open the result in Word and scan the first and last pages.

Frequently asked questions

Will the document look the same afterwards?

No, and it is not meant to: runs and paragraphs fall back to the formatting of their styles, so a pasted Comic Sans paragraph takes on the Normal style's font. Bold and italic keep their look through Strong and Emphasis, and fonts you map to a character style keep theirs.

Why does bold become 'Strong'?

Strong and Emphasis are Word's built-in character styles for bold and italic. A style can be edited once for the whole document, which direct bold cannot. A run that already has another character style, such as Hyperlink, keeps its direct bold because a run can name only one character style.

Why do some Symbol or Wingdings runs keep their direct font?

Those fonts reassign letters to pictures: m in Symbol is μ, and þ in Wingdings is a ticked box. Removing the font would leave the letter m or þ in the text, and the before-and-after text check compares only the characters, so it would not notice. The runs are kept, counted in the report, and you can still set Remove for that exact font in the table.