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 ...
随机推荐
- selenium项目的实战经验
以前学习selenium,最接近项目的经验就是写了百度首页和自己开发的一个小网站的脚本,当时觉得差不多可以了.然而这次项目实战才发现还是学到不少知识,毕竟这个网站的专业程度远超过我自己写的,而且复杂程 ...
- MySQL 主从配置
mysql主从复制指两个服务器之间数据库的同步,当主服务器的数据进行了变更,从服务器也会自动更新,其过程是通过bin-log日志实现的,本质是binlog日志的传输. mysql主从分两个角色 1.主 ...
- 动态SQL语句之sp_executesql的使用
sp_executesql,sql2005中引入的新的系统存储过程,也是用来处理动态sql的, 如: exec sp_executesql @sql, N'@item_name nvarchar(10 ...
- Integer.toBinaryString()的源代码解析
private static String toUnsignedString(int i, int shift) { char[] buf = new char[32];//i是要整形,这里得把它化成 ...
- iOS Developer Library地址
1. iOS Developer Library路径:https://developer.apple.com/library/ios/navigation/ 2. 百度搜索:iOS Developer ...
- WINDOWS遠程常規化後再次切換回到全屏
其实有更好的方法的,CTRI+Alt+Break,博主试试看
- length属性,length()方法和size()的方法的区别
一.java 1.length属性是针对Java中的数组来说的,要求数组的长度可以用其length属性: 2.length()方法是针对字符串来说的,要求一个字符串的长度就要用到它的length()方 ...
- Hive:org.apache.hadoop.hdfs.protocol.NSQuotaExceededException: The NameSpace quota (directories and files) of directory /mydir is exceeded: quota=100000 file count=100001
集群中遇到了文件个数超出限制的错误: 0)昨天晚上spark 任务突然抛出了异常:org.apache.hadoop.hdfs.protocol.NSQuotaExceededException: T ...
- kali 更改root密码
sudo root passwd root 然后输入两次密码即可
- C#先序遍历2叉树(非递归)
找了下先序遍历二叉树C# 实现貌似没有 顺手些了一个 大致思路是: 传入根节点,然后依次循环其子节点推入到栈中, 当推入的节点没有子节点的时候(叶子)或者所有子节点均已经遍历过后(上一次遍历的节点是该 ...