1

我有一个非常大的 Excel 表(大约 30,000 多个)记录房价及其位置(纬度和经度值)。目前,我可以使用 Apache POI 将部分 excel 表解析到 Eclipse 控制台中。但是,如果它们在用户给定纬度和经度的 x KM 的半径内,是否可以只返回某些行及其房价?

我被引导相信haversine公式可以用来计算这样的东西,但我已经碰到了一堵墙,我将如何开始将它实现到这样的程序中。

public class ExcelReader {

    public static final String SAMPLE_XLSX_FILE_PATH = "./LatLongPrice.xlsx";

    public static void main(String[] args) throws IOException, InvalidFormatException {

        Workbook workbook = WorkbookFactory.create(new File(SAMPLE_XLSX_FILE_PATH));

        // Retrieving the number of sheets in the Workbook
        System.out.println("Workbook has " + workbook.getNumberOfSheets() + " Sheets : ");




        // obtain a sheetIterator and iterate over it
        Iterator<Sheet> sheetIterator = workbook.sheetIterator();
        System.out.println("Retrieving Sheets using Iterator");
        while (sheetIterator.hasNext()) {
            Sheet sheet = sheetIterator.next();
            System.out.println("=> " + sheet.getSheetName());
        }



        // Getting the Sheet at index zero
        Sheet sheet = workbook.getSheetAt(0);

        // Create a DataFormatter to format and get each cell's value as String
        DataFormatter dataFormatter = new DataFormatter();

        // Obtain a rowIterator and columnIterator and iterate over them
        System.out.println("\n\nIterating over Rows and Columns using Iterator\n");
        Iterator<Row> rowIterator = sheet.rowIterator();
        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();

            // Iteratating over the columns of the current row
           Iterator<Cell> cellIterator = row.cellIterator();

            while (cellIterator.hasNext()) {
                Cell cell = cellIterator.next();
                String cellValue = dataFormatter.formatCellValue(cell);
                System.out.print(cellValue + "\t");
            }
            System.out.println();
        }
        });

        // Closing the workbook
        workbook.close();
    }
4

0 回答 0