首页 > 解决方案 > 在Apache POI JAVA中将单元格添加到Excel工作表的下一个空行

问题描述

我正在开发一个从 excel 文件导入信息然后将其保存在第二个文件中的项目。我得到以下变量,我需要将它们作为单独的单元格存储在新行中

userID = "" + importUsers.getSheetAt(0).getRow(counter).getCell(5); computername = "" + importUsers.getSheetAt(0).getRow(counter).getCell(21); location = "" + importUsers.getSheetAt(0).getRow(counter).getCell(14); migID = "" + importUsers.getSheetAt(0).getRow(counter).getCell(0);

然后我创建一个 enterInfo.java 的实例

new enterInfo(userID, computername, location,migID,row);

这导致了这个类

public class enterInfo extends JFrame{

    public enterInfo(String userID, String computername, String location, String migID, int row) throws InvalidFormatException, IOException  {
        System.out.println("adding...");

        File workbookFile = new File("C:\\Users\\strinca1\\Decomp\\activeUsers.xlsx.xlsx");
        FileInputStream file = new FileInputStream(workbookFile);
        Workbook activeUsers = WorkbookFactory.create(file);
        Row reihe = activeUsers.getSheetAt(0).createRow((short)row);
        // Create a cell and put a value in it.
        Cell cell = reihe.createCell(0);
        cell.setCellValue(1);

    }
}

然而,它并没有添加任何东西activeUsers.xlsx.xlsx

我找不到哪里出错了

感谢您提前提供任何帮助

标签: javaexcelapache-poi

解决方案


推荐阅读