Java 将其他工作表中的行复制到新工作表中

Java 将其他工作表中的行复制到新工作表中,java,excel,apache-poi,Java,Excel,Apache Poi,我正在使用apache poi,我想做的是: 我有一张这样的工作表,我想将具有特定名称的行处理为另一张这样的工作表: 对于此操作,我编写了几行代码: public void read() throws Exception { InputStream inp = new FileInputStream(inputFile); System.out.println(inputFile); // InputStream inp = new FileInputStream("

我正在使用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();
    }
}
public void read()引发异常{
InputStream Input=新文件InputStream(inputFile);
System.out.println(输入文件);
//InputStream inp=新文件InputStream(“workbook.xlsx”);
wb=WorkbookFactory.create(inp);
Sheet Sheet=wb.getSheetAt(0);
//1.获取数组列表中的名称值
用于(第r行:页){
细胞c=r.getCell(4);
c、 setCellType(Cell.Cell\u TYPE\u字符串);
如果(c!=null){
nameList.add(c.getStringCellValue());
}
}
//2.删除重复项
移除的副本(名称列表);
用于(第r行:页){
细胞c=r.getCell(4);
c、 setCellType(Cell.Cell\u TYPE\u字符串);
//创建新工作簿
工作簿=新的HSSF工作簿();
对于(int i=0;i

如您所见,我正在努力使用
从另一个图纸部分获取行。我非常感谢您回答如何实现这一点?

您是否有任何错误,或者它不是您所期望的那样?@SachinThapa Nope还没有。但是我正在绞尽脑汁想办法从另一张纸上得到所有的行。。。