Hello.
Is there a way to import data (numbers) in to a Java program which will do analysis on the data?
Thanks!
Evelina

Dani AI

Generated

Quick summary for (and followup to ): there are two practical approaches depending on complexity and fidelity required. For simple numeric tables a delimited-text parser (CSV) is the fastest route. For reading native Excel files (.xls and .xlsx) and preserving types, formulas and dates, use a library such as Apache POI. See Apache POI for Java-based Excel handling and OpenCSV for robust CSV parsing: Apache POI , .

Typical workflow with Apache POI: open the workbook with WorkbookFactory, iterate rows, and use a FormulaEvaluator to get a stable numeric value (handles formulas and cached values). The snippet below shows the pattern to extract numeric cell values safely.

try (FileInputStream fis = new FileInputStream("data.xlsx");
     Workbook wb = WorkbookFactory.create(fis)) {
  Sheet sheet = wb.getSheetAt(0);
  FormulaEvaluator eval = wb.getCreationHelper().createFormulaEvaluator();
  for (Row row : sheet) {
    Cell cell = row.getCell(0);
    CellValue cv = eval.evaluate(cell);
    if (cv != null && cv.getCellType() == CellType.NUMERIC) {
      double v = cv.getNumberValue();
      // collect v for analysis
    }
  }
}

Troubleshooting tips: watch for numbers stored as text (trim and parse), Excel dates (Excel stores them as numeric—use POI DateUtil), locale decimal/thousand separators when importing CSV, and memory with very large spreadsheets (use POI's SAX/streaming API for XLSX). Modern Java no longer relies on the old JDBC-ODBC bridge; prefer file-based libraries above registering Excel as an OS data source.

Recommended Answers

All 3 Replies

yes there is! firstly, you need to know how the data is stored in the file (ie., structure, data types etc). Then you can read the file through a java program and do your data analysis.

Do I have to set up the excel file as a data source on my computer like I would do to a database?

Not entirely sure what you meant by "data source" but you need to save your excel file where you know what the data structure, I normally save it as a CSV (comma delimited) coz its easier to read this way and extract my data.
Example you have a table that looks like this in excel:
Age Name year of Birth
20 someone 1985
18 someone1 1988
....(and so on)

If you save this to a CSV file (File > Save as > Save as Type > CSV)
the data in your *.csv file would look like this:

Age,Name,year of Birth
20,someone,1985
18,someone1,1988

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.