I got a lots of notes from books in docx. There are in tables ex.: I would like to convert them to org-mode like this
What would be the best approach to do it ?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityI got a lots of notes from books in docx. There are in tables ex.: I would like to convert them to org-mode like this
What would be the best approach to do it ?
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.
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