Python & Ms Word: Convert .Doc to .Docx

Python & MS Word: Convert .doc to .docx?

You are working with Linux/ubuntu, you can use LibreOffice’s inbuilt converter.

SYNTAX

lowriter --convert-to docx *.doc

Example

lowriter --convert-to docx testdoc.doc

This will convert all doc files to docx and save in the same folder itself.

Is there any package for converting doc file to docx format using python programming in Azure?

There are few approaches:

  • with unoconv: unoconv -d document --format=docx test.doc
  • with lowriter: lowriter --convert-to docx test.doc
  • with soffice: soffice --headless --convert-to docx test.doc
  • with libreoffice: libreoffice --convert-to docx test.doc

You can run these command directly from your terminal but if you want you can integrated them into python as described here:

#!/usr/bin/env python

import glob
import subprocess

for doc in glob.iglob("*.doc"):
subprocess.call(['soffice', '--headless', '--convert-to', 'docx', doc])

In the example I'm using soffice but you can now substitute unoconv, lowriter or libreoffice.

Convert .doc files in .docx in windows programatically using Python

Try win32com.client instead of just win32com

import win32com.client
word = win32com.client.Dispatch("Word.application")


Related Topics



Leave a reply



Submit