require("luacom"); require("lc"); --創建excel對象 local excel = luacom.CreateObject("Excel.Application"); --創建新的實例 excel.Visible = false; local book =excel.Workbooks:Add(); --讀第一個工作表 local sheet = book.Sheets(1); sheet.Cells(1, 1).Value2 = "hello"; sheet.Cells(1, 2).Value2 = lc.a2u("你好"); sheet.Cells(2, 1).Value2 = "hello"; sheet.Cells(2, 2).Value2 = "java"; local name = 'E://' .. lc.a2u("fjhx") .. '.xls'; -- 保存 book:SaveAs(name); book:Close(); --[[ 關閉excel -------------]] excel:Quit(); --釋放資源 excel = nil; collectgarbage();