Unix & Linux
emacs editors documents microsoft-word
Updated Fri, 27 May 2022 18:40:51 GMT

Edit .docx files with Emacs?


I'm starting with Emacs, and testing around I wondered if I could edit my own .docx file from there, just to explore its features and that stuff.

But my surprise is huge when, having the text perfectly displayed in my screen, I can't manage to write over it. Emacs' DocView tells me that it's a read-only document, and that I have to type C-c C-c in order to edit it. That displays me the display (sorry), but I can't see where can I edit it.

Does somebody know anything about this issue? It's the first day I'm trying Emacs, but it seems quite shocking to me it can't deal with docx files.




Solution

The Office 2007 files are all just zipped .xml files at heart. Just rename the file with a .zip and emacs will know what to do:

mv file.docx file.zip
emacs -nw file.zip

Gives output such as:

M Filemode      Length  Date         Time      File
- ----------  --------  -----------  --------  ------------------------------
  -rw-rw-rw-      3744   1-Jan-1980  00:00:00  [Content_Types].xml
  -rw-rw-rw-       737   1-Jan-1980  00:00:00  _rels/.rels    
  -rw-rw-rw-      3184   1-Jan-1980  00:00:00  word/_rels/document.xml.rels
  -rw-rw-rw-     60108   1-Jan-1980  00:00:00  word/document.xml
  -rw-rw-rw-      1226   1-Jan-1980  00:00:00  word/footer1.xml
  -rw-rw-rw-     15183   1-Jan-1980  00:00:00  word/header3.xml

(...)

  -rw-rw-rw-     23893   1-Jan-1980  00:00:00  word/styles.xml
  -rw-rw-rw-     24646   1-Jan-1980  00:00:00  word/stylesWithEffects.xml
  -rw-rw-rw-       831   1-Jan-1980  00:00:00  word/webSettings.xml
  -rw-rw-rw-       699   1-Jan-1980  00:00:00  docProps/core.xml
- ----------  --------  -----------  --------  ------------------------------
                244649                         34 files

which you can edit as much as you want.





Comments (1)

  • +0 – I do not need to change the file name. Opening the .docx file is enough. Not sure if it depends on version or OS, I'm using Emacs 24.3.1 on Linux OpenSuse Leap 42.2 64 bit. (editing is still not practical beyond simple corrections as the XML format is not user friendly - better use Open or LibreOffice I guess) — Sep 24, 2017 at 21:30