这是我在Excel中导出数据的代码。我的用户列表不为空。

def exportExcel(){

        if(params?.type && params.type != "html"){

            response.contentType = grailsApplication.config.grails.mime.types[params.type]
            response.setHeader("Content-disposition", "attachment; filename=cdsadminlist.${params.extension}")

            List fields = ["username", "email"]
            Map labels = ["username":"User Name", "email":"Email"]

            def upperCase = { domain, value ->
                return value.toUpperCase()
            }

            Map parameters = [title: "cds admin list", "column.widths":[0.15, 0.4]]
            Map formatters = [:]
            List users = userService.cdsAdminList()

            exportService.export(params.type, response.outputStream, users, fields, labels, formatters, parameters)
        }

    }

这是我获取用户的代码

def cdsAdminList(){
    def users = UserRole.createCriteria().list{
            or{
                eq("role",Role.findByAuthority(CdsStaticPath.StaticRoles.ROLE_CDSUSER))
                eq("role",Role.findByAuthority(CdsStaticPath.StaticRoles.ROLE_AGENTADMIN))
                eq("role",Role.findByAuthority(CdsStaticPath.StaticRoles.ROLE_REPORTVIEWER))
            }
    }

    def userList = []
    users.each {user->
        if(user.user.enabled){
            userList.add(user)
        }
    }

    return userList
}

Excel显示空行
grails - 无法在Excel中写入行-LMLPHP

帮我解决这个问题。

最佳答案

找到了!!!

您使用包含User对象的UserRole对象进行迭代。您必须将user对象添加到列表中:

if(user.user.enabled){
  userList.add(user.user)
}

关于grails - 无法在Excel中写入行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51075226/

10-13 07:15
查看更多