Search code examples
excelxlsxspacedata-recoverynul

XLSX corrupt after accidental open & save in Notepad


Is there a programmatic, built-in, or external method to recover a corrupt Excel file?

I accidentally opened my .XLSX file (Excel 2010) in Windows Notepad, added a line of recognizable text, and saved it. Now the file cannot be opened by Excel, as the internally compressed .XLSX file cannot be uncompressed.

My research showed me that:

  1. The .XLSX file is a compressed archive, starting with PK….

  2. By saving the file in Notepad, all Null/\0 characters were replaced with spaces (0x20).

  3. Before the mistake happened, the file contained already several hundreds of 0x20 characters, so replacing all 0x20 with 0x00 won't help.

Any ideas are appreciated! Thanks in advance!


Solution

  • Wow, that sucks, bigtime.

    I've seen lots of corrupt files caused lots of different ways but that's a new one.

    That series of events if probably near the top of the list of "Things not to do to Excel files." We're sorry, we'll have to suspend your "Excel Operator's License".

    I guess there's a couple things you could try...,


    Plan A

    Is there any chance you have Autorecover turned on? If not, you should probably turn them on now, for "next time".

    If it is on, then hopefully the Document Recovery task pane appears when you try to open the file (in Excel). If so, see:

    Even if your file doesn't show up in that dialog, double-check all of the folders/files located in the default AutoRecover save location to see if a recent version was saved, "just in case":

    %AppData%\Microsoft\Excel


    Plan B:

    Since an XLSX file is actually just a .ZIP file, there's a chance you may be able to use WinZip or a ZIP Repair Utility to recover your data (depending, of course, on how badly you messed it up.)

    • Change the file's extension to .ZIP and open it with WinZip.

    • It may try to repair the file, and if it does it might even succeed (on some or all "parts").

    • Put all the files back into a new .ZIP.

    • Change the extension back to .XLS.

    • Cross you fingers and try opening it with Excel.

    There are also lots of standalone ZIP Repair Utilities out there, so you could try a few others with the same process.

    I have no idea if any will actually work in this case, but please report back if you do end up trying any of them (whether or not they fix it), so we all know.

    More about Excel File Structure:


    Plan C:

    Short of that working, you could try opening it back up in Notepad and see if there's any legible data you can copy & paste out manually... might be there a while, if there's anything at all...


    Plan D:

    There is no Plan C. Sorry, you're SOL.

    How to turn on AutoRecover (for next time):

    1. Click FileOptionsSave
    2. Make sure the Save AutoRecover information every x minutes box is selected

    Important: Even after turning AutoRecover on, the image Save button is still your best friend.

    To be sure you don’t lose your latest work, click Save Button image (or press Ctrl+S) often.

    dialog screenshot

    Oh, and in the future:

    Don't open Excel files in anything but Excel.


    Source & More Info:


    Sudoku