将行从另一个工作表复制到新工作表
我使用的是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
。 我真的很感激你的答案如何实现呢?
- 逐行写入XSSF文件输出stream? (Java中的POI)
- 通过apache poi将图像embedded到excel中
- 获取错误“您的InputStream既不是OLE2stream,也不是OOXMLstream”通过Apache POI创build文件时
- 将所有types的RELATIONS从一个工作簿复制到新的工作簿Apache POI XSSFWorkbook
- 编写大型格式化Excel(.xlsx)时发生Zip-bombexception
- 实现Excel的小计function
- 如何使用Apache POI获取MS Excel的单元格的别名
- 如何使用POI(Eevnt模型)读取密码保护的Excel文件?
- 如何使用Apache POI将图表复制到其他工作表(3.11)