0

'''import com object '''

import time
import win32com.client as win32 
word = win32.gencache.EnsureDispatch('Word.Application',1)
word.Visible = 1

'''content '''

doc = word.Documents.Add()
doc.Top = 1
doc.Content.Text = "hello world"

doc.Content.Paragraphs.Add()
doc.Content.InsertAfter("hello2 ?")
doc.Content.InsertAfter("hello world 3")

''' location of table '''

location = doc.Range()
location.Move() # place table at the end 

'''
first table '''

table = doc.Content.Tables.Add(location, 2, 4)

'''
second table '''

table2 = doc.Content.Tables.Add(location, 2, 2)

table2.PreferredWidth = 40

table.ApplyStyleHeadingRows = 0 
table.AutoFormat(16)
table.PreferredWidth = 400

doc.Content.InsertAfter("hello4 hello5")
Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
  • First, try it yourself as a user, in Word. You'll see this is not something Word is built to do, at least, not easily. It can be done, either by nesting the three tables in each of three cells of a one-row table. Or by activating "text wrap" formatting on the tables so that they can be positioned like graphics. Or by inserting the tables in text boxes and positioning the text boxes. Given the complexity of trying to position things with text wrap formatting, I'd opt for the nested tables... – Cindy Meister Mar 26 '20 at 16:26
  • i can do it with textboxes but I don't like it . I don't know how to do with text wrap – Freedom Noso Choussi Mar 27 '20 at 14:41
  • I'm at a mobile device so I can't look up the exact menu names (and anyway, this is an end-user issue), but start with the "Table Properties" dialog box. As I recall, it's in the first tab, bottom half, and is not labelled "text wrap", something more likely "positioning" – Cindy Meister Mar 27 '20 at 15:38

0 Answers0