- 浏览: 726106 次
- 性别:
- 来自: 宁波
文章分类
- 全部博客 (125)
- 软件开发 (17)
- java (32)
- js (2)
- jsp (1)
- struts2 (1)
- jquery (4)
- oracle (12)
- 程序员 (2)
- 三星i9300 联通版 root (1)
- easyui (2)
- DOM4J (2)
- 哲学 (1)
- ftp (1)
- oracle每日一学 (2)
- spring (4)
- jquery每日一学 (5)
- shiro (4)
- ITextRenderer (1)
- shiro标签 (1)
- mysql (1)
- mysql每日一学 (4)
- 分词 (1)
- vtiger crm (1)
- IkAnalyzer (1)
- jsoup (1)
- 多线程 (1)
- quartz (1)
- ubuntu (2)
- gradle学习笔记 (1)
- node.js (1)
- ajax (1)
- mybatis (1)
- cas (2)
- cxf (1)
- jqgrid (1)
- 开发工具破解 (1)
最新评论
-
氵每市蜃木娄:
使用过后,移动滚动条,非冻结的列,表头不见了。
easyui datagrid 右冻结 -
18335864773:
推荐用pageoffice组件打开文档,pageoffice ...
java word导出 -
xiaoliuf4565:
用过之后中文可以换行,但是现在编程了英文和数字不换行了脑壳痛
freemarker+ITextRenderer 生成html转pdf -
A741841403:
Error:(275, 29) java: 无法访问com.l ...
freemarker+ITextRenderer 生成html转pdf -
A741841403:
楼主你好,我想问下,如何在maven中使用你的jar包呢
freemarker+ITextRenderer 生成html转pdf
java 按照每周分组
- 博客分类:
- java
本例的工作应用是导入excel excel的列里有一个发布日期
时间格式这种 2014/5/30 年月日的
导入技术用的poi
实现的效果需求是 按照 发布日期进行每周分组 一周的数据为星期一到星期五 如果某天没数据就留空(因为考虑到那几天可能是节假日没有出数据) 然后将分组后的数据 每组数据插入到资讯表,按照一条资讯显示一周记录的形式 在网站上呈现出来
所以下面的效果图里会显示 填充后的 数据 即将一周里没有数据的那天 用空值填充
excel读取工具类 相关poi工具包 网上很多这里就不分享了
业务实体bean
效果图:
我上传了测试用的excel 文件 大家可以看看效果
有什么问题大家加我qq 讨论 6637152
apche shiro权限框架 技术讨论群 欢迎您的加入 208316279
没有 啊 我是根据列头名称来读取的 根据不同的列头来读取的 ,不需要改代码的
在循环中 entry.getValue().get("列头名"))这样就能获取的
看来你是没有仔细看我的代码
哈哈 有点复杂 实现起来代码有点多 这是测试的demo代码 正式的工作应用封装的好点
咋了么
咋了
时间格式这种 2014/5/30 年月日的
导入技术用的poi
实现的效果需求是 按照 发布日期进行每周分组 一周的数据为星期一到星期五 如果某天没数据就留空(因为考虑到那几天可能是节假日没有出数据) 然后将分组后的数据 每组数据插入到资讯表,按照一条资讯显示一周记录的形式 在网站上呈现出来
所以下面的效果图里会显示 填充后的 数据 即将一周里没有数据的那天 用空值填充
package com.test; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.sql.Timestamp; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import net.sf.json.JSONObject; import ztxx.cl.entity.AreaCopperInfos; import ztxx.common.util.ExcelUtil; import ztxx.common.util.StringUtils; import ztxx.common.util.ExcelUtil.GroupBy; public class POIexceltest { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub Map<Integer, JSONObject> content = new LinkedHashMap<Integer, JSONObject>(); File file = new File("d:/test/测试.xlsx"); FileInputStream fi = new FileInputStream(file); if (file.getName().toLowerCase().endsWith("xls")) { content = ExcelUtil.readExcelContent(fi, 1); } else if (file.getName().toLowerCase().endsWith("xlsx")) { content = ExcelUtil.read2007Excels(fi, 1); } List<AreaCopperInfos> listTsts = new ArrayList<AreaCopperInfos>(); for (Map.Entry<Integer, JSONObject> entry : content.entrySet()) { AreaCopperInfos aci = new AreaCopperInfos(); aci.setAudit(1); if (StringUtils.stringIsNull(entry.getValue().get("品名")).equals("")) { continue; } aci.setChange(Double.valueOf(StringUtils.stringIsNull(entry .getValue().get("涨跌")))); aci.setCommodity(StringUtils.stringIsNull(entry.getValue() .get("品名"))); aci.setFold(Double.valueOf(StringUtils.stringIsNull(entry .getValue().get("均价")))); aci.setInfTypeId(11); aci.setMaterial(StringUtils .stringIsNull(entry.getValue().get("材质"))); // System.out.println("材质:"+StringUtils.stringIsNull(entry.getValue().get( // "材质"))); aci.setMaximumprice(Double.valueOf(StringUtils.stringIsNull(entry .getValue().get("最高价")))); aci.setMinimumtprice(Double.valueOf(StringUtils.stringIsNull(entry .getValue().get("最低价")))); aci.setOg(StringUtils.stringIsNull(entry.getValue().get("产地/牌号"))); String fbsj = StringUtils .stringIsNull(entry.getValue().get("发布日期")); // System.out.println("发布日期:"+fbsj); String dateString = fbsj; Date date = null; try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); date = sdf.parse(dateString); } catch (ParseException e) { System.out.println(e.getMessage()); } // System.out.println("星期code:"+getWeekOfDate(date)); Timestamp ts = new Timestamp(System.currentTimeMillis()); String tsStr = fbsj + " 00:00:00"; try { ts = Timestamp.valueOf(tsStr); } catch (Exception e) { e.printStackTrace(); } aci.setReleaseDate(ts); aci .setRemarks(StringUtils.stringIsNull(entry.getValue().get( "备注"))); aci.setUnit(StringUtils.stringIsNull(entry.getValue().get("单位"))); listTsts.add(aci); } System.out.println("导入完成:" + listTsts.size()); List<AreaCopperInfos> listTstsNew = new ArrayList<AreaCopperInfos>(); // 去除重复发布日期 listTstsNew = removeDuplicate(listTsts); System.out.println("去除重复发布日期后的list元素数量:" + listTstsNew.size()); // 按照升序排 sortClass sort = new sortClass(); Collections.sort(listTstsNew, sort); for (int i = 0; i < listTstsNew.size(); i++) { AreaCopperInfos temp = (AreaCopperInfos) listTstsNew.get(i); // System.out.println("品名:" + temp.getCommodity() + ",发布日期:" // + temp.getReleaseDate()); } final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Map<String, List<AreaCopperInfos>> mapMonth = new HashMap<String, List<AreaCopperInfos>>(); mapMonth = ExcelUtil.group(listTstsNew, new GroupBy<String>() { @Override public String groupby(Object obj) { AreaCopperInfos d = (AreaCopperInfos) obj; String fbstr = sdf.format(d.getReleaseDate()); String fbstrArray[] = fbstr.split("-", -1); String yue = fbstrArray[0] + fbstrArray[1]; return yue; // 分组依据为发布时间 } }); System.out.println("按年月分组完成" + mapMonth.size()); Set<String> key = null; if (null != mapMonth) { key = mapMonth.keySet(); } // Set<Long> key = map.keySet(); if (null != key) { for (Iterator it = key.iterator(); it.hasNext();) { // 组循环 String s = (String) it.next(); List<AreaCopperInfos> laci = mapMonth.get(s); // 抽出每组里的地区铜价集合数据 Map<Integer, List<AreaCopperInfos>> mapWeek = new HashMap<Integer, List<AreaCopperInfos>>(); // 按照每周分组 mapWeek = ExcelUtil.group(laci, new GroupBy<Integer>() { @Override public Integer groupby(Object obj) { AreaCopperInfos d = (AreaCopperInfos) obj; SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd"); String str = sdf.format(d.getReleaseDate()); Integer weekValue = getWeek(str); return weekValue; // 分组依据为发布时间 } }); System.out.println("按照每周分组完成,该月一共有几周:" + mapWeek.size()); Set<Integer> keyWeek = null; if (null != mapWeek) { keyWeek = mapWeek.keySet(); } for (Iterator itWeek = keyWeek.iterator(); itWeek.hasNext();) { // 循环每组里的星期 Integer zhou = (Integer) itWeek.next(); List<AreaCopperInfos> laciWeek = mapWeek.get(zhou); Map<String, AreaCopperInfos> maplistsa = new LinkedHashMap<String, AreaCopperInfos>(); LinkedList<Map<String, AreaCopperInfos>> allWeek = new LinkedList<Map<String, AreaCopperInfos>>(); for (int k = 0; k < laciWeek.size(); k++) { System.out.println("周里面的铜信息:" + laciWeek.get(k).getCommodity() + ":" + laciWeek.get(k).getReleaseDate() + getWeek(laciWeek.get(k).getReleaseDate())); maplistsa.put(getWeek(laciWeek.get(k).getReleaseDate()), laciWeek.get(k)); } if(laciWeek.size()<5&&laciWeek.size()>=1){ //做填充 System.out.println("填充后:"); Map<String, AreaCopperInfos> map = new LinkedHashMap<String, AreaCopperInfos>(); map.put("星期一", maplistsa.get("星期一")); map.put("星期二", maplistsa.get("星期二")); map.put("星期三", maplistsa.get("星期三")); map.put("星期四", maplistsa.get("星期四")); map.put("星期五", maplistsa.get("星期五")); allWeek.add(map); for(int i=0;i<allWeek.size();i++){ if(null!=allWeek.get(i).get("星期一")){ if(null!=allWeek.get(i).get("星期一").getCommodity()){ System.out.println("周里面的铜信息:" + allWeek.get(i).get("星期一").getCommodity() + ":" + allWeek.get(i).get("星期一").getReleaseDate() + getWeek(allWeek.get(i).get("星期一") .getReleaseDate())); } }else{ System.out.println("周里面的铜信息:"+"空的"); } if(null!=allWeek.get(i).get("星期二")){ if(null!=allWeek.get(i).get("星期二").getCommodity()){ System.out.println("周里面的铜信息:" + allWeek.get(i).get("星期二").getCommodity() + ":" + allWeek.get(i).get("星期二").getReleaseDate() + getWeek(allWeek.get(i).get("星期二") .getReleaseDate())); } }else{ System.out.println("周里面的铜信息:"+"空的"); } if(null!=allWeek.get(i).get("星期三")){ if(null!=allWeek.get(i).get("星期三").getCommodity()){ System.out.println("周里面的铜信息:" + allWeek.get(i).get("星期三").getCommodity() + ":" + allWeek.get(i).get("星期三").getReleaseDate() + getWeek(allWeek.get(i).get("星期三") .getReleaseDate())); } }else{ System.out.println("周里面的铜信息:"+"空的"); } if(null!=allWeek.get(i).get("星期四")){ if(null!=allWeek.get(i).get("星期四").getCommodity()){ System.out.println("周里面的铜信息:" + allWeek.get(i).get("星期四").getCommodity() + ":" + allWeek.get(i).get("星期四").getReleaseDate() + getWeek(allWeek.get(i).get("星期四") .getReleaseDate())); } }else{ System.out.println("周里面的铜信息:"+"空的"); } if(null!=allWeek.get(i).get("星期五")){ if(null!=allWeek.get(i).get("星期五").getCommodity()){ System.out.println("周里面的铜信息:" + allWeek.get(i).get("星期五").getCommodity() + ":" + allWeek.get(i).get("星期五").getReleaseDate() + getWeek(allWeek.get(i).get("星期五") .getReleaseDate())); } }else{ System.out.println("周里面的铜信息:"+"空的"); } } } System.out.println("第" + zhou + "周"); } } } } public static List<AreaCopperInfos> removeDuplicate( List<AreaCopperInfos> list) { for (int i = 0; i < list.size() - 1; i++) { for (int j = list.size() - 1; j > i; j--) { if (list.get(j).getReleaseDate().equals( list.get(i).getReleaseDate())) { list.remove(j); } } } return list; } public static int getWeek(String str) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date date = null; try { date = sdf.parse(str); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } Calendar calendar = Calendar.getInstance(); calendar.setTime(date); // 第几周 int week = calendar.get(Calendar.WEEK_OF_MONTH); // 第几天,从周日开始 int day = calendar.get(Calendar.DAY_OF_WEEK); return week; } /** * 根据日期获得星期 * * @param date * @return */ public static String getWeekOfDate(Date date) { String[] weekDaysName = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; String[] weekDaysCode = { "0", "1", "2", "3", "4", "5", "6" }; Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int intWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1; return weekDaysCode[intWeek]; } // 根据日期取得星期几 public static String getWeek(Date date) { String[] weeks = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; Calendar cal = Calendar.getInstance(); cal.setTime(date); int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1; if (week_index < 0) { week_index = 0; } return weeks[week_index]; } /** * 判断两个日期是否为同一周 * * @param date1 * @param date2 * @return */ public static boolean isSameDate(String date1, String date2) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date d1 = null; Date d2 = null; try { d1 = format.parse(date1); d2 = format.parse(date2); } catch (Exception e) { e.printStackTrace(); } Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTime(d1); cal2.setTime(d2); int subYear = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR); // subYear==0,说明是同一年 if (subYear == 0) { if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2 .get(Calendar.WEEK_OF_YEAR)) return true; } // 例子:cal1是"2005-1-1",cal2是"2004-12-25" // java对"2004-12-25"处理成第52周 // "2004-12-26"它处理成了第1周,和"2005-1-1"相同了 // 大家可以查一下自己的日历 // 处理的比较好 // 说明:java的一月用"0"标识,那么12月用"11" else if (subYear == 1 && cal2.get(Calendar.MONTH) == 11) { if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2 .get(Calendar.WEEK_OF_YEAR)) return true; } // 例子:cal1是"2004-12-31",cal2是"2005-1-1" else if (subYear == -1 && cal1.get(Calendar.MONTH) == 11) { if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2 .get(Calendar.WEEK_OF_YEAR)) return true; } return false; } }
package com.test; import java.util.Comparator; import ztxx.cl.entity.AreaCopperInfos; public class sortClass implements Comparator{ public int compare(Object arg0,Object arg1){ AreaCopperInfos user0 = (AreaCopperInfos)arg0; AreaCopperInfos user1 = (AreaCopperInfos)arg1; int flag = user0.getReleaseDate().compareTo(user1.getReleaseDate()); //System.out.println(flag); return flag; } }
excel读取工具类 相关poi工具包 网上很多这里就不分享了
package ztxx.common.util; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.sql.Timestamp; import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import net.sf.json.JSONObject; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFDataFormat; import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import ztxx.cl.entity.AreaCopperInfos; public class ExcelUtil { private static POIFSFileSystem fs; private static HSSFWorkbook wb; private static HSSFSheet sheet; private static HSSFRow row; private static FileInputStream input; private static String[] excleTitle; public static boolean isNum(String str) { return str.matches("^[-+]?(([0-9]+)([.]([0-9]+))?|([.]([0-9]+))?)$"); } /** * 根据文件路径读取Excel数据内容 返回map * * @param excelPath * @return */ public static Map<Integer, JSONObject> readExcelContent(String excelPath) { Map<Integer, JSONObject> contentJson = new LinkedHashMap<Integer, JSONObject>(); String excelStr = "";// excel 内容 try { input = new FileInputStream(new File(excelPath)); fs = new POIFSFileSystem(input); wb = new HSSFWorkbook(fs); sheet = wb.getSheetAt(0); int rowNum = sheet.getLastRowNum(); // 得到总行数 row = sheet.getRow(0);// 得到标题的内容对象。 int colNum = row.getPhysicalNumberOfCells();// 得到每行的列数。 excleTitle = new String[colNum]; for (int i = 0; i < colNum; i++) { excleTitle[i] = getStringCellValue(row.getCell((short) i)); } // 正文内容应该从第二行开始,第一行为表头的标题 for (int i = 1; i <= rowNum; i++) { row = sheet.getRow(i); int j = 0; while (j < colNum) { String v = ""; if (j + 1 == colNum) { String vs = getStringCellValue(row.getCell((short) j)) .trim(); if (vs.indexOf(".") > -1) { if (isNum(vs)) { // 是否是数字 if (vs.endsWith("0")) { v = vs.substring(0, vs.indexOf(".")); } } else { v = vs.trim(); } } else { v = vs.trim(); } excelStr += v; } else { String vs = getStringCellValue(row.getCell((short) j)) .trim() + "&"; if (vs.indexOf(".") > -1) { if (isNum(vs)) { // 是否是数字 if (vs.endsWith("0")) { // 处理用poi读取excel整数后面加.0的格式化 v = vs.substring(0, vs.indexOf(".")); } } else { v = vs.trim(); } } else { v = vs.trim(); } excelStr += v; } j++; } String excelstrArray[] = excelStr.split("&", -1); // 每行数据 Map<String, String> params = new LinkedHashMap<String, String>(); for (int k = 0; k < excelstrArray.length; k++) { params.put(excleTitle[k], excelstrArray[k]); } JSONObject jsonObject = JSONObject.fromObject(params); contentJson.put(i, jsonObject); // content.put(i, excelStr); excelStr = ""; } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (input != null) { input.close(); } } catch (IOException e) { e.printStackTrace(); } } return contentJson; } /** * 根据文件流读取Excel数据内容 返回map 2003 * * @param input * @param count从第几行开始读 * @return */ public static Map<Integer, JSONObject> readExcelContent(InputStream input, int count) {// 读取Excel数据内容 Map<Integer, JSONObject> contentJson = new LinkedHashMap<Integer, JSONObject>(); String excelStr = "";// excel 内容 try { fs = new POIFSFileSystem(input); wb = new HSSFWorkbook(fs); sheet = wb.getSheetAt(0); int rowNum = sheet.getLastRowNum(); // 得到总行数 row = sheet.getRow(0);// 得到标题的内容对象。 int colNum = row.getPhysicalNumberOfCells();// 得到每行的列数。 excleTitle = new String[colNum]; for (int i = 0; i < colNum; i++) { excleTitle[i] = getStringCellValue(row.getCell(i)); } // 正文内容应该从第二行开始,第一行为表头的标题 for (int i = count; i <= rowNum; i++) { row = sheet.getRow(i); int j = 0; while (j < colNum) { String v = ""; if (j + 1 == colNum) { String vs = getStringCellValue(row.getCell(j)).trim(); if (vs.indexOf(".") > -1) { if (isNum(vs)) { // 是否是数字 if (vs.endsWith("0")) { v = vs.substring(0, vs.indexOf(".")); } } else { v = vs.trim(); } } else { v = vs.trim(); } excelStr += v; } else { String vs = getStringCellValue(row.getCell(j)).trim() + "&"; if (vs.indexOf(".") > -1) { if (isNum(vs)) { // 是否是数字 if (vs.endsWith("0")) { // 处理用poi读取excel整数后面加.0的格式化 v = vs.substring(0, vs.indexOf(".")); } } else { v = vs.trim(); } } else { v = vs.trim(); } excelStr += v; } j++; } String excelstrArray[] = excelStr.split("&", -1); // 每行数据 Map<String, String> params = new LinkedHashMap<String, String>(); for (int k = 0; k < excelstrArray.length; k++) { params.put(excleTitle[k], excelstrArray[k]); } JSONObject jsonObject = JSONObject.fromObject(params); contentJson.put(i, jsonObject); // content.put(i, excelStr); excelStr = ""; } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (input != null) { input.close(); } } catch (IOException e) { e.printStackTrace(); } } return contentJson; } /** * 读取Office 2007 excel * * @param input * @param count * 从第几行开始读 * @return * @throws IOException */ public static Map<Integer, JSONObject> read2007Excels(InputStream input, int count) throws IOException { Map<Integer, JSONObject> contentJson = new LinkedHashMap<Integer, JSONObject>(); // 构造 XSSFWorkbook 对象,strPath 传入文件路径 XSSFWorkbook xwb = new XSSFWorkbook(input); // 读取第一章表格内容 XSSFSheet sheet = xwb.getSheetAt(0); XSSFRow row = null; XSSFCell cell = null; XSSFRow headerrow = sheet.getRow(0); // 表头 得到标题的内容对象 int colNum = headerrow.getPhysicalNumberOfCells();// 得到每行的列数。 excleTitle = new String[colNum]; for (int i = 0; i < colNum; i++) { excleTitle[i] = getStringCellValue(headerrow.getCell((short) i)); } // System.out.println(sheet.getPhysicalNumberOfRows()); // 循环内容项 不循环标题 所以+1 for (int i = sheet.getFirstRowNum() + count; i <= sheet .getPhysicalNumberOfRows(); i++) { row = sheet.getRow(i); if (row == null) { continue; } List<String> linked = new LinkedList<String>(); for (int j = row.getFirstCellNum(); j < row.getLastCellNum(); j++) { Object value = null; cell = row.getCell(j); if (null != cell) { value = getStringCellValue(cell); } linked.add(StringUtils.stringIsNull(value)); } Map<String, String> params = new LinkedHashMap<String, String>(); for (int j = 0; j < linked.size(); j++) { params.put(excleTitle[j], linked.get(j)); } JSONObject jsonObject = JSONObject.fromObject(params); contentJson.put(i, jsonObject); } return contentJson; } /** * 根据(字节串(或叫字节数组)变成输入流的形式)读取Excel数据内容 返回map * * @param input * @return */ public static Map<Integer, JSONObject> readExcelContent( ByteArrayInputStream input) {// 读取Excel数据内容 // Map<Integer, String> content = new HashMap<Integer, String>(); Map<Integer, JSONObject> contentJson = new LinkedHashMap<Integer, JSONObject>(); String excelStr = "";// excel 内容 try { // ByteArrayInputStream is = new ByteArrayInputStream( new // byte[1000]); fs = new POIFSFileSystem(input); wb = new HSSFWorkbook(fs); sheet = wb.getSheetAt(0); int rowNum = sheet.getLastRowNum(); // 得到总行数 row = sheet.getRow(0);// 得到标题的内容对象。 int colNum = row.getPhysicalNumberOfCells();// 得到每行的列数。 excleTitle = new String[colNum]; for (int i = 0; i < colNum; i++) { excleTitle[i] = getStringCellValue(row.getCell((short) i)); } // 正文内容应该从第二行开始,第一行为表头的标题 for (int i = 1; i <= rowNum; i++) { row = sheet.getRow(i); int j = 0; while (j < colNum) { String v = ""; if (j + 1 == colNum) { String vs = getStringCellValue(row.getCell((short) j)) .trim(); if (vs.indexOf(".") > -1) { if (isNum(vs)) { // 是否是数字 if (vs.endsWith("0")) { v = vs.substring(0, vs.indexOf(".")); } } else { v = vs.trim(); } } else { v = vs.trim(); } excelStr += v; } else { String vs = getStringCellValue(row.getCell((short) j)) .trim() + "&"; if (vs.indexOf(".") > -1) { if (isNum(vs)) { // 是否是数字 if (vs.endsWith("0")) { // 处理用poi读取excel整数后面加.0的格式化 v = vs.substring(0, vs.indexOf(".")); } } else { v = vs.trim(); } } else { v = vs.trim(); } excelStr += v; } j++; } String excelstrArray[] = excelStr.split("&", -1); // 每行数据 Map<String, String> params = new LinkedHashMap<String, String>(); for (int k = 0; k < excelstrArray.length; k++) { params.put(excleTitle[k], excelstrArray[k]); } JSONObject jsonObject = JSONObject.fromObject(params); contentJson.put(i, jsonObject); // content.put(i, excelStr); excelStr = ""; } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (input != null) { input.close(); } } catch (IOException e) { e.printStackTrace(); } } return contentJson; } /** * 获取单元格数据内容为字符串类型的数据97-2003 * * @param cell * @return */ private static String getStringCellValue(HSSFCell cell) { String strCell = ""; if (cell != null) { switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_STRING: strCell = cell.getStringCellValue(); break; case HSSFCell.CELL_TYPE_NUMERIC: // strCell = String.valueOf(cell.getNumericCellValue()); if (HSSFDateUtil.isCellDateFormatted(cell)) {// 处理日期格式、时间格式 SimpleDateFormat sdf = null; if (cell.getCellStyle().getDataFormat() == HSSFDataFormat .getBuiltinFormat("h:mm")) { sdf = new SimpleDateFormat("HH:mm"); } else {// 日期 sdf = new SimpleDateFormat("yyyy-MM-dd"); } Date date = cell.getDateCellValue(); strCell = sdf.format(date); } else if (cell.getCellStyle().getDataFormat() == 58) { // 处理自定义日期格式:m月d日(通过判断单元格的格式id解决,id的值是58) SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); double value = cell.getNumericCellValue(); Date date = org.apache.poi.ss.usermodel.DateUtil .getJavaDate(value); strCell = sdf.format(date); } else { double value = cell.getNumericCellValue(); CellStyle style = cell.getCellStyle(); DecimalFormat format = new DecimalFormat(); String temp = style.getDataFormatString(); // 单元格设置成常规 if (temp.equals("General")) { format.applyPattern("#"); } strCell = format.format(value); } break; case HSSFCell.CELL_TYPE_BOOLEAN: strCell = String.valueOf(cell.getBooleanCellValue()); break; case HSSFCell.CELL_TYPE_BLANK: strCell = ""; break; default: cell.setCellType(Cell.CELL_TYPE_STRING); // 如果出现意外类型就先设置为string类型否则将会报数据类型异常 strCell = cell.getStringCellValue(); // strCell = ""; break; } } if (strCell.equals("") || strCell == null) { return ""; } if (cell == null) { return ""; } return strCell; } /** * 获取单元格数据内容为日期类型的数据 * * @param cell * @return */ private static String getDateCellValue(HSSFCell cell) { String result = ""; try { int cellType = cell.getCellType(); if (cellType == HSSFCell.CELL_TYPE_NUMERIC) { Date date = cell.getDateCellValue(); result = (date.getYear() + 1900) + "-" + (date.getMonth() + 1) + "-" + date.getDate(); } else if (cellType == HSSFCell.CELL_TYPE_STRING) { String date = getStringCellValue(cell); result = date.replaceAll("[年月]", "-").replace("日", "").trim(); } else if (cellType == HSSFCell.CELL_TYPE_BLANK) { result = ""; } } catch (Exception e) { System.out.println("日期格式不正确!"); e.printStackTrace(); } return result; } /** * 根据byte数组,生成文件 */ public static void getFile(byte[] bfile, String filePath, String fileName) { BufferedOutputStream bos = null; FileOutputStream fos = null; File file = null; try { File dir = new File(filePath); if (!dir.exists() && dir.isDirectory()) {// 判断文件目录是否存在 dir.mkdirs(); } file = new File(filePath + "\\" + fileName); fos = new FileOutputStream(file); bos = new BufferedOutputStream(fos); bos.write(bfile); } catch (Exception e) { e.printStackTrace(); } finally { if (bos != null) { try { bos.close(); } catch (IOException e1) { e1.printStackTrace(); } } if (fos != null) { try { fos.close(); } catch (IOException e1) { e1.printStackTrace(); } } } } // 从byte[]转file public static File getFileFromBytes(byte[] b, String outputFile) { BufferedOutputStream stream = null; File file = null; try { file = new File(outputFile); if (!file.exists() && file.isDirectory()) {// 判断文件目录是否存在 file.mkdirs(); // mkdirs() 可以在不存在的目录中创建文件夹。诸如:a\\b,既可以创建多级目录。 } FileOutputStream fstream = new FileOutputStream(file); stream = new BufferedOutputStream(fstream); stream.write(b); } catch (Exception e) { e.printStackTrace(); } finally { if (stream != null) { try { stream.close(); } catch (IOException e1) { e1.printStackTrace(); } } } return file; } /** * 读取Office 2007 excel * */ private static Map<Integer, JSONObject> read2007Excels(File file) throws IOException { Map<Integer, JSONObject> contentJson = new LinkedHashMap<Integer, JSONObject>(); // 构造 XSSFWorkbook 对象,strPath 传入文件路径 XSSFWorkbook xwb = new XSSFWorkbook(new FileInputStream(file)); // 读取第一章表格内容 XSSFSheet sheet = xwb.getSheetAt(0); Object value = null; XSSFRow row = null; XSSFCell cell = null; XSSFRow headerrow = sheet.getRow(0); // 表头 得到标题的内容对象 int colNum = headerrow.getPhysicalNumberOfCells();// 得到每行的列数。 excleTitle = new String[colNum]; for (int i = 0; i < colNum; i++) { excleTitle[i] = getStringCellValue(headerrow.getCell((short) i)); } // System.out.println(sheet.getPhysicalNumberOfRows()); // 循环内容项 不循环标题 所以+1 for (int i = sheet.getFirstRowNum() + 1; i <= sheet .getPhysicalNumberOfRows(); i++) { row = sheet.getRow(i); if (row == null) { continue; } List<String> linked = new LinkedList<String>(); for (int j = row.getFirstCellNum(); j < row.getLastCellNum(); j++) { cell = row.getCell(j); if (null != cell) { value = getStringCellValue(cell); } linked.add(StringUtils.stringIsNull(value)); } Map<String, String> params = new LinkedHashMap<String, String>(); for (int j = 0; j < linked.size(); j++) { params.put(excleTitle[j], linked.get(j)); } JSONObject jsonObject = JSONObject.fromObject(params); contentJson.put(i, jsonObject); } return contentJson; } /** * 获取单元格数据内容为字符串类型的数据 excel2007 * * @param cell * @return */ public static String getStringCellValue(XSSFCell cell) { String strCell = ""; // if(cell.equals("发布日期")){ // return String.valueOf(cell.getDateCellValue()); // } switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_STRING: strCell = cell.getStringCellValue(); break; case HSSFCell.CELL_TYPE_NUMERIC: // strCell = String.valueOf(cell.getNumericCellValue()); // break; if (HSSFDateUtil.isCellDateFormatted(cell)) {// 处理日期格式、时间格式 SimpleDateFormat sdf = null; if (cell.getCellStyle().getDataFormat() == HSSFDataFormat .getBuiltinFormat("h:mm")) { sdf = new SimpleDateFormat("HH:mm"); } else {// 日期 sdf = new SimpleDateFormat("yyyy-MM-dd"); } Date date = cell.getDateCellValue(); strCell = sdf.format(date); } else if (cell.getCellStyle().getDataFormat() == 58) { // 处理自定义日期格式:m月d日(通过判断单元格的格式id解决,id的值是58) SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); double value = cell.getNumericCellValue(); Date date = org.apache.poi.ss.usermodel.DateUtil .getJavaDate(value); strCell = sdf.format(date); } else { double value = cell.getNumericCellValue(); CellStyle style = cell.getCellStyle(); DecimalFormat format = new DecimalFormat(); String temp = style.getDataFormatString(); // 单元格设置成常规 if (temp.equals("General")) { format.applyPattern("#"); } strCell = format.format(value); } break; case HSSFCell.CELL_TYPE_BOOLEAN: strCell = String.valueOf(cell.getBooleanCellValue()); break; case HSSFCell.CELL_TYPE_BLANK: strCell = ""; break; default: if (HSSFDateUtil.isCellDateFormatted(cell)) {// 处理日期格式、时间格式 SimpleDateFormat sdf = null; if (cell.getCellStyle().getDataFormat() == HSSFDataFormat .getBuiltinFormat("h:mm")) { sdf = new SimpleDateFormat("HH:mm"); } else {// 日期 sdf = new SimpleDateFormat("yyyy-MM-dd"); } Date date = cell.getDateCellValue(); strCell = sdf.format(date); } else if (cell.getCellStyle().getDataFormat() == 58) { // 处理自定义日期格式:m月d日(通过判断单元格的格式id解决,id的值是58) SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); double value = cell.getNumericCellValue(); Date date = org.apache.poi.ss.usermodel.DateUtil .getJavaDate(value); strCell = sdf.format(date); } else { cell.setCellType(Cell.CELL_TYPE_STRING); strCell = cell.getStringCellValue(); } break; } if (strCell.equals("") || strCell == null) { return ""; } if (cell == null) { return ""; } return strCell; } /** * 获得指定文件的byte数组 */ public static byte[] getBytes(String filePath) { byte[] buffer = null; try { File file = new File(filePath); FileInputStream fis = new FileInputStream(file); ByteArrayOutputStream bos = new ByteArrayOutputStream(1000); byte[] b = new byte[1000]; int n; while ((n = fis.read(b)) != -1) { bos.write(b, 0, n); } fis.close(); bos.close(); buffer = bos.toByteArray(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return buffer; } public static void main(String args[]) throws IOException { Map<Integer, JSONObject> content = new LinkedHashMap<Integer, JSONObject>(); File f = new File("D://test//铜价导入模版.xlsx"); FileInputStream input = null; try { input = new FileInputStream(f); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } String filename = f.getName(); if (filename.toLowerCase().endsWith("xls")) { content = ExcelUtil.readExcelContent(input, 1); } else if (filename.toLowerCase().endsWith("xlsx")) { content = ExcelUtil.read2007Excels(input, 1); } List<AreaCopperInfos> listAci = new ArrayList<AreaCopperInfos>(); for (Map.Entry<Integer, JSONObject> entry : content.entrySet()) { AreaCopperInfos aci = new AreaCopperInfos(); aci.setAudit(1); aci.setChange(Double.valueOf(StringUtils.stringIsNull(entry .getValue().get("涨跌")))); aci.setCommodity(StringUtils.stringIsNull(entry.getValue() .get("品名"))); aci.setFold(Double.valueOf(StringUtils.stringIsNull(entry .getValue().get("均价")))); aci.setInfTypeId(129); aci.setMaterial(StringUtils .stringIsNull(entry.getValue().get("材质"))); aci.setMaximumprice(Double.valueOf(StringUtils.stringIsNull(entry .getValue().get("最高价")))); aci.setMinimumtprice(Double.valueOf(StringUtils.stringIsNull(entry .getValue().get("最低价")))); aci.setOg(StringUtils.stringIsNull(entry.getValue().get("产地/牌号"))); String fbsj = StringUtils .stringIsNull(entry.getValue().get("发布日期")); Timestamp ts = new Timestamp(System.currentTimeMillis()); String tsStr = fbsj + " 00:00:00"; try { ts = Timestamp.valueOf(tsStr); // System.out.println(ts); } catch (Exception e) { e.printStackTrace(); } aci.setReleaseDate(ts); aci .setRemarks(StringUtils.stringIsNull(entry.getValue().get( "备注"))); aci .setUnit(StringUtils.stringIsNull(entry.getValue().get( "产地/牌号"))); aci.setInfosid(0); listAci.add(aci); // System.out.println(entry.getValue().get("品名")); // System.out.println(entry.getValue().get("材质")); // System.out.println(entry.getValue().get("最低价")); // System.out.println(entry.getValue().get("最高价")); // System.out.println(entry.getValue().get("均价")); // System.out.println(entry.getValue().get("发布日期")); // System.out.println("---------------------"); } // 进行分组 Map<Long, List<AreaCopperInfos>> map = group(listAci, new GroupBy<Long>() { @Override public Long groupby(Object obj) { AreaCopperInfos d = (AreaCopperInfos) obj; return d.getReleaseDate().getTime(); // 分组依据为课程ID } }); Set<Long> key = map.keySet(); for (Iterator it = key.iterator(); it.hasNext();) { Long s = (Long) it.next(); System.out.println(map.get(s)); } // //Group g=new Group(); // List<GroupContinerAreaCopperInfos> // lgac=Group.groupAreaCopperInfos(listAci); // // System.out.println("分组完成"); // for(int i=0;i<lgac.size();i++){ // System.out.println(lgac.get(i).getReleaseDate()); // } } /** * 分組依據接口,用于集合分組時,獲取分組依據 * * @author ZhangLiKun * @title GroupBy * @date 2013-4-23 */ public interface GroupBy<T> { T groupby(Object obj); } /** * * @param colls * @param gb * @return */ public static final <T extends Comparable<T>, D> Map<T, List<D>> group( Collection<D> colls, GroupBy<T> gb) { if (colls == null || colls.isEmpty()) { System.out.println("分組集合不能為空!"); return null; } if (gb == null) { System.out.println("分組依據接口不能為Null!"); return null; } Iterator<D> iter = colls.iterator(); Map<T, List<D>> map = new HashMap<T, List<D>>(); while (iter.hasNext()) { D d = iter.next(); T t = gb.groupby(d); if (map.containsKey(t)) { map.get(t).add(d); } else { List<D> list = new ArrayList<D>(); list.add(d); map.put(t, list); } } return map; } public static List<AreaCopperInfos> removeDuplicate( List<AreaCopperInfos> list) { for (int i = 0; i < list.size() - 1; i++) { for (int j = list.size() - 1; j > i; j--) { if (list.get(j).getReleaseDate().equals( list.get(i).getReleaseDate())) { list.remove(j); } } } return list; } public static int getWeek(String str) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date date = null; try { date = sdf.parse(str); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } Calendar calendar = Calendar.getInstance(); calendar.setTime(date); // 第几周 int week = calendar.get(Calendar.WEEK_OF_MONTH); // 第几天,从周日开始 int day = calendar.get(Calendar.DAY_OF_WEEK); return week; } /** * 根据日期获得星期 * * @param date * @return */ public static String getWeekOfDate(Date date) { String[] weekDaysName = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; String[] weekDaysCode = { "0", "1", "2", "3", "4", "5", "6" }; Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int intWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1; return weekDaysCode[intWeek]; } // 根据日期取得星期几 public static String getWeek(Date date) { String[] weeks = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" }; Calendar cal = Calendar.getInstance(); cal.setTime(date); int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1; if (week_index < 0) { week_index = 0; } return weeks[week_index]; } /** * 判断两个日期是否为同一周 * * @param date1 * @param date2 * @return */ public static boolean isSameDate(String date1, String date2) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date d1 = null; Date d2 = null; try { d1 = format.parse(date1); d2 = format.parse(date2); } catch (Exception e) { e.printStackTrace(); } Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTime(d1); cal2.setTime(d2); int subYear = cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR); // subYear==0,说明是同一年 if (subYear == 0) { if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2 .get(Calendar.WEEK_OF_YEAR)) return true; } // 例子:cal1是"2005-1-1",cal2是"2004-12-25" // java对"2004-12-25"处理成第52周 // "2004-12-26"它处理成了第1周,和"2005-1-1"相同了 // 大家可以查一下自己的日历 // 处理的比较好 // 说明:java的一月用"0"标识,那么12月用"11" else if (subYear == 1 && cal2.get(Calendar.MONTH) == 11) { if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2 .get(Calendar.WEEK_OF_YEAR)) return true; } // 例子:cal1是"2004-12-31",cal2是"2005-1-1" else if (subYear == -1 && cal1.get(Calendar.MONTH) == 11) { if (cal1.get(Calendar.WEEK_OF_YEAR) == cal2 .get(Calendar.WEEK_OF_YEAR)) return true; } return false; } @SuppressWarnings("static-access") public static String getValue(XSSFCell xssfCell) { if (xssfCell.getCellType() == xssfCell.CELL_TYPE_BOOLEAN) { return String.valueOf(xssfCell.getBooleanCellValue()); } else if (xssfCell.getCellType() == xssfCell.CELL_TYPE_NUMERIC) { // DecimalFormat df = new DecimalFormat("#.######"); // String strCell = df.format(xssfCell.getNumericCellValue()); // DecimalFormat df = new DecimalFormat("0"); // String strCell = df.format(xssfCell.getNumericCellValue()); return String.valueOf(xssfCell.getNumericCellValue()); } else { return String.valueOf(xssfCell.getStringCellValue()); } } @SuppressWarnings("static-access") public static String getValue(HSSFCell hssfCell) { if (hssfCell.getCellType() == hssfCell.CELL_TYPE_BOOLEAN) { return String.valueOf(hssfCell.getBooleanCellValue()); } else if (hssfCell.getCellType() == hssfCell.CELL_TYPE_NUMERIC) { if (org.apache.poi.ss.usermodel.DateUtil .isCellDateFormatted(hssfCell)) { // sb.append(SEPARATOR + cell.getDateCellValue()); return String.valueOf(hssfCell.getDateCellValue()); } else { // sb.append(SEPARATOR + cellValue.getNumberValue()); return String.valueOf(hssfCell.getNumericCellValue()); } // return String.valueOf(hssfCell.getNumericCellValue()); // return String.valueOf(hssfCell.getNumericCellValue()); // } else if (hssfCell.getCellType() == hssfCell.CELL_TYPE_STRING) { // return String.valueOf(hssfCell.getStringCellValue()); } else { return String.valueOf(hssfCell.getStringCellValue()); } } }
业务实体bean
package ztxx.cl.entity; import java.sql.Timestamp; /** * AreaCopperInfos entity. @author MyEclipse Persistence Tools */ public class AreaCopperInfos implements java.io.Serializable { // Fields private Integer id; private String commodity; private String material; private Double minimumtprice; private Double maximumprice; private Double fold; private String unit; private Double change; private String og; private Timestamp releaseDate; private String remarks; private Timestamp createdate; private Integer infTypeId; private Integer audit; private Timestamp auditDate; private Timestamp updatetime; private Integer infosid; private String itname; // Constructors /** default constructor */ public AreaCopperInfos() { } /** full constructor */ public AreaCopperInfos(String commodity, String material, Double minimumtprice, Double maximumprice, Double fold, String unit, Double change, String og, Timestamp releaseDate, String remarks, Timestamp createdate, Integer infTypeId, Integer audit, Timestamp auditDate, Timestamp updatetime, Integer infosid) { this.commodity = commodity; this.material = material; this.minimumtprice = minimumtprice; this.maximumprice = maximumprice; this.fold = fold; this.unit = unit; this.change = change; this.og = og; this.releaseDate = releaseDate; this.remarks = remarks; this.createdate = createdate; this.infTypeId = infTypeId; this.audit = audit; this.auditDate = auditDate; this.updatetime = updatetime; this.infosid = infosid; } // Property accessors public Integer getId() { return this.id; } public void setId(Integer id) { this.id = id; } public String getCommodity() { return this.commodity; } public void setCommodity(String commodity) { this.commodity = commodity; } public String getMaterial() { return this.material; } public void setMaterial(String material) { this.material = material; } public Double getMinimumtprice() { return this.minimumtprice; } public void setMinimumtprice(Double minimumtprice) { this.minimumtprice = minimumtprice; } public Double getMaximumprice() { return this.maximumprice; } public void setMaximumprice(Double maximumprice) { this.maximumprice = maximumprice; } public Double getFold() { return this.fold; } public void setFold(Double fold) { this.fold = fold; } public String getUnit() { return this.unit; } public void setUnit(String unit) { this.unit = unit; } public Double getChange() { return this.change; } public void setChange(Double change) { this.change = change; } public String getOg() { return this.og; } public void setOg(String og) { this.og = og; } public Timestamp getReleaseDate() { return this.releaseDate; } public void setReleaseDate(Timestamp releaseDate) { this.releaseDate = releaseDate; } public String getRemarks() { return this.remarks; } public void setRemarks(String remarks) { this.remarks = remarks; } public Timestamp getCreatedate() { return this.createdate; } public void setCreatedate(Timestamp createdate) { this.createdate = createdate; } public Integer getInfTypeId() { return this.infTypeId; } public void setInfTypeId(Integer infTypeId) { this.infTypeId = infTypeId; } public Integer getAudit() { return this.audit; } public void setAudit(Integer audit) { this.audit = audit; } public Timestamp getAuditDate() { return this.auditDate; } public void setAuditDate(Timestamp auditDate) { this.auditDate = auditDate; } public Timestamp getUpdatetime() { return this.updatetime; } public void setUpdatetime(Timestamp updatetime) { this.updatetime = updatetime; } public Integer getInfosid() { return this.infosid; } public void setInfosid(Integer infosid) { this.infosid = infosid; } public String getItname() { return itname; } public void setItname(String itname) { this.itname = itname; } }
效果图:
我上传了测试用的excel 文件 大家可以看看效果
有什么问题大家加我qq 讨论 6637152
apche shiro权限框架 技术讨论群 欢迎您的加入 208316279
评论
8 楼
zqb666kkk
2014-06-10
tonybin_0220 写道
读取的excel列固定,发生改变还要修改代码.
没有 啊 我是根据列头名称来读取的 根据不同的列头来读取的 ,不需要改代码的
在循环中 entry.getValue().get("列头名"))这样就能获取的
看来你是没有仔细看我的代码
7 楼
tonybin_0220
2014-06-10
读取的excel列固定,发生改变还要修改代码.
6 楼
zqb666kkk
2014-06-09
qq466862016 写道
感觉是给自己看的。。。。
哈哈 有点复杂 实现起来代码有点多 这是测试的demo代码 正式的工作应用封装的好点
5 楼
qq466862016
2014-06-09
感觉是给自己看的。。。。
4 楼
zqb666kkk
2014-06-09
qq466862016 写道
这代码。。。。。
咋了么
3 楼
qq466862016
2014-06-09
这代码。。。。。
2 楼
zqb666kkk
2014-06-09
mfkvfn 写道
这代码。。。
咋了
1 楼
mfkvfn
2014-06-09
这代码。。。
发表评论
-
java word导出
2016-06-30 08:49 2540需要导出的word文档是事先准备好的一个模板,文档数据所在的位 ... -
spring 4mvc下载文件的实现
2016-06-14 13:52 2481网上找到的版本较老 是spring3的 org.spring ... -
cas不同登录页面手动设置不同国际化提示
2016-05-05 09:48 1225<% org.springframework.web. ... -
实用技术解决方案博客地址记录
2016-04-14 10:35 540Jquery 将表单序列化为Json对象:http://www ... -
如果实现类似微信附近的人功能
2016-01-13 10:09 2395如果实现类似微信附近的人功能: 第一种可以使用redis-ge ... -
cxf+wss4j+mysql webservice 加密服务开发
2015-11-04 10:02 2921我采用的是cxf 加密端用的 WSS4J 服务端查询数据库 ... -
多项目集中权限管理系统 采用cas +shiro+spring mvc+mbatis+bootstrap单点登录
2015-10-13 17:37 10123流程架构图: 这里权限系统也可以理解为cas client ... -
OAuthProblemException{error='unsupported_response_type', description='Invalid re
2015-09-21 18:05 4423OAuthProblemException{error='un ... -
导出数据到excel
2014-12-08 10:10 1356/** * * @param datas 数据行 ... -
java.lang.NoSuchMethodError: org.apache.axiom.soap.SOAPEnvelope.hasFault()Z错误的解决
2014-12-05 14:21 1573axis2 运行报这个错误的原因是 要么缺少 包 ,axiom ... -
spring mvc+shiro的通用权限管理系统
2014-10-23 13:50 26774同志们 我的 spring mvc+shiro的通用权限管理系 ... -
多线程断点下载文件
2014-09-23 15:46 1190所谓多线程断点下载 :就是当某个文件下了一部分后突然断电了,或 ... -
多线程下载文件
2014-09-22 17:27 2126package mutiDownload; import ... -
java按照每周分组 改进版
2014-07-07 16:07 4243之前是按照 先把数据按月分组 然后再按周分组 这样有个问题就是 ... -
java计算链表、数组列表或数组中最大元素
2014-03-09 23:50 2608package com; import java.uti ... -
java 获取数组的最大值和最小值
2014-03-02 22:08 6858package com; public class St ... -
宁波java开发技术群
2014-02-17 09:54 1宁波java开发群 240974225 在宁波做java开发的 ... -
spring mvc +jdbctemplate 返回多表查询List<Bean>
2013-12-27 13:19 17713发现 hibernate做多表查询 是忒麻烦了 Spring ... -
读《大型网站技术架构:核心原理与案例分析》 后感
2013-11-26 10:36 5614大型网站软件系统有比 ... -
java拆分list
2013-11-22 09:21 2128java 将一个list平均拆成十个list,如果 list的 ...
相关推荐
NULL 博文链接:https://skyfar666.iteye.com/blog/2089134
java 集合分组排序帮助类有好的意见可以互相交流不甚感激
java 奇偶分组 java 奇偶分组 java 奇偶分组
主要介绍了Java在Excel中创建多级分组、折叠或展开分组的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
将一群人尽量平均随机分为4组
vue+Java 实现附件分组下载压缩包(csdn)————程序
java实现分组聚合,实现范围(时间、数字)、步长(特殊的范围)和不同值的分组,满足大部分需求
因工作的需要,利用Guave对集合进行分组。这是个最简单的例子,希望对大家有用。
比如数据库查询出来的是每个员工的信息,使用此程序能将各个部门、各个小组进行分类,放入到map中。
主要是介绍在 JDK8中使用 stream 流的 groupingBy 方法源进行最大值分组、最小值分组、平均值分组、统计分组
客户端/服务器程序 登陆能实现java分组聊天 进入不同的房间聊天
根据前台表样已定义好的高级表格,而当前表格的HeaderColumn部份为高级分组,即多层分组列,将我们前所见即所得,点击导出按钮后,直接根据数据的逻辑,自动生成了多层组表的表头部份数据样式。 文件夹中附有源代码...
详细完整的实现 java分组和分页功能 public static final int PAGE_SIZE = 5; // 每页记录数 public static final int GROUP_SIZE = 5; // 每组显示的页数 private List<ClaimVoucher> list;// 要返回的某一页的...
该例子实现了ext的gridpanel多层表头+分组+小计以及与Java后台交互的全代码。还有自适应浏览器大小的功能包括导出excel,里面有注释,可能注释不全。分别为group.jsp,totals.jsp页面。
关于Java中List对象的分页思想-按10个或者n个数对list进行分组
如果正则表达式的内容需要被再次引用,那么需要对正则表达式的内容进行分组
有关Java编写正态分布涉及到的函数!正态分组, 计算组距。
对list分组操作,进行封装。 相对于java8stream流分组操作相对,更好一些。
java 路由分组转发仿真 可成功运行