将行从另一个工作表复制到新工作表

我使用的是apache poi ,我想要做的是:

在这里输入图像说明

我有一个看起来像这样的工作表,我想处理具有特定名称的行到另一个工作表:

在这里输入图像说明在这里输入图像说明

对于这个操作,我写了一些代码行:

 public void read() throws Exception { InputStream inp = new FileInputStream(inputFile); System.out.println(inputFile); // InputStream inp = new FileInputStream("workbook.xlsx"); wb = WorkbookFactory.create(inp); Sheet sheet = wb.getSheetAt(0); // 1. get the Name Values in an array list for (Row r : sheet) { Cell c = r.getCell(4); c.setCellType(Cell.CELL_TYPE_STRING); if (c != null) { nameList.add(c.getStringCellValue()); } } // 2. Remove the duplicates removeDuplicates(nameList); for (Row r : sheet) { Cell c = r.getCell(4); c.setCellType(Cell.CELL_TYPE_STRING); //Create new workbook Workbook workbook = new HSSFWorkbook(); for (int i = 0; i < nameList.size(); i++) { //if the list with the name equals the cell in the excel sheet if (nameList.get(i).equals(c.toString())) { // Output path fileOut = new FileOutputStream( "C:/Users/Desktop/" + nameList.get(i) + ".xls"); // 3. create workbook and sheet worksheet = workbook.createSheet(nameList.get(i)); //TODO Problem: How to get the rows from the other sheet? System.out.println("Write out Sheet: " + nameList.get(i)); } } workbook.write(fileOut); fileOut.close(); } } 

正如你所看到的,我正在getting the rows from the other sheet part 。 我真的很感激你的答案如何实现呢?