【发布时间】:2014-01-08 12:26:30
【问题描述】:
我使用下面的代码从文本文件中写入 ms 字,但没有写入行。我也无法从中设置页面宽度和高度。我将 wordapp.PageSetup.width 用于某个值,但它引发了错误。 请建议我在哪里失败..
import win32com.client
read = open('out.txt','r')
curser = read.readlines()
wordapp = win32com.client.Dispatch("Word.Application")
wordapp.Visible = 0
x = wordapp.Documents.Add()
x.PageSetup.Orientation = 1 # Make some Setup to the Document:
x.PageSetup.LeftMargin = 0.4
x.PageSetup.TopMargin = 0.5
x.PageSetup.Width = 8.27 #This threw an error
x.PageSetup.BottomMargin = 0.5
x.PageSetup.RightMargin = 0.4
x.Content.Font.Size = 11
x.Content.Paragraphs.TabStops.Add (100)
x.Content.Text = curser #This threw an error
x.Content.MoveEnd
x.Close() # Close the Word Document (a save-Dialog pops up)
x.Quit() # Close the Word Application
【问题讨论】:
-
“一个”错误?您可能想详细说明是哪一个。
-
我的意思是为什么我不能使用 use Content.Text = cursorr 以及为什么只有curser[n] 以及如何修改word文档的宽度和高度..?提前致谢
-
我的意思是你为什么不能告诉我们你遇到的 错误,而不是说你得到“一个错误”。提前致谢。
-
AttributeError: 无法设置属性 '
.Width'。是我使用 x.PageSetup.Width= 8.27 时得到的。请帮帮我。