python3中的win32com Word.Application:如何水平放置表?

2024-09-27 23:26:11 发布

您现在位置:Python中文网/ 问答频道 /正文

''导入com对象 '''

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

''内容 '''

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 = doc.Range()
location.Move() # place table at the end 

''”
第一桌 '''

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

''”
第二桌 '''

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")

Tags: importcomaddhelloworldtablesdoctable

热门问题