0

I am working on copying specified tables from one word file to another existing word file. I got the success in that, I am able to do it but the problem is that those tables have images inside the cell. What i get in copied version is just blank box at right place with original size containing "The Picture can't be displayed."

The mentioned linked has the same issue but it was with paragraph. I tried that out but it is not working with the tables. Can anyone please help?

Edited - Here I attached two picture those are from different file.

1st image is the original document where I have table with picture inside cells

2nd image is the template file where I am pasting the whole table element from the original file where I can not get the image.

This is the code I am using..

Copy tabel from original file.

temp = docx.Document('xyz.docx')
table_list = []
for report_ele in temp.element.body:
   if isinstance(report_ele, CT_Tbl):
       table_list.append(report_ele)
        

Paste copied table using the bookmark

doc = docx.Document('abc.docx')

# geting bookmark list

bookmark_list = doc.element.findall('.//' + qn('w:bookmarkStart'))

# finding particular bookmark name    
for bookmark in bookmark_list:
    name = bookmark.get(qn('w:name'))
    if name == bookmark_name:
        bookmark_par = bookmark.getparent()
        if not isinstance(bookmark_par, docx.oxml.CT_P):
            return false
        else:
            return bookmark_par

bookmark_par_parent = bookmark_par.getparent()

index = bookmark_par_parent.index(bookmark_par) + 1

# adding a table from the prepared tabel list:
bookmark_par_parent.insert(index, add_table)

bookmark_par_parent.remove(bookmark_par)

Copying .docx and preserving images

Dhruval
  • 1
  • 2

0 Answers0