--保留字符串格式导出Excel,tn_busi_util是新写的,需要打包进xdb
ui:use('tn_busi_util');

m_pGrid = CLuaGridUtil();
m_pGrid:SetGrid(ui:getDialogName(),'id_grid');

--表格里的数据查询这里就省略了……

function click_id_export()
    local helpColumns = CSelectHelp();
    m_pGrid:getColumnsInfo(helpColumns);
    local help = CSelectHelp();
    m_pGrid:getHelp(help);
    --调用tn_busi_util的方法导出Excel
    export_excel(help,helpColumns);
end
ui:setClickEvent('id_export','click_id_export');

--以下为导出Excel方法源码
--tn_busi_util
--功能说明:客户端通用工具
--
--Copyright(C) 杭州塔网科技有限公司  2015-2020
--
--更新日志
--        2020-05-09 新建   --by Chen 
--------------------------------------------------
--#######变量定义开始
function export_excel(help,helpColumns)
    local line = CVector();
    local lineName = CVector();
    helpColumns:orderBy('序号');
    for i=0,helpColumns:size()-1 do
        if helpColumns:vs(i,'是否显示') == '1' then
            line:push_back(helpColumns:vs(i,'编码'));
            lineName:push_back(helpColumns:vs(i,'显示名称'));
        end
    end 
    local xlsx = CLuaXlsxUtil();
    local helpFormat = CSelectHelp();
    for i=0,lineName:size()-1 do
        xlsx:writeString(1,i+1,lineName:get(i),helpFormat);
    end
    for i=0,help:size()-1 do
        for j=0,line:size()-1 do
            xlsx:writeString(i+2,j+1,help:vs(i,line:get(j)),helpFormat);
        end
    end
    local sName = ui:getSaveFileName('保存文件',cutil:getBusiUniqueID('',''),'(*.xlsx)');
    xlsx:saveAs(sName);
    if ui:msgConfirm('是否打开文件', sName) then
        sName = string.gsub(sName, '/', '\\');
        os.execute(string.format([[explorer "%s"]], sName));
    end
end
Copyright © TouchNet 2015 all right reserved,powered by Gitbook最后修订时间: 2022-06-21 09:21:04

results matching ""

    No results matching ""