package cn.cnnic.ops;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory; public class DutyRosterVerification { public static void main(String[] args) {
try {
// getDataFromExcel("D:\\soft\\eclipse\\workspace\\DutyRoster\\src\\20160726_2016年8月份值班表.xlsx");
getDataFromExcel("D:\\Data\\xxx.xlsx");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidFormatException e) {
e.printStackTrace();
}
} public static void getDataFromExcel(String file) throws FileNotFoundException, IOException, InvalidFormatException {
InputStream ins = null;
Workbook wb = null;
ins = new FileInputStream(new File(file));
wb = WorkbookFactory.create(ins);
ins.close();
Sheet sheet = wb.getSheetAt(0);
int rowNum = sheet.getLastRowNum(); Map<String, String> dutyMap = new HashMap<String, String>();
dutyMap.put("1", "***");
dutyMap.put("2", "***");
dutyMap.put("3", "***");
dutyMap.put("4", "***");
dutyMap.put("5", "***");
dutyMap.put("6", "***");
dutyMap.put("7", "***"); Map<String, Integer> dayShift = new HashMap<String, Integer>();
Map<String, Integer> nightShift = new HashMap<String, Integer>(); // System.out.println(sheet.getRow(3).getCell(2).toString().split("\n")[0]);
for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
Row rowCurrent = sheet.getRow(rowIndex);
if (rowIndex >= 3 && (rowIndex - 3) % 4 == 0) {
for (int colIndex = 2; colIndex <= 8; colIndex++) {
Cell cellCurrent = rowCurrent.getCell(colIndex);
if (cellCurrent != null) {
cellCurrent.setCellType(Cell.CELL_TYPE_STRING);
}
String team = cellCurrent.toString().trim().split("\n")[0];
String[] teamPerson = team.split(",");
for (int teamIndex = 0; teamIndex < teamPerson.length; teamIndex++) {
if (dayShift.get(teamPerson[teamIndex]) == null) {
dayShift.put(teamPerson[teamIndex], 1);
} else {
dayShift.put(teamPerson[teamIndex], dayShift.get(teamPerson[teamIndex]) + 1);
}
}
}
} else if (rowIndex >= 4 && (rowIndex - 4) % 4 == 0) {
for (int colIndex = 2; colIndex <= 8; colIndex++) {
Cell cellCurrent = rowCurrent.getCell(colIndex);
if (cellCurrent != null) {
cellCurrent.setCellType(Cell.CELL_TYPE_STRING);
}
String team = cellCurrent.toString().trim().split("\n")[0];
String[] teamPerson = team.split(",");
for (int teamIndex = 0; teamIndex < teamPerson.length; teamIndex++) {
if (nightShift.get(teamPerson[teamIndex]) == null) {
nightShift.put(teamPerson[teamIndex], 1);
} else {
nightShift.put(teamPerson[teamIndex], nightShift.get(teamPerson[teamIndex]) + 1);
}
}
}
}
} outputSort("白班", dayShift, dutyMap);
outputSort("夜班", nightShift, dutyMap);
} /**
*
* @param str
* 说明白班还是夜班
* @param map
* 员工及值班个数HashMap
* @param mapDim
* 值班维表
*/
public static void outputSort(String str, Map<String, Integer> map, Map<String, String> mapDim) { List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(map.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
@Override
public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
return -(o1.getValue() - o2.getValue());
}
}); System.out.println("===================" + str + "======================");
for (int index = 0; index < list.size(); index++) {
System.out.println(list.get(index).getKey() + "==" + mapDim.get(list.get(index).getKey()) + "=="
+ list.get(index).getValue());
}
} /**
*
* @param str
* 说明白班还是夜班
* @param map
* 员工及值班个数HashMap
* @param mapDim
* 值班维表
*/
public static void output(String str, Map<String, Integer> map, Map<String, String> mapDim) {
System.out.println("===================" + str + "======================");
Set<Entry<String, Integer>> dayEntities = map.entrySet();
for (Entry<String, Integer> en : dayEntities) {
System.out.println(en.getKey() + "---" + mapDim.get(en.getKey()) + "---" + en.getValue());
}
}
}

读取excel数据,并进行统计输出的更多相关文章

  1. 读取excel数据,并统计输出Frame版本

    package cn.cnnic.ops; import java.awt.Button; import java.awt.FileDialog; import java.awt.FlowLayout ...

  2. JAVA反射机制示例,读取excel数据映射到JAVA对象中

    import java.beans.PropertyDescriptor; import java.io.File; import java.io.FileInputStream; import ja ...

  3. jxl读写excel, poi读写excel,word, 读取Excel数据到MySQL

    这篇blog是介绍: 1. java中的poi技术读取Excel数据,然后保存到MySQL数据中. 2. jxl读写excel 你也可以在 : java的poi技术读取和导入Excel了解到写入Exc ...

  4. Java读取Excel数据

    Java读取Excel数据,解析文本并格式化输出 Java读取Excel数据,解析文本并格式化输出 Java读取Excel数据,解析文本并格式化输出 下图是excel文件的路径和文件名 下图是exce ...

  5. 性能测试工具LoadRunner27-LR之读取Excel数据

    为何要读取Excel数据? 很多用户喜欢用Excel来统计数据,比如学生成绩表.个人信息等.有时需要把Excel中的数据来进行参数化,数据量比较多时,一个个在LR里输入是不现实的,因此需要用LR来导入 ...

  6. java的poi技术读取Excel数据到MySQL

    这篇blog是介绍java中的poi技术读取Excel数据,然后保存到MySQL数据中. 你也可以在 : java的poi技术读取和导入Excel了解到写入Excel的方法信息 使用JXL技术可以在 ...

  7. .NET读取Excel数据,提示错误:未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序

    解决.NET读取Excel数据时,提示错误:未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序的操作: 1. 检查本机是否安装Office Access,如果未安装去去h ...

  8. oledbdataadapter 读取excel数据时,有的单元格内容不能读出

    表现:excel中某列中,有的单元格左上角有绿色箭头标志,有的没有,c#编写读取程序,但是只能读取出带绿色箭头的单元格中的内容,其余不带的读取不到内容 原因:excel中单元格因为是文本格式而存储了数 ...

  9. Openxml入门---Openxm读取Excel数据

    Openxml读取Excel数据: 有些问题,如果当Cell 里面是 日期和浮点型的话,对应的Cell.DataType==Null,对应的时间会转换为一个浮点型,对于这块可以通过DateTime.F ...

  10. C# 读取EXCEL数据

       /// <summary> /// 读取EXCEL数据 /// </summary> /// <param name="Path">< ...

随机推荐

  1. java1234教程系列笔记 S1 Java SE chapter 02 写乘法口诀表

    一.水仙花数 1.方式一:这是我的思路,取各个位数的方式.我个人习惯于使用取模运算. public static List<Integer> dealNarcissiticNumberMe ...

  2. [2016.01.01]万峰文本处理专家 v2.0

    <万峰文本处理专家>是一款简单易用,且功能强大的各类文本文件处理软件.1.支持多任务的处理模式,允许一次处理多个任务.2.支持正则表达式替换,替换更加强大:3.支持各类关键字的行处理操作: ...

  3. SSIS 文件系统任务无法使用变量配置目标路径

    SSIS 文件系统任务无法使用变量配置目标路径 需求: 在SSIS2012中,某个从平面文件导入数据的包中,需要把处理出错的文件拷贝到一个专门的文件夹,便于管理人员及时处理. 问题描述: 1. 在包参 ...

  4. Rails 4.0 移除了 XML 参数解析器。若要使用请加入 actionpack-xml_parser

    拜读了用 Rails 搭建微信公众平台 API之后发现, params[:xml]这个办法在Rails 4里面已经被办掉了,于是就看了一下Rails 4的新特性发现XML Parameter pars ...

  5. MSSQL 多行合并为一行

    select ptl_a01, ptl_piitem, ( ) as ptl_count, STUFF((SELECT ','+ltrim(ptl_pdid) FROM PRODUCT_TRACEAB ...

  6. oracle中找出某个字段中有非数字型的记录

    工作中遇到一个大表记录中有非法非数字字符,不想用正则语法去做, 用一条SQL语句查出来的方法如下: select * from table where translate(col,'*01234567 ...

  7. Android Event

    2016-10-11 http://p.codekk.com/detail/Android/wcy10586/androidEvent https://my.oschina.net/u/191330/ ...

  8. HDU 1556 Color the ball(线段树区间更新)

    Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...

  9. php生成curl命令行

    e.g. curl “http://localhost/other/serverInfo.php?dd=ddd” -H “Host:localhost” -H “Connection:keep-ali ...

  10. java.lang.NoClassDefFoundError 解决方案

    http://stackoverflow.com/questions/9870995/android-java-lang-noclassdeffounderror 像网络了上说的一般这种问题是 运行时 ...