如何使用Java将我的数据从excel工作表转储到Mongodb

如何使用Java将我的数据从excel工作表转储到Mongodb,java,mongodb,excel-2010,Java,Mongodb,Excel 2010,我只需要读取我的excel文件,该文件将包含n个列,并使用Java编程将这些数据推送到我的MongoDB中。您考虑过将Apache POI用于电子表格吗?他们对如何读取/写入Excel文件有不同的理解,例如: // Get content of cells // import org.apache.poi.ss.usermodel.*; Sheet sheet1 = wb.getSheetAt(0); for (Row row : sheet1) { for (Cell cell :

我只需要读取我的
excel
文件,该文件将包含n个列,并使用
Java
编程将这些数据推送到我的
MongoDB
中。

您考虑过将Apache POI用于电子表格吗?他们对如何读取/写入Excel文件有不同的理解,例如:

// Get content of cells
// import org.apache.poi.ss.usermodel.*;

Sheet sheet1 = wb.getSheetAt(0);
for (Row row : sheet1) {
    for (Cell cell : row) {
        CellReference cellRef = new CellReference(row.getRowNum(), cell.getColumnIndex());
        System.out.print(cellRef.formatAsString());
        System.out.print(" - ");

        switch (cell.getCellType()) {
            case Cell.CELL_TYPE_STRING:
                System.out.println(cell.getRichStringCellValue().getString());
                break;
            case Cell.CELL_TYPE_NUMERIC:
                if (DateUtil.isCellDateFormatted(cell)) {
                    System.out.println(cell.getDateCellValue());
                } else {
                    System.out.println(cell.getNumericCellValue());
                }
                break;
            case Cell.CELL_TYPE_BOOLEAN:
                System.out.println(cell.getBooleanCellValue());
                break;
            case Cell.CELL_TYPE_FORMULA:
                System.out.println(cell.getCellFormula());
                break;
            default:
                System.out.println();
        }
    }
}

然后,为了将内容映射到MongoDB,您必须使用。关于这一点,我无法给您提供太多信息,因为我只使用过Python驱动程序,但入门手册似乎很容易理解。

到目前为止您尝试了什么?只需导出到CSV并将其作为文本文件阅读即可