Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用java从excel中提取重复记录并写入新文件_Java_Excel_Duplicates_Apache Poi - Fatal编程技术网

如何使用java从excel中提取重复记录并写入新文件

如何使用java从excel中提取重复记录并写入新文件,java,excel,duplicates,apache-poi,Java,Excel,Duplicates,Apache Poi,我可以使用下面的代码读取一列0的数据。我需要获取列0中存在的重复值的记录 FileInputStream fis = new FileInputStream(theNewestFile); XSSFWorkbook workbook = new XSSFWorkbook(fis); XSSFSheet spreadsheet = workbook.getSheetAt(0); XSSFRow row; String cellValueMaybeNull; List<Cell> cel

我可以使用下面的代码读取一列0的数据。我需要获取列0中存在的重复值的记录

FileInputStream fis = new FileInputStream(theNewestFile);
XSSFWorkbook workbook = new XSSFWorkbook(fis);
XSSFSheet spreadsheet = workbook.getSheetAt(0);
XSSFRow row;
String cellValueMaybeNull;
List<Cell> cells = new ArrayList<Cell>();

for (int rowIndex = 0; rowIndex <= spreadsheet.getLastRowNum(); rowIndex++) {
    row = (XSSFRow) spreadsheet.getRow(rowIndex);
    if (row != null) {
        int colIndex = 0;
        Cell cell = row.getCell(colIndex);
        if (cell != null) {
            // Found column and there is value in the cell.
            cellValueMaybeNull = cell.getStringCellValue();
            // Do something with the cellValueMaybeNull here ...
            System.out.println(cellValueMaybeNull);

        }
    }
} 
FileInputStream fis=新文件inputstream(新文件);
XSSF工作簿=新XSSF工作簿(fis);
XSSFSheet电子表格=工作簿.getSheetAt(0);
XSSFRow行;
字符串cellValueMaybeNull;
列表单元格=新的ArrayList();

对于(int rowIndex=0;rowIndex声明一个映射,捕获所有重复项并稍后打印。如果列表大小大于1,则为重复案例场景

FileInputStream fis = new FileInputStream(theNewestFile);
XSSFWorkbook workbook = new XSSFWorkbook(fis);
XSSFSheet spreadsheet = workbook.getSheetAt(0);
XSSFRow row;
String cellValueMaybeNull;
List<Cell> cells = new ArrayList<Cell>();

Map<String,List<String>> duplicateCheck = new HashMap<String,List<String>>();
for (int rowIndex = 0; rowIndex <= spreadsheet.getLastRowNum(); rowIndex++) {
         row = (XSSFRow) spreadsheet.getRow(rowIndex);
         if (row != null) {
           int colIndex = 0;
           Cell cell = row.getCell(colIndex);
           if (cell != null) {
           // Found column and there is value in the cell.
           cellValueMaybeNull = cell.getStringCellValue();
           // Do something with the cellValueMaybeNull here ...
           if(duplicateCheck.get(cellValueMaybeNull) != null) {
                 duplicateCheck.get(cellValueMaybeNull).add(cellValueMaybeNull);
           }
           else {
           List<String> list = new ArrayList<String>();
               list.add(cellValueMaybeNull);
               duplicateCheck.put(cellValueMaybeNull, list);
            }

               }
            }
        } 

for(List<String> duplicateValue : duplicateCheck.values()) {
            if(duplicateValue.size() > 1) {
                System.out.println("Duplicate values :"+duplicateValue);
            }
        }
FileInputStream fis=新文件inputstream(新文件);
XSSF工作簿=新XSSF工作簿(fis);
XSSFSheet电子表格=工作簿.getSheetAt(0);
XSSFRow行;
字符串cellValueMaybeNull;
列表单元格=新的ArrayList();
Map duplicateCheck=新建HashMap();
对于(int-rowIndex=0;rowIndex 1){
System.out.println(“重复值:“+duplicateValue”);
}
}

这将返回第0列中的重复记录。但必须在下一列中捕获该重复记录的所有记录