3

I got a lots of notes from books in docx. There are in tables ex.: Notes in docx I would like to convert them to org-mode like this enter image description here

What would be the best approach to do it ?

  • I would go with copy and paste. – John Kitchin Nov 13 '18 at 22:29
  • but I got like 500 hundred pages :/ I will took a a lot of time. – slk500 Nov 13 '18 at 23:28
2

One way that might not be too bad, if the tables are all structured the same way, e.g. the first column is always a first level heading (and there are no newlines in it), and the second column should always be second columns, and all notes for a book are in one row, is to extract the tables using a Python script. I would put this script at the top of an org-file, change the filename to your file and see what it outputs.

#+BEGIN_SRC ipython :results raw
from docx.api import Document

document = Document('One.docx')

for table in document.tables:
    for i, row in enumerate(table.rows):
        text = [cell.text for cell in row.cells]

        print(f'* {row.cells[0].text}')
        for subheading in row.cells[1].text.split('\n'):
            print(f'** {subheading}')
    print('\n')
#+END_SRC

This performed reasonably on a one page docx with two tables in it for me. I just had to pip install python-docx for Python3.

The solution by @richiemorrisroe will also get you an org-file with the notes in table form, but I think it would be more challenging to write elisp code to convert those into headings than the little python script above.

  • Awesome! Works great! I'm very gratefull for you help and this solution :D – slk500 Nov 16 '18 at 9:35
0

The best way to convert docx to org-mode (in general, not just for tables) is to use pandoc (https://pandoc.org/).

You can do this: pandoc -f docx -t org inputfile.docx -o output.org

  • I think you mean docx to org-mode. I tried this on a docx file containing a simple table and was surprised at how well it turned those tables into org tables. That seems like a good start towards this goal, but there will still be a lot of processing to do to convert the tables to headlines. – John Kitchin Nov 14 '18 at 23:48
  • @JohnKitchin I do, thank you!. I normally just write a keyboard macro to find any tables and make a name, then export to csv (which was the use-case I had). – richiemorrisroe Nov 17 '18 at 18:02

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.