Data_Process.java
package com;
import java.util.List;
import java.util.Map;
public class DataProcessing {
public static void main(String[] args) {
String TeamTrackSource = System.getProperty(“C:\wz\Crester\9-20\marked//FEM.xlsx”);
String JiraSource = System.getProperty(“C:\wz\Crester\-20\JIRAxlsx//Jira_FEM_new.xlsx”);
String TargetPath = “C:\wz\Crester”;
// String TeamTrackSource = System.getProperty(“TeamTrackSource”);
// String JiraSource = System.getProperty(“JiraSource”);
// String TargetPath = System.getProperty(“TargetPath”);
int [] TeamTrack1 = Utils.readTeamTrackFileList(TeamTrackSource,0,5);
int [] jira1 = Utils.readJiraFileList(JiraSource,0,0);
List<List> TeamTrackList = Utils.readTeamTrackFile(TeamTrackSource,0,TeamTrack1);
List<List> Jira_List = Utils.readAssignByJiraExcel(JiraSource,0,jira1);
Map map = MapTest.test2(TeamTrackList,Jira_List);
//导出数据
// DataEx.Log(“Final Result:”,“C:\wz\Crester”);
// DataEx.Log(“Final Result:”,TargetPath);
System.out.println(map.get(“errorList”));
System.out.println(map.get(“unExistList”));
}
}
Utils.java
package com;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.util.StringUtil;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.;
import java.text.SimpleDateFormat;
import java.util.;
public class Utils {
//读取excel
public static org.apache.poi.ss.usermodel.Workbook readExcel(String filePath) {
org.apache.poi.ss.usermodel.Workbook wb = null;
if (filePath == null) {
return null;
}
String extString = filePath.substring(filePath.lastIndexOf("."));
InputStream is = null;
try {
is = new FileInputStream(filePath);
if (".xls".equals(extString)) {
return wb = new HSSFWorkbook(is);
} else if (".xlsx".equals(extString)) {
return wb = new XSSFWorkbook(is);
// return wb = new SXSSFWorkbook(new XSSFWorkbook(is));
} else {
return wb = null;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return wb;
}
//获取指定colnum
public static List<List> readAssignByExcel(String file, int index, int[] a) {
List<List> list = new ArrayList<>();
// List list2= new ArrayList();
try {
org.apache.poi.ss.usermodel.Sheet sheet = null;
org.apache.poi.ss.usermodel.Workbook wb = readExcel(file);
sheet = wb.getSheetAt(index);
int rows = sheet.getPhysicalNumberOfRows();
// System.out.println(rows);
// int col2= sheet.getLastRowNum();
// System.out.println(“col2 : “+col2);
Row row = sheet.getRow(0);
for (int i = 6; i < rows; i++) {
List li = new ArrayList<>();
Row row1 = sheet.getRow(i);
int colnum1 = row1.getPhysicalNumberOfCells();
for (int j = 0; j < colnum1 ; j++) {
//获取指定列数的值index=0、1、…
for (int a1 : a) {
if (a1 == j) {
if (row1.getCell(j) == null) {
li.add(””);
} else {
li.add(row1.getCell(j).toString());
}
}
}
}
list.add(li);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
//获取指定colnum others
public static List<List> readAssignByExcelothers(String file, int index, int[] a) {
List<List> list = new ArrayList<>();
// List list2= new ArrayList();
try {
org.apache.poi.ss.usermodel.Sheet sheet = null;
org.apache.poi.ss.usermodel.Workbook wb = readExcel(file);
sheet = wb.getSheetAt(index);
int rows = sheet.getPhysicalNumberOfRows();
// System.out.println(rows);
// int col2= sheet.getLastRowNum();
// System.out.println(“col2 : “+col2);
Row row = sheet.getRow(0);
for (int i = 6; i < rows +10; i++) {
List li = new ArrayList<>();
Row row1 = sheet.getRow(i);
if(row1 == null){
continue;
}
int colnum1 = row1.getPhysicalNumberOfCells();
for (int j = 0; j < colnum1 +10 ; j++) {
//获取指定列数的值index=0、1、…
for (int a1 : a) {
if (a1 == j) {
if (row1.getCell(j) == null) {
li.add(””);
} else {
li.add(row1.getCell(j).toString());
}
}
}
}
list.add(li);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
//获取指定colnum other
public static List<List> readAssignByExcelother(String file, int index, int[] a) {
List<List> list = new ArrayList<>();
// List list2= new ArrayList();
try {
org.apache.poi.ss.usermodel.Sheet sheet = null;
org.apache.poi.ss.usermodel.Workbook wb = readExcel(file);
sheet = wb.getSheetAt(index);
int rows = sheet.getPhysicalNumberOfRows();
// System.out.println(rows);
// int col2= sheet.getLastRowNum();
// System.out.println(“col2 : “+col2);
Row row = sheet.getRow(0);
for (int i = 6; i < rows + 1; i++) {
List li = new ArrayList<>();
Row row1 = sheet.getRow(i);
int colnum1 = row1.getPhysicalNumberOfCells();
for (int j = 0; j < colnum1 ; j++) {
//获取指定列数的值index=0、1、…
for (int a1 : a) {
if (a1 == j) {
if (row1.getCell(j) == null) {
li.add(””);
} else {
li.add(row1.getCell(j).toString());
}
}
}
}
list.add(li);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
//获取指定colnum mayaetl
public static List<List> readAssignByExcelmayaetl(String file, int index, int[] a) {
List<List> list = new ArrayList<>();
// List list2= new ArrayList();
try {
org.apache.poi.ss.usermodel.Sheet sheet = null;
org.apache.poi.ss.usermodel.Workbook wb = readExcel(file);
sheet = wb.getSheetAt(index);
int rows = sheet.getPhysicalNumberOfRows();
// System.out.println(rows);
// int col2= sheet.getLastRowNum();
// System.out.println(“col2 : “+col2);
Row row = sheet.getRow(0);
for (int i = 6; i < rows +1; i++) {
List li = new ArrayList<>();
Row row1 = sheet.getRow(i);
int colnum1 = row1.getPhysicalNumberOfCells();
for (int j = 0; j < colnum1 ; j++) {
//获取指定列数的值index=0、1、…
for (int a1 : a) {
if (a1 == j) {
if (row1.getCell(j) == null) {
li.add(””);
} else {
li.add(row1.getCell(j).toString());
}
}
}
}
list.add(li);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
//获取指定colnum ilevel
public static List<List> readAssignByExcelilevel(String file, int index, int[] a) {
List<List> list = new ArrayList<>();
// List list2= new ArrayList();
try {
org.apache.poi.ss.usermodel.Sheet sheet = null;
org.apache.poi.ss.usermodel.Workbook wb = readExcel(file);
sheet = wb.getSheetAt(index);
int rows = sheet.getPhysicalNumberOfRows();
// System.out.println(rows);
// int col2= sheet.getLastRowNum();
// System.out.println(“col2 : “+col2);
Row row = sheet.getRow(0);
for (int i = 6; i < rows+1; i++) {
List li = new ArrayList<>();
Row row1 = sheet.getRow(i);
int colnum1 = row1.getPhysicalNumberOfCells();
for (int j = 0; j < colnum1 ; j++) {
//获取指定列数的值index=0、1、…
for (int a1 : a) {
if (a1 == j) {
if (row1.getCell(j) == null) {
li.add(””);
} else {
li.add(row1.getCell(j).toString());
}
}
}
}
list.add(li);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
//获取指定colnum icrm
public static List<List> readAssignByExcelicrm(String file, int index, int[] a) {
List<List> list = new ArrayList<>();
// List list2= new ArrayList();
try {
org.apache.poi.ss.usermodel.Sheet sheet = null;
org.apache.poi.ss.usermodel.Workbook wb = readExcel(file);
sheet = wb.getSheetAt(index);
int rows = sheet.getPhysicalNumberOfRows();
// System.out.println(rows);
// int col2= sheet.getLastRowNum();
// System.out.println(“col2 : “+col2);
Row row = sheet.getRow(0);
for (int i = 6; i < rows+1; i++) {
List li = new ArrayList<>();
Row row1 = sheet.getRow(i);
int colnum1 = row1.getPhysicalNumberOfCells();
for (int j = 0; j < colnum1+10 ; j++) {
//获取指定列数的值index=0、1、…
for (int a1 : a) {
if (a1 == j) {
if (row1.getCell(j) == null) {
li.add(””);
} else {
if(j == 0){
//去掉0
int o1 = Integer.parseInt(row1.getCell(j).toString());
String stro1 = String.valueOf(o1);
li.add(stro1);
}else {
li.add(row1.getCell(j).toString());
}
}
}
}
}
list.add(li);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
//获取指定colnumibor
public static List<List> readAssignByExcelibor(String file, int index, int[] a) {
List<List> list = new ArrayList<>();
// List list2= new ArrayList();
try {
org.apache.poi.ss.usermodel.Sheet sheet = null;
org.apache.poi.ss.usermodel.Workbook wb = readExcel(file);
sheet = wb.getSheetAt(index);
int rows = sheet.getPhysicalNumberOfRows();
// System.out.println(rows);
// int col2= sheet.getLastRowNum();
// System.out.println(“col2 : “+col2);
Row row = sheet.getRow(0);
for (int i = 6; i < rows+1; i++) {
List li = new ArrayList<>();
Row row1 = sheet.getRow(i);
int colnum1 = row1.getPhysicalNumberOfCells();
for (int j = 0; j < colnum1 ; j++) {
//获取指定列数的值index=0、1、…
for (int a1 : a) {
if (a1 == j) {
if (row1.getCell(j) == null) {
li.add(””);
} else {
li.add(row1.getCell(j).toString());
}
}
}
}
list.add(li);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
//获取指定colnumica
public static List<List> readAssignByExcelca(String file, int index, int[] a) {
List<List> list = new ArrayList<>();
// List list2= new ArrayList();
try {
org.apache.poi.ss.usermodel.Sheet sheet = null;
org.apache.poi.ss.usermodel.Workbook wb = readExcel(file);
sheet = wb.getSheetAt(index);
int rows = sheet.getPhysicalNumberOfRows();
// System.out.println(rows);
// int col2= sheet.getLastRowNum();
// System.out.println(“col2 : “+col2);
Row row = sheet.getRow(0);
for (int i = 6; i < rows+1; i++) {
List li = new ArrayList<>();
Row row1 = sheet.getRow(i);
int colnum1 = row1.getPhysicalNumberOfCells();
for (int j = 0; j < colnum1+10; j++) {
//获取指定列数的值index=0、1、…
for (int a1 : a) {
if (a1 == j) {
if (row1.getCell(j) == null) {
li.add(””);
} else {
li.add(row1.getCell(j).toString());
}
}
}
}
list.add(li);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
//获取指定colnumifem
public static List<List> readAssignByExcelfem(String file, int index, int[] a) {
List<List> list = new ArrayList<>();
// List list2= new ArrayList();
try {
org.apache.poi.ss.usermodel.Sheet sheet = null;
org.apache.poi.ss.usermodel.Workbook wb = readExcel(file);
sheet = wb.getSheetAt(index);
int rows = sheet.getPhysicalNumberOfRows();
// System.out.println(rows);
// int col2= sheet.getLastRowNum();
// System.out.println(“col2 : “+col2);
Row row = sheet.getRow(0);
for (int i = 6; i < rows+1; i++) {
List li = new ArrayList<>();
Row row1 = sheet.getRow(i);
int colnum1 = row1.getPhysicalNumberOfCells();
for (int j = 0; j < colnum1 +10 ; j++) {
//获取指定列数的值index=0、1、…
for (int a1 : a) {
if (a1 == j) {
if (row1.getCell(j) == null) {
li.add(””);
} else {
li.add(row1.getCell(j).toString());
}
}
}
}
list.add(li);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
//获取指定colnum
public static List<List> readAssignByExcel1(String file, int index, int[] a) {
List<List> list = new ArrayList<>();
try {
org.apache.poi.ss.usermodel.Sheet sheet = null;
org.apache.poi.ss.usermodel.Workbook wb = readExcel(file);
sheet = wb.getSheetAt(index);
int rows = sheet.getPhysicalNumberOfRows();
Row row = sheet.getRow(0);
for (int i = 6; i < rows + 1; i++) {
List<String> li = new ArrayList<>();
Row row1 = sheet.getRow(i);
int colnum1 = row1.getPhysicalNumberOfCells();
for (int j = 0; j < colnum1 + 33; j++) {
//获取指定列数的值index=0、1、.....
for (int a1 : a) {
if (a1 == j) {
if (row1.getCell(j) == null) {
li.add("");
} else {
if(j == 0){
int o1 = Integer.parseInt(row1.getCell(j).toString());
String stro1 = String.valueOf(o1);
li.add(stro1);
}else {
li.add(row1.getCell(j).toString());
}
}
}
}
//
}
list.add(li);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
//获取指定colnum
public static List<List> readAssignByExcelibor_it(String file, int index, int[] a) {
List<List> list = new ArrayList<>();
try {
org.apache.poi.ss.usermodel.Sheet sheet = null;
org.apache.poi.ss.usermodel.Workbook wb = readExcel(file);
sheet = wb.getSheetAt(index);
int rows = sheet.getPhysicalNumberOfRows();
Row row = sheet.getRow(0);
for (int i = 6; i < rows+1; i++) {
List<String> li = new ArrayList<>();
Row row1 = sheet.getRow(i);
int colnum1 = row1.getPhysicalNumberOfCells();
for (int j = 0; j < colnum1 + 33; j++) {
//获取指定列数的值index=0、1、.....
for (int a1 : a) {
if (a1 == j) {
if (row1.getCell(j) == null) {
li.add("");
} else {
li.add(row1.getCell(j).toString());
}
}
}
//
}
list.add(li);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
//获取指定Jira colnum
public static List<List> readAssignByJiraExcel(String file, int index, int[] a) {
List<List> list = new ArrayList<>();
try {
org.apache.poi.ss.usermodel.Sheet sheet = null;
org.apache.poi.ss.usermodel.Workbook wb = readExcel(file);
sheet = wb.getSheetAt(index);
int rows = sheet.getPhysicalNumberOfRows();
Row row = sheet.getRow(0);
for (int i = 1; i < rows; i++) {
List<String> li = new ArrayList<>();
Row row1 = sheet.getRow(i);
int colnum1 = row1.getPhysicalNumberOfCells();
for (int j = 0; j < colnum1 + 33; j++) {
//获取指定列数的值index=0、1、.....
for (int a1 : a) {
if (a1 == j) {
if (row1.getCell(j) == null) {
li.add("");
} else {
li.add(rvZeroAndDot(row1.getCell(j).toString()));
}
}
}
//
}
list.add(li);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
//去掉小数点后多余的零
public static String rvZeroAndDot(String s) {
if (s.isEmpty()) {
return null;
}
if (s.indexOf(".") > 0) {
s = s.replaceAll("0+?$", "");//去掉多余的0
s = s.replaceAll("[.]$", "");//如最后一位是.则去掉
}
return s;
}
//找差集 FindDiff
public static List findDiff(List list, List list1) {
List arrList = new ArrayList();
for(int i = 0; i < list.size(); i++) {
int o = 0;
String str = list.get(i).toString();
for(int j = 0; j < list1.size(); j++){
String str1 = list1.get(j).toString();
if(str.equals(str1)){
o=o+1;
}
}
if(o == 0){
arrList.add(str);
}
}
return arrList;
}
//找交集 intersection
public static List<List> findIntersection( List<List> list1,List list) {
List<List> arrList = new ArrayList();
for(int i = 0; i < list1.size(); i++) {
for(int j = 0; j < list.size(); j++){
if(list.get(i).toString().equals(list1.get(j).get(7))){
arrList.add(list1.get(i));
}
}
}
return arrList;
}
//获取指定colnum others
public static List<List> readTeamTrackFile(String file, int index, int[] a) {
List<List> list = new ArrayList<>();
// List list2= new ArrayList();
try {
org.apache.poi.ss.usermodel.Sheet sheet = null;
org.apache.poi.ss.usermodel.Workbook wb = readExcel(file);
sheet = wb.getSheetAt(index);
int rows = sheet.getPhysicalNumberOfRows();
// System.out.println(rows);
// int col2= sheet.getLastRowNum();
// System.out.println(“col2 : “+col2);
Row row = sheet.getRow(0);
for (int i = 6; i < rows +10; i++) {
List li = new ArrayList<>();
Row row1 = sheet.getRow(i);
if(row1 == null){
continue;
}
int colnum1 = row1.getPhysicalNumberOfCells();
for (int j = 0; j < colnum1 +10 ; j++) {
//获取指定列数的值index=0、1、…
for (int a1 : a) {
if (a1 == j) {
if (row1.getCell(j) == null) {
li.add(””);
} else {
if(j == 0){
//去掉0
int o1 = Integer.parseInt(row1.getCell(j).toString());
String stro1 = String.valueOf(o1);
li.add(stro1);
}else {
li.add(row1.getCell(j).toString());
}
}
}
}
}
list.add(li);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
//获取TeamTrack colnum 数组
public static int [] readTeamTrackFileList(String file, int index,int a) {
List<List> list = new ArrayList<>();
int [] temp = new int[8];
// List list2= new ArrayList();
try {
org.apache.poi.ss.usermodel.Sheet sheet = null;
org.apache.poi.ss.usermodel.Workbook wb = readExcel(file);
sheet = wb.getSheetAt(index);
int rows = sheet.getPhysicalNumberOfRows();
// System.out.println(rows);
// int col2= sheet.getLastRowNum();
// System.out.println("col2 : "+col2);
Row row = sheet.getRow(a);
int colnum1 = row.getPhysicalNumberOfCells();
for (int j = 0; j < colnum1+10 ; j++) {
//获取指定列数的值index=0、1、.....
if(row.getCell(j)==null){
break;
}
if (row.getCell(j).toString().equals("Item Id")) {
System.out.println(row.getCell(j).toString());
temp [0]=j;
}
if (row.getCell(j).toString().equals("Title")) {
System.out.println(row.getCell(j).toString());
temp [1]=j;
}
if (row.getCell(j).toString().equals("Assigned To")) {
System.out.println(row.getCell(j).toString());
temp [2]=j;
}
if (row.getCell(j).toString().equals("Country")) {
System.out.println(row.getCell(j).toString());
temp [3]=j;
}
if (row.getCell(j).toString().equals("Item Type")) {
System.out.println(row.getCell(j).toString());
temp [4]=j;
}
if (row.getCell(j).toString().equals("Last Modified Date")) {
System.out.println(row.getCell(j).toString());
temp [5]=j;
}
if (row.getCell(j).toString().equals("Severity")) {
System.out.println(row.getCell(j).toString());
temp [6]=j;
}
if (row.getCell(j).toString().equals("Submitter")) {
System.out.println(row.getCell(j).toString());
temp [7]=j;
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return temp;
}
//获取TeamTrack colnum 数组 两个字段
public static int [] readTeamTrackFileList2(String file, int index,int a) {
List<List> list = new ArrayList<>();
int [] temp = new int[2];
try {
org.apache.poi.ss.usermodel.Sheet sheet = null;
org.apache.poi.ss.usermodel.Workbook wb = readExcel(file);
sheet = wb.getSheetAt(index);
Row row = sheet.getRow(a);
int colnum1 = row.getPhysicalNumberOfCells();
for (int j = 0; j < colnum1+10 ; j++) {
//获取指定列数的值index=0、1、.....
if(row.getCell(j)==null){
continue;
}
if (row.getCell(j).toString().equals("Item Id")) {
// System.out.println(row.getCell(j).toString());
temp [0]=j;
}
if (row.getCell(j).toString().equals(“Title”)) {
// System.out.println(row.getCell(j).toString());
temp [1]=j;
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return temp;
}
//获取TeamTrack colnum 数组
public static int [] readJiraFileList (String file, int index,int a) {
List<List> list = new ArrayList<>();
int [] temp = new int[8];
try {
org.apache.poi.ss.usermodel.Sheet sheet = null;
org.apache.poi.ss.usermodel.Workbook wb = readExcel(file);
sheet = wb.getSheetAt(index);
int rows = sheet.getPhysicalNumberOfRows();
Row row = sheet.getRow(a);
int colnum1 = row.getPhysicalNumberOfCells();
for (int j = 0; j < colnum1+10 ; j++) {
//获取指定列数的值index=0、1、.....
if(row.getCell(j)==null){
break;
}
if (row.getCell(j).toString().equals("Summary")) {
System.out.println(row.getCell(j).toString());
temp [0]=j;
}
if (row.getCell(j).toString().equals("Invest_report_itemtype")) {
System.out.println(row.getCell(j).toString());
temp [1]=j;
}
if (row.getCell(j).toString().equals("Severity")) {
System.out.println(row.getCell(j).toString());
temp [2]=j;
}
if (row.getCell(j).toString().equals("Updated")) {
System.out.println(row.getCell(j).toString());
temp [3]=j;
}
if (row.getCell(j).toString().equals("TT_Assignee")) {
System.out.println(row.getCell(j).toString());
temp [4]=j;
}
if (row.getCell(j).toString().equals("TT_Country")) {
System.out.println(row.getCell(j).toString());
temp [5]=j;
}
if (row.getCell(j).toString().equals("TT_Submitter")) {
System.out.println(row.getCell(j).toString());
temp [6]=j;
}
if (row.getCell(j).toString().equals("Team Track ID")) {
System.out.println(row.getCell(j).toString());
temp [7]=j;
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return temp;
}
//获取TeamTrack colnum 数组 2
public static int [] readJiraFileList2 (String file, int index,int a) {
List<List> list = new ArrayList<>();
int [] temp = new int[2];
try {
org.apache.poi.ss.usermodel.Sheet sheet = null;
org.apache.poi.ss.usermodel.Workbook wb = readExcel(file);
sheet = wb.getSheetAt(index);
Row row = sheet.getRow(a);
int colnum1 = row.getPhysicalNumberOfCells();
for (int j = 0; j < colnum1+10 ; j++) {
//获取指定列数的值index=0、1、.....
if(row.getCell(j)==null){
continue;
}
if (row.getCell(j).toString().equals("Summary")) {
// System.out.println(row.getCell(j).toString());
temp [0]=j;
}
if (row.getCell(j).toString().equals(“Team Track ID”)) {
// System.out.println(row.getCell(j).toString());
temp [1]=j;
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return temp;
}
}