LuaCOM Word文档标题

时间:2013-05-29 21:13:21

标签: com lua luacom

我正在尝试创建一些创建word文档的LuaCOM编程。我已经弄清了大部分内容,但似乎无法理解页眉/页脚是如何工作的。

word = luacom.CreateObject("Word.Application")


book = word.documents:Add()
word.Visible = true



paras = book.Paragraphs:Add()
range = paras.Range

range.Text = ([[Nam fabulas mnesarchum comprehensam ne, cu ullum euismod consulatu usu. Eam alii lobortis voluptatum id, denique eligendi pertinax quo ne. Vis congue eirmod ut. Duo probo soleat ex. Elit pertinax abhorreant eu his, ipsum dicam dissentiunt pri id. Kasd erant dolorum id sed, ei vim partem deseruisse, ne mea dico tantas alienum.
Has cu facilisis mediocritatem. Fabellas lucilius vim ex.
]])

book.InlineShapes:AddPicture("C:\\13.png", 0, 1);
range.Style = ("Normal")
range:InsertParagraphAfter()

word.DisplayAlerts = false;

doc = nil
word = nil

这里我只是创建一个带有段落的标准文档,并在顶部附近添加图像。我想将标题中的图像与标题中的一些文本对齐。

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

这对我有用:

require("luacom")
local word = luacom.CreateObject("Word.Application")
local book = word.documents:Add()
word.Visible = true
local section = book.Sections(1)
local headers = section.Headers
local header = headers:Item(1)
header.Range.Text = "HEADER"
header.Range.InlineShapes:AddPicture("C:\\13.png", 0, 1);
doc = nil
word = nil