How to upgrade the docx format to the latest by docx?

98 Views Asked by At

The original file is docx format, which has multiple tables, but there may be format problems, so it cannot be read by python-docx.

✔️ 1.Solution by hand:

solve the question by click [save as ....] menu. A prompt box appears:

prompt box : appears upgrade to newest

❓2. Question:

How to implement [save as] function through Python-docx, upgrade the docx format to the latest?

Thanks for any suggestion!

3. appendix

from docx import Document
from win32com import client as wc

file = 'D:\\1.docx'
word = wc.Dispatch("Word.Application") 
word.Visible = False

doc = word.Documents.Open(file) 
doc.SaveAs("{}".format(file), 12)
doc.Close() 

word.Quit()
1

There are 1 best solutions below

1
3 ert On

With a compromise method,

  1. we first created a blank DOCX,
  2. then using Win32 libraries to copy the content as a whole to the blank DOCX,
  3. testing available

Still looking forward to optimization methods