Repair Corrupted Office File
Operator: Abdulla Al Fahad. How tools are built and checked
A .docx, .xlsx or .pptx is a ZIP of XML files, and almost every "file is corrupt" message comes from one of three breaks: the ZIP's directory at the end of the file is gone because the download stopped early, one XML part ends mid-tag, or a small glue part such as [Content_Types].xml or a relationships file is missing. The file is read without trusting its directory, each of those layers is repaired, and every part is listed as intact, repaired, rebuilt or lost, so you know what the new file contains.
Key features
- Reads ZIP entries one by one from their local headers, so a file whose central directory is missing, short or wrong still gives up the entries that are present
- Closes truncated XML at the last readable point and drops a half-written spreadsheet cell instead of keeping half a number
- Rebuilds [Content_Types].xml, the root relationships, a workbook's sheet list and relationships, and an OpenDocument manifest from the parts it finds
- Text and tables only export: a clean .docx for Word and ODT, a clean .xlsx for Excel and ODS, and a .txt of slide text for PowerPoint and ODP
What can be repaired in an Office file and what cannot
A ZIP stores each file behind a local header, then a central directory at the end that lists them all. Office writes most entries with a trailing data descriptor, so the header itself says "size unknown". The page recovers the size by inflating the stream until it ends, then locating the descriptor whose CRC-32 matches the output. An entry that was cut off keeps the bytes that inflated before the break.
Every inflate counts the bytes it really produces, with one running total of 256 MB for the whole file. Sizes written inside the ZIP are never used for that limit, because a hostile file can declare any size it likes.
How it works
The repair runs in a background worker, with progress and a Cancel button, so a large or hostile file cannot freeze the page. A deflate stream tells the page where it ends, so entries are found in one linear pass whatever the file contains.
Layer one salvages the ZIP and checks each entry's CRC-32 against the value the file stores. A part whose bytes do not match is kept but flagged. A part whose data is damaged can still inflate without an error, so its text is checked as XML. The first place where it stops being well-formed (a control or replacement character, an entity that is not one, a stray < in text, a name that is not a name, a closing tag that matches nothing) marks the damage. The part is cut a margin before that point, of 1,024 to 8,192 characters (a tenth of the part), because wrong text that still looks like text comes first, and everything after the damage is dropped, not kept unchecked. The part table and the notes say where it was cut.
Layer two repairs each XML part in one pass: attributes are re-quoted, bare ampersands escaped, stray end tags dropped, and the elements still open at the end are closed in order. Standard Office namespace declarations are restored on the root element when a damaged declaration list left a prefix unbound.
Layer three fixes what ties the parts together. Relationships that point at lost parts are removed, a missing image gets a 1-pixel transparent stand-in so a reference to it stays valid, shared-string indexes beyond the end of a truncated table are emptied, and an Excel calcChain, which is only a cache, is deleted. A package check then reopens the result and tests well-formedness, content types and relationship targets.
Common use cases
- A project manager gets a Word report whose attachment the mail gateway cut off. The repaired copy keeps the opening chapters in order, and the part table names word/document.xml as the part that was cut short.
- An accountant's workbook with 3,000 rows lost its tail on a failed USB copy. The sheet comes back with the rows before the break; because the shared-string table sat after the sheets, text cells are empty, and the notes say so.
- A 12-slide deck was cut off partway through the download. The slides whose parts survive stay in order; the others are removed from the slide list so PowerPoint is not pointed at slides that are not there, and the text-only export returns the text of the survivors.
- A minutes document in OpenDocument format lost its META-INF/manifest.xml. The manifest is rebuilt from the parts present, and mimetype is written first and uncompressed, which the format requires.
How to use this tool
- Choose the file that will not open; the repair runs as soon as it is read.
- Read the top notice and the Part by part table, which lists the worst parts first.
- Press Download repaired file and try it in the application.
- If it still refuses to open, press Download text and tables only for a clean new file with the content that survived.
Example
A 1,600-paragraph Word document written by a script (21 KB as a file, 261 KB of XML), cut off after 50 percent of its bytes
The download stopped partway; the ZIP has no central directory and word/document.xml ends mid-text. This file's entries state their sizes in their local headers, so a percentage can be shown; a file saved by Word usually leaves them blank.Part table and repaired content
word/document.xml is marked truncated: the header states 261,328 bytes and 215,005 were readable, 5 open elements were closed, about 82% of the part survived. word/_rels/document.xml.rels loses 7 relationships to parts that are gone, and [Content_Types].xml and the root relationships are rebuilt. The repaired file contains paragraphs 1 to 1,317, in order and identical to the original, with the last one cut short.Common pitfalls
A flipped byte inside compressed data usually corrupts everything after it, not just one character. The repair keeps what came before the first sign of damage, drops a margin in front of it and everything after it, and reports about how much of the part survived. A burst of damage early in a file can cost most of the document; compare the last few paragraphs or rows with your own copy.
Sheet names, defined names and print settings live in xl/workbook.xml. If that part was lost, the rebuilt workbook names its sheets Sheet1, Sheet2 and so on.
A package that passes this page's checks can still make Word or Excel ask to repair it, because the applications check more than the structure.
- A workbook that lost its shared-string table keeps its numbers and formulas but loses its text. Look for this in the notes before deciding whether the repair is enough.
- If the part table shows the main part (word/document.xml, xl/workbook.xml, ppt/presentation.xml) as lost, stop: no repair can rebuild content that is not in the file.
Common errors and how to fix them
- "This file is encrypted (a password-protected Office file is stored in a different container, not a ZIP)."
- A password-protected Office file is not a ZIP and cannot be read without the password. Open it in the application, remove the password, and try again if it still will not open.
- "This is an old binary Office file (.doc, .xls or .ppt)."
- The old formats are not ZIP packages and are not supported here. Open the file in LibreOffice, which has its own recovery for them.
- "No ZIP data was found anywhere in this file."
- The file may be an HTML error page or a download that never started. Check its size and its first bytes, and download it again.
- "The main content part of this file was lost."
- The part that holds the body text, the sheets or the slide list is not in the file. Use an earlier copy, an email attachment or a backup.
Reading the status of a part
Intact means the bytes matched their stored checksum and the XML needed no change. Repaired means the content was complete but something structural was fixed, such as a mismatched tag or an unquoted attribute. Truncated means data ended early and the part now holds only what came before the break; the detail column gives the percentage of the original size that survived when the ZIP still states that size.
Rebuilt means the part was missing and was regenerated from the other parts, which applies to content types, relationships, a workbook's sheet list and an OpenDocument manifest. Placeholder is a stand-in for a lost image. Dropped is optional metadata with damaged namespaces. Lost means nothing usable was read.
What the text-only export keeps
It keeps paragraph text, heading levels, bulleted-paragraph marks and tables for Word and ODT; cell values for Excel and ODS; and the text of each slide for PowerPoint and ODP. It does not keep fonts, colours, pictures, charts, headers, footers, comments or tracked changes, and a spreadsheet date stored as a serial number stays a number.
A text cell in the exported workbook that begins with =, +, - or @ gets a leading apostrophe so a spreadsheet cannot read it as a formula.
Frequently asked questions
Can it open a file that is protected with a password?
No. A password-protected .docx or .xlsx is stored in a different container whose contents are encrypted. The page detects it and says so rather than trying.
Why does the recovered paragraph count stop mid-sentence?
The last paragraph that was being written when the data ended is kept as far as it was readable. Only complete elements are closed; the text is not completed.
Does it fix macros or embedded objects?
It keeps vbaProject.bin and embedded objects as bytes if they were read in full, and flags them if they were cut. It does not repair them, and a damaged macro project is likely to make the application refuse the file.