package org.ccpit.base.utils.excelUtil;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;

import javax.servlet.http.HttpServletResponse;



/**
 * @Description 描述：excel助手类
 * @author dingwei
 * @Version v0.1
 * @2015-6-5上午8:38:45
 * JDK版本 sun jdk1.6
 *********************************更新记录******************************
 * 版本：  <版本号>        修改日期：  <日期>        修改人： <修改人姓名>
 * 修改内容：  <修改内容描述>
 **********************************************************************
 *
 */
public class ExcelHelper {

	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	private static SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static void main(String[] args){
		Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00"));    //获取东八区时间
		System.out.println(c.get(Calendar.YEAR));
		Calendar cal = Calendar.getInstance();
		System.out.println(cal.get(Calendar.YEAR));
	}
	
	public int getYear(Calendar cal){
		return cal.get(Calendar.YEAR);
	}
	
	/**
	 * 
	 * getList:( 转码防止乱码  ). <br/>
	 * @author dingwei
	 * @param response
	 * @param excelName
	 * @since JDK 1.6
	 */
	public void setTranscode(HttpServletResponse response,String excelName){
		response.reset();
    	response.setContentType("application/vnd.ms-excel; charset=utf-8");
    	response.setContentType("application/x-download"); 
		try {
			response.addHeader("Content-Disposition", "attachment;filename="+new String(excelName.getBytes("gb2312"),"ISO8859-1" )+".xlsx");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * exportExcelHDBM:(经营信息导出). <br/>
	 * @author dingwei
	 * @param os
	 * @param newsInfoList
	 * @param sheetName
	 * @since JDK 1.6
	 */
	/*public void exportExcel_JY(OutputStream os,List<Approveplan> newsInfoList,String sheetName){
		//创建Excel工作薄
		XSSFWorkbook book = new XSSFWorkbook();
		//在Excel工作薄中建一张工作表
		XSSFSheet sheet = book.createSheet(sheetName);
		//创建cell背景颜色
		XSSFCellStyle style = book.createCellStyle();
		XSSFFont font = book.createFont();
		font.setColor(HSSFColor.BLACK.index);//字体颜色
        font.setFontHeightInPoints((short)12);
        font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);         //字体增粗
		style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); //垂直
		style.setFillBackgroundColor(HSSFColor.ROYAL_BLUE.index);
		//设置单元格格式(文本)
		XSSFCellStyle cellStyle = book.createCellStyle();
		//创建第一行为标题行
		XSSFRow row = sheet.createRow(0);
		row.setRowStyle(style);
		XSSFCell cell0 = row.createCell(0);
		XSSFCell cell1 = row.createCell(1);
		XSSFCell cell2 = row.createCell(2);
		XSSFCell cell3 = row.createCell(3);
		XSSFCell cell4 = row.createCell(4);
		XSSFCell cell5 = row.createCell(5);
		XSSFCell cell6 = row.createCell(6);
		XSSFCell cell7 = row.createCell(7);
		XSSFCell cell8 = row.createCell(8);
		XSSFCell cell9 = row.createCell(9);
		XSSFCell cell10 = row.createCell(10);
		XSSFCell cell11= row.createCell(11);
		XSSFCell cell12 = row.createCell(12);
		XSSFCell cell13 = row.createCell(13);
		XSSFCell cell14 = row.createCell(14);
		XSSFCell cell15 = row.createCell(15);
		XSSFCell cell16 = row.createCell(16);
		XSSFCell cell17 = row.createCell(17);
		XSSFCell cell18 = row.createCell(18);
		XSSFCell cell19 = row.createCell(19);
		XSSFCell cell20 = row.createCell(20);
		
		//定义单元格为字符串类型
		cell0.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell1.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell2.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell3.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell4.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell5.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell6.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell7.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell8.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell9.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell10.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell11.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell12.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell13.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell14.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell15.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell16.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell17.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell18.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell19.setCellType(XSSFCell.CELL_TYPE_STRING);
		cell20.setCellType(XSSFCell.CELL_TYPE_STRING);
		
		cell0.setCellValue("公司名称");
		cell1.setCellValue("规模");
		cell2.setCellValue("任职人");
		cell3.setCellValue("任职人职务");
		cell4.setCellValue("主要需求");
		cell5.setCellValue("经营范围");  //
		cell6.setCellValue("上年总资产");
		cell7.setCellValue("上年销售收入");
		cell8.setCellValue("上年实现利税");// 
		cell9.setCellValue("员工人数");  
		cell10.setCellValue("希望得到商会哪些服务"); //改成姓(英)
		cell11.setCellValue("已开拓海外市场");//改成名(英)
		cell12.setCellValue("有意开拓海外市场");
		cell13.setCellValue("公司网址");
		cell14.setCellValue("公司地址");
		cell15.setCellValue("信息状态");
		
		if(null != newsInfoList){
			//循环导出数据到excel中
			for(int i=0; i<newsInfoList.size();i++){
				Approveplan approveplan = newsInfoList.get(i);
				//创建第i行
				XSSFRow rowi = sheet.createRow(i+1);
				if(null != approveplan){ //单位名称
					rowi.createCell(0).setCellValue(null == approveplan.getMemberBaseInfo()?"":approveplan.getMemberBaseInfo().getUnitName());
					rowi.createCell(1).setCellValue(approveplan.getScale());
					rowi.createCell(2).setCellValue(approveplan.getIncumbent());
					rowi.createCell(3).setCellValue(approveplan.getIncumbentPost());
					rowi.createCell(4).setCellValue(approveplan.getMainNeed());
					rowi.createCell(5).setCellValue(approveplan.getProductOrService());
					rowi.createCell(6).setCellValue(approveplan.getLastYearAssets());
					rowi.createCell(7).setCellValue(approveplan.getLastYearRevenue());
					rowi.createCell(8).setCellValue(approveplan.getLastYearTax());
					rowi.createCell(9).setCellValue(approveplan.getStaffNum());
					rowi.createCell(10).setCellValue(approveplan.getHopeService());
					rowi.createCell(11).setCellValue(approveplan.getDevelopedMarket());
					rowi.createCell(12).setCellValue(approveplan.getHopeDevelopMarket());
					rowi.createCell(13).setCellValue(approveplan.getWebsiteUrl());
					rowi.createCell(14).setCellValue(approveplan.getAddress());
					rowi.createCell(15).setCellValue(1 == approveplan.getInfoStatus()?"当前数据":"历史数据");
				}
			}
			try {
				book.write(os);
				os.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}*/
	
}
