lua对于excel的操作

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();

 

posted @ 2019-03-06 21:47  Answer.AI.L  阅读(2946)  评论(0编辑  收藏  举报