easyui DataGrid 工具类之 TableUtil class
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.poi.ss.formula.functions.T;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.dom.DOMDocument;
import com.gsoft.cos.core.util.Assert;
import com.gsoft.modules.infrastructureManagement.utils.execl.ColumnVO;
/**
* @ClassName: TableUtil
* @Description: excel工具类
*/
public class TableUtil {
public static String print(List<List<ColumnVO>> list, List<T> datas) {
return print(list, null, datas);
}
@SuppressWarnings("unchecked")
public static String print(List<List<ColumnVO>> list, String title,
List<?> datas) {
Document doc = new DOMDocument();
doc.setXMLEncoding("UTF-8");
Element table = doc.addElement("table");
table.addAttribute("class", "print-table");
if (Assert.isNotEmpty(title)) {
Element caption = table.addElement("caption");
caption.setText(title);
}
// 表头
List<String> contains = new ArrayList<String>();
Map<String, String> keyMap = new HashMap<String, String>();
for (int i = 0; i < list.size(); i++) {
List<ColumnVO> columns = list.get(i);
int startColumn = 0;
Element tr = table.addElement("tr");
tr.addAttribute("class", "print-th");
for (int j = 0; j < columns.size(); j++) {
if (!contains.contains(startColumn + "," + i)) {
ColumnVO column = columns.get(j);
if ((Assert.isNotEmpty(column.getHidden()) && column
.getHidden()) || !column.isExported()) {
continue;
}
if (Assert.isNotEmpty(column.getField())) {
keyMap.put(String.valueOf(startColumn),
column.getField());
}
Element td = tr.addElement("td");
td.setText(column.getTitle());
int colspan = 1;
if ((Assert.isNotEmpty(column.getColspan()) && column
.getColspan() > 1)) {
colspan = column.getColspan();
}
int rowspan = 1;
if (Assert.isNotEmpty(column.getRowspan())
&& column.getRowspan() > 1) {
rowspan = column.getRowspan();
}
if (colspan > 1) {
td.addAttribute("colspan", String.valueOf(colspan));
}
if (rowspan > 1) {
contains.add(startColumn + "," + (rowspan - 1));
td.addAttribute("rowspan", String.valueOf(rowspan));
}
startColumn += colspan;
} else {
startColumn += 1;
}
}
}
Object object = null;
// 遍历集合
if (datas != null) {
for (int i = 0; i < datas.size(); i++) {
object = datas.get(i);
Element tr = table.addElement("tr");
tr.addAttribute("class", "print-tr");
Map<String, Object> map = new HashMap<String, Object>();
if (!(object instanceof Map)) {
try {
map = BeanUtils.describe(object);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
for (int j = 0; j < keyMap.size(); j++) {
String key = keyMap.get(String.valueOf(j));
String value = MapUtils.getString(map, key);
Element td = tr.addElement("td");
td.addAttribute("class", "print-td");
td.setText(value);
}
}
}
return table.asXML();
}
}
easyui DataGrid 工具类之 TableUtil class的更多相关文章
- easyui DataGrid 工具类之 WorkbookUtil class
/** * @Title: WorkbookUtil.java * @Description: excel工具类 * @date 2014年5月29日 上午10:36:42 * @version V1 ...
- easyui DataGrid 工具类之 util js
var jq; var tab; var tabsIndex; /** ...
- easyui DataGrid 工具类之 Utils class
import java.lang.reflect.InvocationTargetException;import java.text.ParseException;import java.text. ...
- easyui DataGrid 工具类之 后台生成列
@SuppressWarnings({ "rawtypes", "unchecked" }) public Map<String, Object&g ...
- easyui DataGrid 工具类之 列属性class
public class ColumnVO { /** * 列标题文本 */ private String title; /** * 列字段名称 */ pr ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(8)-MVC与EasyUI DataGrid 分页
系列目录 前言 为了符合后面更新后的重构系统,文章于2016-11-1日重写 EasyUI Datagrid在加载的时候会提交一些分页的信息到后台,我们需要根据这些信息来进行数据分页再次返回到前台 实 ...
- 控制EasyUI DataGrid高度
这次要说的是控制EasyUI的高度,平时我公司的项目,用EasyUI较多,然后datagrid这个组件是用的非常多的.平时我们都是固定高度,常见代码如下: <table ...
- easyui datagrid标题列宽度自适应
最近项目中使用easyui做前端界面,相信大部分使用过easyui datagrid的朋友有这么一个疑问:如果在columns中不设置width属性能不能写个方法让datagrid的头部标题和数据主体 ...
- 实现easyui datagrid在没有数据时显示相关提示内容
本示例实现easyui datagrid加载/查询数据时,如果没有相关记录,则在datagrid中显示没有相关记录的提示信息,效果如下图所示 本实例要实现如下图所示的效果: 本示例easyui版本为1 ...
随机推荐
- 出售一套Unity + Lua热更新框架代码
出售一套Unity + Lua的客户端框架代码,功能有资源管理.网络通信.配置文件解析.热更新.文件读写.Lua加密揭秘.UI框架.打包工具.编辑器工具等,已经在多个实际项目(已上线)中使用.代码优雅 ...
- 【iOS测试】【随笔】帧率FPS评测
◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/5943263.html 背景 我们的新版App对首页的列 ...
- C#程序以管理员权限运行
原文:C#程序以管理员权限运行 C#程序以管理员权限运行 在Vista 和 Windows 7 及更新版本的操作系统,增加了 UAC(用户账户控制) 的安全机制,如果 UAC 被打开,用户即使以管理员 ...
- 随手记一次用C#正则表达式获取下拉菜单html标签<select>以及相关属性值
随手记一次用C#正则表达式获取下拉菜单html标签<select>以及相关属性值 1:有如下html: .................. <select id="aaa ...
- FIFO简记
FIFO( First In First Out)简单说就是指先进先出的存储方式,在高速外设读取时经常使用. FIFO从读写的时钟可分为同步和异步两种,从信号来说都有读.写使能信号,读.写数据总线,满 ...
- Docker入门简介
Docker的概念 什么是Docker? Docker是一个开源平台,包含:容器引擎和Docker Hub注册服务器 Docker容器引擎:可以将开发者打包他们的应用和依赖包到一个可一直的容器中,然后 ...
- sys.syslockinfo--master..syslockinfo
from:http://technet.microsoft.com/zh-cn/library/ms189497.aspx 重要提示 将此 SQL Server 2000 系统表作为一个视图包含进来是 ...
- JSP 登录与注册的小案例
源代码连接地址如下:链接:http://pan.baidu.com/s/1nvEuHBj 密码:qsr1 #properties文件 driver=oracle.jdbc.driver.OracleD ...
- ios - runtime运行时应用---交换方法
runtime运行时用法之一 --- 交换类的方法,此处简单写了把系统的UIView的setBackgroundColor的方法换成了自定义的pb_setBackgroundColor 首先创建UIV ...
- Error : An error occurred while creating the WebJob schedule: Response status code does not indicate success: 409 (Conflict).
How to fix the error? the answer is simple switch from Free to Standard...