Forum Archive

Create docx file using Python-docx?

MDB

I would like to convert an .md or .txt file to a docx, locally. I've been using the docverter workflow, and I'm really happy with it, but it still needs an internet connection, which is sometimes not possible.

I recently found Python-docx on github (https://github.com/python-openxml/python-docx) which seems to do exactly that.

I don't have a clue about working in Python. Is this something Editorial can do in a workflow with a python step?

Is Python-docx even possible to use on an iOS device?

If not, does anyone have any ideas about how to do the conversion?

FYI, all I'm really trying to do is send an Editorial file to Word (for iPad) using "open in". I can make Word appear as a sharesheet destination by just giving the file a .docx extension, but of course it won't open in Word.

Thanks for any advice.

roosterboy197

I am pretty sure this isn't possible, since python-docx (and python-xlsx) requires lxml, which is not installed on Pythonista or Editorial and is a C library rather than a native Python module and therefore can't be user-installed. It would require either a) Ole to include lxml as part of the app, or b) someone to rework python-docx and -xlsx to use another XML-parsing module, like say elementtree.

I would dearly love to be proven wrong, though.

dgbmcc

The app makeDoc by toketaWare
https://appsto.re/gb/6bHsK.i

Can use x-callbacks and will create docx files from markup and text.

Webmaster4o

@roosterboy197 I have had some success in the past simply replacing lxml functions with their xml equivalents (only works in some places). I remember getting one module to work by replacing

import lxml.etree

with

import xml.etree

sucessfully. I don't know how heavily lxml is used, but in some cases, xml can be used to do the same operations slightly less efficiently.