Luaスクリプトを使用して、Microsoft WordもMicrosoft Excelも開くことなく、指定した内容でそれらの文書を生成します。
Windowsオペレーティングシステムを使用していること、およびMicrosoft WordまたはMicrosoft Excel、あるいはその両方がインストールされていることを確認します。
-
スクリプトエディターを開きます。
-
新しい空のスクリプトを作成します。
-
例として、次のスクリプトのいずれかをスクリプトエディターに読み込みます。
-
そのスクリプトを実行します。
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 )