- 浏览: 737630 次
- 性别:
- 来自: 宁波
-
文章分类
- 全部博客 (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
之前是按照 先把数据按月分组 然后再按周分组 这样有个问题就是 会导致像6月30号这种数据 应该是 跟7月1号 7月2号等分在一组的 但是 按照上次的算法 会被分开 显然这样似乎有点不太好理解
所以这次不做按月分组 直接 利用java里 判断今天是当前年中第几周来做每周分组
excel工具类:
并附上测试的excel文件
所以这次不做按月分组 直接 利用java里 判断今天是当前年中第几周来做每周分组
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/630有问题.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(listTstsNew, 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 = ExcelUtil.getWeekOfYear(d.getReleaseDate()); //一年当中的第几周 return weekValue; // 分组依据为发布时间 } }); //System.out.println("按照每周分组完成,该月一共有几周:" + mapWeek.size()); System.out.println("该年有几周:" + ExcelUtil.getMaxWeekNumOfYear(2014)); 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; } }
excel工具类:
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.GregorianCalendar; 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 = parseExcel(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; // } private static String parseExcel(Cell cell) { String result = new String(); switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_NUMERIC:// 数字类型 //1、判断是否是数值格式 // if(cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){ // short format = cell.getCellStyle().getDataFormat(); // SimpleDateFormat sdf = null; // if(format == 14 || format == 31 || format == 57 || format == 58){ // //日期 // sdf = new SimpleDateFormat("yyyy-MM-dd"); // }else if (format == 20 || format == 32) { // //时间 // sdf = new SimpleDateFormat("HH:mm"); // } // double value = cell.getNumericCellValue(); // Date date = org.apache.poi.ss.usermodel.DateUtil.getJavaDate(value); // result = sdf.format(date); // } 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(); result = 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); result = 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("#"); } result = format.format(value); } break; case HSSFCell.CELL_TYPE_STRING:// String类型 result = cell.getRichStringCellValue().toString(); break; case HSSFCell.CELL_TYPE_BLANK: result = ""; default: result = cell.getDateCellValue().toString(); break; } return result; } /** * 获取单元格数据内容为字符串类型的数据 excel2007 * * @param cell * @return */ public static String getStringCellValue(XSSFCell cell) { String strCell = ""; // if(cell.equals("发布日期")){ // return String.valueOf(cell.getDateCellValue()); // } DecimalFormat df = new DecimalFormat("#"); 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); } // if(HSSFDateUtil.isCellDateFormatted(cell)){ // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // strCell= sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue())).toString(); // }else{ // strCell= df.format(cell.getNumericCellValue()); // } 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()); } } // // public static int getweekofyear(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 cal=Calendar.getInstance(); // cal.setTime(date); // return cal.get(Calendar.WEEK_OF_YEAR); // // } // 获取当前时间所在年的最大周数 public static int getMaxWeekNumOfYear(int year) { Calendar c = new GregorianCalendar(); c.set(year, Calendar.DECEMBER, 31, 23, 59, 59); return getWeekOfYear(c.getTime()); } // 获取当前时间所在年的周数 public static int getWeekOfYear(Date date) { Calendar c = new GregorianCalendar(); c.setFirstDayOfWeek(Calendar.MONDAY); c.setMinimalDaysInFirstWeek(7); c.setTime(date); return c.get(Calendar.WEEK_OF_YEAR); } }
并附上测试的excel文件
- 630有问题_-_副本.rar (8.1 KB)
- 下载次数: 9
发表评论
-
java word导出
2016-06-30 08:49 2617需要导出的word文档是事先准备好的一个模板,文档数据所在的位 ... -
spring 4mvc下载文件的实现
2016-06-14 13:52 2575网上找到的版本较老 是spring3的 org.spring ... -
cas不同登录页面手动设置不同国际化提示
2016-05-05 09:48 1336<% org.springframework.web. ... -
实用技术解决方案博客地址记录
2016-04-14 10:35 667Jquery 将表单序列化为Json对象:http://www ... -
如果实现类似微信附近的人功能
2016-01-13 10:09 2534如果实现类似微信附近的人功能: 第一种可以使用redis-ge ... -
cxf+wss4j+mysql webservice 加密服务开发
2015-11-04 10:02 2994我采用的是cxf 加密端用的 WSS4J 服务端查询数据库 ... -
多项目集中权限管理系统 采用cas +shiro+spring mvc+mbatis+bootstrap单点登录
2015-10-13 17:37 10232流程架构图: 这里权限系统也可以理解为cas client ... -
OAuthProblemException{error='unsupported_response_type', description='Invalid re
2015-09-21 18:05 4571OAuthProblemException{error='un ... -
导出数据到excel
2014-12-08 10:10 1433/** * * @param datas 数据行 ... -
java.lang.NoSuchMethodError: org.apache.axiom.soap.SOAPEnvelope.hasFault()Z错误的解决
2014-12-05 14:21 1654axis2 运行报这个错误的原因是 要么缺少 包 ,axiom ... -
spring mvc+shiro的通用权限管理系统
2014-10-23 13:50 26861同志们 我的 spring mvc+shiro的通用权限管理系 ... -
多线程断点下载文件
2014-09-23 15:46 1249所谓多线程断点下载 :就是当某个文件下了一部分后突然断电了,或 ... -
多线程下载文件
2014-09-22 17:27 2198package mutiDownload; import ... -
java 按照每周分组
2014-06-09 09:07 7033本例的工作应用是导入excel excel的列里有一个发布日 ... -
java计算链表、数组列表或数组中最大元素
2014-03-09 23:50 2677package com; import java.uti ... -
java 获取数组的最大值和最小值
2014-03-02 22:08 6939package com; public class St ... -
宁波java开发技术群
2014-02-17 09:54 1宁波java开发群 240974225 在宁波做java开发的 ... -
spring mvc +jdbctemplate 返回多表查询List<Bean>
2013-12-27 13:19 17787发现 hibernate做多表查询 是忒麻烦了 Spring ... -
读《大型网站技术架构:核心原理与案例分析》 后感
2013-11-26 10:36 5684大型网站软件系统有比 ... -
java拆分list
2013-11-22 09:21 2212java 将一个list平均拆成十个list,如果 list的 ...
相关推荐
用户可以轻松添加、删除或编辑主机,进行分组管理,实现高效的运维操作。 2. **主机批量执行**:平台支持跨主机的命令行操作,可以一次性在多个主机上执行相同或不同的命令,极大地减少了重复劳动,提高了运维效率...
Tripple Farm:Match 3 Combination Game Complete Project 合成小镇三消Unity合成消除游戏项目游戏插件模版C# 支持Unity2020.3.4或更高 您知道像三合镇这样的著名益智游戏,并且您想制作一个自己的游戏。就是这样。这个包正好适合您。 这是一个完整的项目,您可以在零分钟内将其上传到 appstore 或 googleplay 商店。 基本规则: 3个或以上相同的道具可以匹配升级为新的道具。动物如果被困住,也可以合并。 羽毛: -移动(android/ios)就绪。 - 包含所有源代码。 -超过 12 座建筑/军团需要升级。 -三种特殊物品可以提供帮助。 - 三个不同的主题(场景和动物) -unity iap 支持 -Unity UI -广告位已准备好 -包含详细文档
内容概要:本文档是一份针对Java初学者的基础测试题,分为不定项选择题、简答题和编程题三大部分。选择题涵盖标识符、数组初始化、面向对象概念、运算符优先级、循环结构、对象行为、变量命名规则、基本
内容概要:本文详细介绍了如何利用MATLAB进行机器人运动学、动力学以及轨迹规划的建模与仿真。首先,通过具体的代码实例展示了正运动学和逆运动学的实现方法,包括使用DH参数建立机械臂模型、计算末端位姿以及求解关节角度。接着,讨论了雅克比矩阵的应用及其在速度控制中的重要性,并解释了如何检测和处理奇异位形。然后,深入探讨了动力学建模的方法,如使用拉格朗日方程和符号工具箱自动生成动力学方程。此外,还介绍了多种轨迹规划技术,包括抛物线插值和五次多项式插值,确保路径平滑性和可控性。最后,提供了常见仿真问题的解决方案,强调了在实际工程项目中需要注意的关键点。 适合人群:对机器人控制感兴趣的初学者、希望深入了解机器人运动学和动力学的学生及研究人员、从事机器人开发的技术人员。 使用场景及目标:① 学习如何使用MATLAB进行机器人运动学、动力学建模;② 掌握不同类型的轨迹规划方法及其应用场景;③ 解决仿真过程中遇到的各种问题,提高仿真的稳定性和准确性。 其他说明:文中提供的代码片段可以直接用于实验和教学,帮助读者更好地理解和掌握相关概念和技术。同时,针对实际应用中的挑战提出了实用的建议,有助于提升项目的成功率。
包括:源程序工程文件、Proteus仿真工程文件、配套技术手册等 1、采用51/52单片机作为主控芯片; 2、发送机:18B20测温、开关模拟灯光,发送数据; 3、接收机:接受数据、12864液晶显示;
内容概要:本文探讨了在微电网优化中如何处理风光能源的不确定性,特别是通过引入机会约束和概率序列的方法。首先介绍了风光能源的随机性和波动性带来的挑战,然后详细解释了机会约束的概念,即在一定概率水平下放松约束条件,从而提高模型灵活性。接着讨论了概率序列的应用,它通过对历史数据分析生成多个可能的风光发电场景及其概率,以此为基础构建优化模型的目标函数和约束条件。文中提供了具体的Matlab代码示例,演示了如何利用CPLEX求解器解决此类优化问题,并强调了参数选择、模型构建、约束添加以及求解过程中应注意的技术细节。此外,还提到了一些实用技巧,如通过调整MIP gap提升求解效率,使用K-means聚类减少场景数量以降低计算复杂度等。 适合人群:从事电力系统研究、微电网设计与运营的专业人士,尤其是那些对风光不确定性建模感兴趣的研究者和技术人员。 使用场景及目标:适用于需要评估和优化含有大量间歇性可再生能源接入的微电网系统,旨在提高系统的经济性和稳定性,确保在面对风光出力波动时仍能维持正常运作。 其他说明:文中提到的方法不仅有助于学术研究,也可应用于实际工程项目中,帮助工程师们制定更为稳健的微电网调度计划。同时,文中提供的代码片段可供读者参考并应用于类似的问题情境中。
linux之用户管理教程.md
内容概要:本文详细介绍了如何利用组态王和西门子S7-200 PLC构建六层或八层电梯控制系统。首先进行合理的IO地址分配,明确输入输出信号的功能及其对应的物理地址。接着深入解析了PLC源代码的关键部分,涵盖初始化、呼叫处理、电梯运行逻辑和平层处理等方面。此外,提供了组态王源代码用于实现动画仿真,展示了电梯轿厢的画面创建及动画连接方法。最后附上了详细的电气原理图和布局图,帮助理解和实施整个系统架构。 适合人群:从事工业自动化控制领域的工程师和技术人员,尤其是对PLC编程和人机界面开发感兴趣的从业者。 使用场景及目标:适用于教学培训、工程项目实践以及研究开发等场合。旨在为相关人员提供一个完整的电梯控制系统设计方案,便于他们掌握PLC编程技巧、熟悉组态软件的应用,并能够独立完成类似项目的开发。 其他说明:文中不仅包含了理论知识讲解,还分享了许多实际操作经验,如解决编码器丢脉冲的问题、优化平层停车精度的方法等。同时强调了安全性和可靠性方面的考虑,例如设置了多重保护机制以确保系统稳定运行。
在工业生产和设备运行过程中,滚动轴承故障、变压器油气故障等领域的数据分类与故障诊断至关重要。准确的数据分类与故障诊断能够及时发现设备潜在问题,避免故障恶化导致的生产事故与经济损失。LSTM能够捕获时序信息,马尔可夫场(MTF)能够一维信号转换为二维特征图,并结合CNN学习空间特征,MTF-1D-2D-CNN-LSTM-Attention模型通过将一维时序信号和二维图像融合,融合不同模态优势,并引入多头自注意力机制提高泛化能力,为数据分类与故障诊断提供了新的思路。实验结果表明,该模型在分类准确率、鲁棒性和泛化能力方面具有显著优势。多模态融合算法凭借其创新点和实验验证的有效性,在滚动轴承故障、变压器油气故障等领域展现出广阔的应用前景,有望推动相关领域故障诊断技术的进一步发展。 关键词:多模态融合;故障诊断;马尔可夫场;卷积神经网络;长短期记忆神经网络 适用平台:Matlab2023版本及以上。实验硬件设备配置如下:选用高性能计算机,搭载i7处理器,以确保数据处理和模型训练的高效性;配备16GB的内存,满足大规模数据加载和模型运算过程中的内存需求;使用高性能显卡,提供强大的并行计算能力,加速深度学习模型的训练过程。实验参数的选择依据多方面因素确定。
内容概要:本文档提供了一个面试模拟的指导框架,旨在为用户提供一个真实的面试体验。文档中的面试官名为Elian,被设定为性格温和冷静且思路清晰的形象,其主要职责是根据用户提供的简历信息和应聘岗位要求,进行一对一的模拟面试。面试官将逐一提出问题,确保每次只提一个问题,并等待候选人的回答结束后再继续下一个问题。面试官需要深入了解应聘岗位的具体要求,包括但不限于业务理解、行业知识、具体技能、专业背景以及项目经历等方面,从而全面评估候选人是否符合岗位需求。此外,文档强调了面试官应在用户主动发起提问后才开始回答,若用户未提供简历,面试官应首先邀请用户提供简历或描述应聘岗位; 适用人群:即将参加面试的求职者,特别是希望提前熟悉面试流程、提升面试技巧的人士; 使用场景及目标:①帮助求职者熟悉面试流程,提高应对实际面试的信心;②通过模拟面试,让求职者能够更好地展示自己的优势,发现自身不足之处并加以改进; 其他说明:此文档为文本格式,用户可以根据文档内容与面试官Elian进行互动,以达到最佳的模拟效果。在整个模拟过程中,用户应尽量真实地回答每一个问题,以便获得最贴近实际情况的反馈。
招聘技巧HR必看如何进行网络招聘和电话邀约.ppt
内容概要:本文详细介绍了利用三菱PLC(特别是FX系列)和组态王软件构建3x3书架式堆垛式立体库的方法。首先阐述了IO分配的原则,明确了输入输出信号的功能,如仓位检测、堆垛机运动控制等。接着深入解析了梯形图编程的具体实现,包括基本的左右移动控制、复杂的自动寻址逻辑,以及确保安全性的限位保护措施。还展示了接线图和原理图的作用,强调了正确的电气连接方式。最后讲解了组态王的画面设计技巧,通过图形化界面实现对立体库的操作和监控。 适用人群:从事自动化仓储系统设计、安装、调试的技术人员,尤其是熟悉三菱PLC和组态王的工程师。 使用场景及目标:适用于需要提高仓库空间利用率的小型仓储环境,旨在帮助技术人员掌握从硬件选型、电路设计到软件编程的全流程技能,最终实现高效稳定的自动化仓储管理。 其他说明:文中提供了多个实用的编程技巧和注意事项,如避免常见错误、优化性能参数等,有助于减少实际应用中的故障率并提升系统的可靠性。
内容概要:本文详细探讨了利用COMSOL进行电弧放电现象的模拟,重点在于采用磁流体方程(MHD)来耦合电磁、热流体和电路等多个物理场。文中介绍了关键的数学模型如磁流体动力学方程、热传导方程以及电路方程,并讨论了求解过程中遇到的技术难题,包括参数敏感性、求解器选择、网格划分等问题。此外,作者分享了许多实践经验,比如如何处理不同物理场之间的相互作用,怎样避免数值不稳定性和提高计算效率。 适用人群:适用于从事电弧放电研究的专业人士,尤其是那些希望通过数值模拟深入了解电弧行为并应用于实际工程项目的人群。 使用场景及目标:①帮助研究人员更好地理解和预测电弧放电过程中的各种物理现象;②为工程师提供优化电气设备设计的方法论支持;③指导使用者正确配置COMSOL软件的相关参数以确保高效稳定的仿真结果。 其他说明:尽管存在较高的计算复杂度和技术挑战,成功的电弧放电仿真能够显著提升对这一重要物理过程的认识水平,并促进相关领域的技术创新和发展。
内容概要:本文详细介绍了如何利用粒子群优化算法(PSO)改进极限学习机(KELM),以提升其在多维输入单维输出数据处理任务中的性能。首先简述了KELM的工作原理及其快速训练的特点,接着深入探讨了PSO算法的机制,包括粒子的速度和位置更新规则。然后展示了如何将PSO应用于优化KELM的关键参数,如输入权值和隐含层偏置,并提供了具体的Python代码实现。通过对模拟数据和实际数据集的实验对比,证明了PSO优化后的KELM在预测精度上有显著提升,尤其是在处理复杂数据时表现出色。 适合人群:对机器学习尤其是深度学习有一定了解的研究人员和技术爱好者,以及从事数据分析工作的专业人士。 使用场景及目标:适用于需要高效处理多维输入单维输出数据的任务,如时间序列预测、回归分析等。主要目标是通过优化模型参数,提高预测准确性并减少人工调参的时间成本。 其他说明:文中不仅给出了详细的理论解释,还附上了完整的代码示例,便于读者理解和实践。此外,还讨论了一些实用技巧,如参数选择、数据预处理等,有助于解决实际应用中的常见问题。
内容概要:本文介绍了利用粒子群算法(PSO)解决微网优化调度问题的方法。主要内容涵盖微网系统的组成(风力、光伏、储能、燃气轮机、柴油机)、需求响应机制、储能SOC约束处理及粒子群算法的具体实现。文中详细描述了目标函数的设计,包括发电成本、启停成本、需求响应惩罚项和SOC连续性惩罚项的计算方法。同时,阐述了粒子群算法的核心迭代逻辑及其参数调整策略,如惯性权重的线性递减策略。此外,还讨论了代码调试过程中遇到的问题及解决方案,并展示了仿真结果,证明了模型的有效性和优越性。 适合人群:从事电力系统优化、智能算法应用的研究人员和技术人员,特别是对微网调度感兴趣的读者。 使用场景及目标:适用于研究和开发微网优化调度系统,旨在提高供电稳定性的同时降低成本。具体应用场景包括但不限于分布式能源管理、工业园区能源调度等。目标是通过合理的调度策略,使微网系统在满足需求响应的前提下,实现经济效益最大化。 其他说明:本文提供的Matlab程序具有良好的模块化设计,便于扩展和维护。建议读者在理解和掌握基本原理的基础上,结合实际情况进行改进和创新。
KUKA机器人相关资料
基于多智能体的高层建筑分阶段火灾疏散仿 真及策略研究.pdf
Iterative Time Series Imputation by Maintaining Dependency Consistency (ACM TKDD 2024)
内容概要:本文详细探讨了带同步整流桥的交错PFC(功率因数校正)电路的设计与仿真实现。交错PFC通过多路PFC电路交错工作,降低了输入电流纹波,提高了功率密度。同步整流桥采用MOSFET代替传统二极管,减少了整流损耗,提升了效率。文中提供了关键代码片段,包括PWM控制、同步整流桥控制逻辑、电流环控制等,并介绍了如何在MATLAB/Simulink中搭建仿真模型,验证设计方案的有效性。此外,还讨论了仿真过程中遇到的问题及其解决方案,如死区时间处理、电流采样精度、负载突变应对等。 适合人群:从事电力电子设计的研究人员和技术工程师,尤其是对PFC技术和同步整流感兴趣的从业者。 使用场景及目标:适用于研究和开发高效的电源管理系统,旨在提高电能利用率,减少谐波污染,优化电源性能。目标是通过仿真实验验证设计方案的可行性,最终应用于实际硬件开发。 其他说明:文章强调了仿真与实际调试的区别,提醒读者在实际应用中需要注意的细节,如电流采样精度、死区时间和负载突变等问题。同时,提供了具体的代码实现和仿真技巧,帮助读者更好地理解和掌握这一复杂的技术。