extremprocess1

public class ExtremProcess
{
	/**如果每个表单需要标题行,则为1,否则为0*/
	private final int headline = 1;
	private Logger log = Logger.getLogger(ExtremProcess.class);
	
	/**
	 * 
	 * @param dir 文件所在目录
	 * @param override 是否覆盖源文件,true覆盖,false不覆盖
	 */
	public boolean exeDir(File dir,boolean override)
	{
		try
		{
			File[] fs = dir.listFiles(new FilenameFilter() {
				public boolean accept(File dir, String name)
				{
					return name.toLowerCase().endsWith("xls") && name.indexOf("finished") == -1;
				}
			});
			for(File f:fs)
			{
				String src = f.getAbsolutePath();
				exeFile(src, override ? src : src.replace(".", "_finished."));
			}
		}
		catch (Exception e)
		{
			log.error("目录输入有误,请检查重试!");
			return false;
		}
		return true;
	}
	
	/**
	 * 
	 * @param srcFile 源文件
	 * @param desFile 处理后生成的文件,如果与源文件名同则覆盖源文件,原来资料仍然保留
	 */
	public boolean exeFile(String srcFile,String desFile)
	{
		try
		{
			SimpleDateFormat formatter = Const.srcFormat;
			log.info(srcFile+" is processing...");
			Workbook book = Workbook.getWorkbook(new File(srcFile)); 
			
			Sheet sheet = book.getSheet(Const.sheet_index-1);
			Cell[] cells = sheet.getColumn(Const.data_index); 
			
			String dateFormat = "%tF %<tT";
			LinkedHashMap<Integer, ArrayList<Date>> map = new LinkedHashMap<Integer, ArrayList<Date>>(31,1f);
			String result = null;
			for(Cell cell:cells)
			{
				result = cell.getContents(); 
				if(result.trim().length() != 0)//如果非空就转化为日期存起来
				{
					Date d = formatter.parse(result);
					if(map.get(d.getDate()) == null)
					{
						map.put(d.getDate(), new ArrayList<Date>());
					}
					map.get(d.getDate()).add(d);
				}
					
			}
			//对抽取的数据进行处理
			SimpleProcess util = new SimpleProcess();
			util.deal(map);
			LinkedHashMap<Integer,ArrayList<Date>> exception = util.getException();
			LinkedHashMap<Integer,ArrayList<Date>> extra_weekend = util.getExtra_weekend();
			LinkedHashSet<Date> extra_weekday = util.getExtra_weekday();
			
			//新建一个可写工作薄
			WritableWorkbook wbook = Workbook.createWorkbook(new FileOutputStream(desFile,false),book);
			String[] title = {"周末加班","平时加班","异常打卡"};
			WritableSheet[] ws = new WritableSheet[title.length];
			
			//做点清理,如果为空白表单或者与目标表单重名,则予以删除
			for(int i=book.getNumberOfSheets()-1;i >= 0; i--)
			{
				if(book.getSheet(i).getRows() == 0 || book.getSheet(i).getColumns() == 0)
				{
					wbook.removeSheet(i);
					continue;
				}
				for(String t : title)
				{
					if(book.getSheet(i).getName().equals(t))
					{
						wbook.removeSheet(i);
					}
				}
			}

 

你可能感兴趣的:(工作,F#)