Use a Lua script to generate Microsoft Word or Microsoft
Excel documents with specified content without having to open the applications.
Ensure that you are using the Windows operating system and
that Microsoft Word and/or Microsoft Excel is installed on the machine.
-
Open the script editor.
-
Create a new empty script.
-
As an example, load one of the scripts below into the script editor.
-
Run the script.
require "luacom"
local msword = luacom.CreateObject("Word.Application")
assert(msword, "Could not open MS Word")
msword.Visible = true
doc = msword.Documents:Add()
insertionPoint = doc.ActiveWindow.Selection
insertionPoint.Style = "Heading 1"
insertionPoint:TypeText( "Feko Says..." )
insertionPoint:TypeParagraph()
insertionPoint:TypeText( "Hello world!" )
require "luacom"
local excel = luacom.CreateObject("Excel.Application")
assert(excel, "Could not open MS Excel")
excel.Visible = true
workbook = excel.Workbooks:Add()
worksheet = workbook.Worksheets:Add()
worksheet.Range( "A1", "A1" ).Value2 = [[hello]]
worksheet.Range( "A2", "A2" ).Value2 = [[world]]
worksheet.Range( "A3", "A3" ).Value2 = [[=CONCAT(A1," ",A2,"!!")]]
feko.Form.Info( "Excel says...", worksheet.Range( "A3", "A3" ).Value2 )
worksheet.Range( "A2", "A2" ).Value2 = [[everybody]]
feko.Form.Info( "Excel says...", worksheet.Range( "A3", "A3" ).Value2 )