`
zqb666kkk
  • 浏览: 736272 次
  • 性别: Icon_minigender_1
  • 来自: 宁波
社区版块
存档分类
最新评论

java按照每周分组 改进版

    博客分类:
  • java
 
阅读更多
之前是按照 先把数据按月分组 然后再按周分组 这样有个问题就是 会导致像6月30号这种数据 应该是 跟7月1号 7月2号等分在一组的 但是 按照上次的算法 会被分开 显然这样似乎有点不太好理解

所以这次不做按月分组 直接 利用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文件
0
0
分享到:
评论

相关推荐

    Spug是面向中小型企业设计的轻量级无Agent的自动化运维平台,整合了主机管理、主机批量执行、主机在线终端、应用发布部署等功能

    用户可以轻松添加、删除或编辑主机,进行分组管理,实现高效的运维操作。 2. **主机批量执行**:平台支持跨主机的命令行操作,可以一次性在多个主机上执行相同或不同的命令,极大地减少了重复劳动,提高了运维效率...

    `人工智能_人脸识别_活体检测_身份认证`.zip

    人脸识别项目实战

    深度学习教程和开发计划.zip

    深度学习教程和开发计划.zip

    事件总线_对象C_订阅发布_消息传递中间件_1741862275.zip

    c语言学习

    基本版贪吃蛇源代码.zip

    基本版贪吃蛇源代码.zip

    【Python毕设】p107基于Django的药店信息管理-vue.zip

    项目资源包含:可运行源码+sql文件+ python3.8+django+mysql5.7+vue 适用人群:学习不同技术领域的小白或进阶学习者;可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。 项目具有较高的学习借鉴价值,也可拿来修改、二次开发。 有任何使用上的问题,欢迎随时与博主沟通,博主看到后会第一时间及时解答。 Django==3.2.11 PyMySQL==1.0.2 djangorestframework==3.13.0 django-cors-headers==3.13.0 Pillow==9.1.1 psutil==5.9.4

    Abaqus螺栓拧紧过程仿真 (1)螺栓螺母可实现参数化建模,全部采用六面体C3D8R单元建模 (2)施加边界条件实现螺母的拧紧过程,输出过程动画和应力、位移参数 (3)提取螺栓中部截面的轴力和螺母

    Abaqus螺栓拧紧过程仿真 (1)螺栓螺母可实现参数化建模,全部采用六面体C3D8R单元建模 (2)施加边界条件实现螺母的拧紧过程,输出过程动画和应力、位移参数 (3)提取螺栓中部截面的轴力和螺母拧紧力矩之间的关系 ,Abaqus; 螺栓拧紧; 参数化建模; 六面体C3D8R单元建模; 边界条件; 输出动画; 应力位移参数; 轴力与拧紧力矩关系。,Abaqus螺栓拧紧仿真:六面体单元建模与力矩关系分析

    苏苏源码-weixin123-基于SpringBoot的汽车售后服务系统及微信小程序的设计与实现(编号:49000250).zip

    标题基于SpringBoot的汽车售后服务系统及微信小程序的设计与实现AI更换标题第1章引言介绍汽车售后服务的重要性,SpringBoot和微信小程序的应用背景,以及本研究的意义和目的。1.1研究背景与意义阐述汽车售后服务市场的现状及发展趋势,SpringBoot和微信小程序在售后服务中的应用前景。1.2国内外研究现状概述国内外在汽车售后服务系统和小程序开发方面的研究进展。1.3研究内容与创新点介绍本文的主要研究内容,包括系统设计和微信小程序的开发,并阐述创新点。第2章相关理论与技术介绍SpringBoot框架、微信小程序开发的相关理论和关键技术。2.1SpringBoot框架概述阐述SpringBoot框架的特点、优势以及在系统开发中的应用。2.2微信小程序开发技术介绍微信小程序的开发流程、关键技术和功能实现。2.3数据库技术与系统设计讨论数据库设计原则、数据存储和处理速度的问题,并阐述系统设计的思路和方法。第3章系统需求分析与设计对汽车售后服务系统的需求进行分析,并设计系统的整体架构和功能模块。3.1需求分析从用户角度和业务需求出发,对系统的功能需求和非功能需求进行详细分析。3.2

    智慧园区安全方案(浙江大华)PPT(69页).pptx

    在智慧园区建设的浪潮中,一个集高效、安全、便捷于一体的综合解决方案正逐步成为现代园区管理的标配。这一方案旨在解决传统园区面临的智能化水平低、信息孤岛、管理手段落后等痛点,通过信息化平台与智能硬件的深度融合,为园区带来前所未有的变革。 首先,智慧园区综合解决方案以提升园区整体智能化水平为核心,打破了信息孤岛现象。通过构建统一的智能运营中心(IOC),采用1+N模式,即一个智能运营中心集成多个应用系统,实现了园区内各系统的互联互通与数据共享。IOC运营中心如同园区的“智慧大脑”,利用大数据可视化技术,将园区安防、机电设备运行、车辆通行、人员流动、能源能耗等关键信息实时呈现在拼接巨屏上,管理者可直观掌握园区运行状态,实现科学决策。这种“万物互联”的能力不仅消除了系统间的壁垒,还大幅提升了管理效率,让园区管理更加精细化、智能化。 更令人兴奋的是,该方案融入了诸多前沿科技,让智慧园区充满了未来感。例如,利用AI视频分析技术,智慧园区实现了对人脸、车辆、行为的智能识别与追踪,不仅极大提升了安防水平,还能为园区提供精准的人流分析、车辆管理等增值服务。同时,无人机巡查、巡逻机器人等智能设备的加入,让园区安全无死角,管理更轻松。特别是巡逻机器人,不仅能进行360度地面全天候巡检,还能自主绕障、充电,甚至具备火灾预警、空气质量检测等环境感知能力,成为了园区管理的得力助手。此外,通过构建高精度数字孪生系统,将园区现实场景与数字世界完美融合,管理者可借助VR/AR技术进行远程巡检、设备维护等操作,仿佛置身于一个虚拟与现实交织的智慧世界。 最值得关注的是,智慧园区综合解决方案还带来了显著的经济与社会效益。通过优化园区管理流程,实现降本增效。例如,智能库存管理、及时响应采购需求等举措,大幅减少了库存积压与浪费;而设备自动化与远程监控则降低了维修与人力成本。同时,借助大数据分析技术,园区可精准把握产业趋势,优化招商策略,提高入驻企业满意度与营收水平。此外,智慧园区的低碳节能设计,通过能源分析与精细化管理,实现了能耗的显著降低,为园区可持续发展奠定了坚实基础。总之,这一综合解决方案不仅让园区管理变得更加智慧、高效,更为入驻企业与员工带来了更加舒适、便捷的工作与生活环境,是未来园区建设的必然趋势。

    词法分析_SysY2022_标识符字面量_错误处理器_1741862780.zip

    c语言学习

    `移动开发_人脸识别_Face++_Android项目集成`.zip

    人脸识别项目源码实战

    计算机视觉_CNN_人脸识别_训练与测试.zip

    人脸识别项目实战

    电力电子技术基础-电力电子器件与典型应用解析

    内容概要:本文详细介绍了电力电子技术的基础知识及相关器件,内容涵盖电力电子器件(如晶闸管、GTR、IGBT)、相控整流电路(单相和三相)、直流斩波电路、交流变换电路、逆变电路、软开关技术等,并探讨了其应用场景(如开关电源、不间断电源(UPS)、电子镇流器、感应加热、直流电源、开关模焊接等),以及电力电子装置带来的电力公害(谐波污染、电磁干扰和功率因数降低)及其抑制方法。通过丰富的实例讲解了各类电路的工作原理和波形分析方法,旨在让学生和从业人员更好地理解和掌握该领域的核心技术和发展趋势。书中结合最新的研究成果进行了详尽阐述,使内容兼具科学性和创新性,并提供了大量习题以便于教与学。 适合人群:自动化、电气工程及其自动化等相关专业本科生、研究生和技术工程师。 使用场景及目标:①高校教师用于课堂授课,辅助学生深入理解电力电子器件工作原理;②电力电子领域科研人员和工程技术人员参考资料,掌握行业前沿技术和设计理念。 阅读建议:本文不仅讲解了电力电子器件的结构特点、操作流程,更重要的是展示了电力电子技术在整个电力系统和电气设备应用中的关键作用,希望读者能够在学习过程中理论结合实践,加深对知识的理解

    编译技术_C语言_Clang_AST_解释执行器_作业实现辅_1741861002.zip

    c语言学习

    万能视频拼接软件源码,可以直接进行修改增加功能,二次开发!

    万能视频拼接软件源码,可以直接进行修改增加功能,二次开发!

    1. 人工智能_图像识别_CaptchaRecognise_验证码识别.zip

    人脸识别项目源码实战

    医学设备FibroScan PRO肝病检测操作与数据解析指南(可复现,有问题请联系博主)

    内容概要:本文介绍了FibroScan PRO这款专门用于肝脏纤维化程度评估的医疗器械。强调了其仅能被认证过的专员使用,所得到的数据需要专业医生综合考虑病人的实际身体状况进行精准解释。文中列举了若干组测量示例以及相关单位,例如压力数值(kPa)、声衰减参数(dB/m),还特别指出VCTE探针的正确性和精确度依靠定期校正。此外,详细阐述了病人的姿势调整以及测试部位选取的原则,在不同层厚的情况下对皮肤组织进行检查。并提供了一份详细的检查报告模板,涵盖了操作者的身份确认、受检人基本信息、时间戳以及其他一些量化评价指标,例如IQR(四分位距),这有助于更好地理解和应用FibroScan的检测结果。 适合人群:面向医院、诊所等相关医疗保健机构的工作人员,包括但不限于操作员和技术支持团队成员。同时也可以为想要了解这一先进诊断工具的研究人员或医学学生提供重要参考资料。 使用场景及目标:旨在指导医疗机构如何标准化地完成FibroScan设备的实际临床应用过程;确保所有测量数据均能在符合质量控制的前提下产生,并提高医疗服务的质量和效率;并且帮助医师做出更加科学合理的健康决策,最终服务于病患的利益最大化。

    海豚鲸鱼数据集 5435张图 正确识别率可达92.6% 可识别:海豚 虎鲸 蜥蜴 海豹 鲨鱼 龟 支持darknet格式标注

    海豚鲸鱼数据集 5435张图 正确识别率可达92.6% 可识别:海豚 虎鲸 蜥蜴 海豹 鲨鱼 龟 支持darknet格式标注

    TokenYc_FaceRecognizer_1741777923.zip

    人脸识别项目

Global site tag (gtag.js) - Google Analytics