通过java从xlsx读取数据时创建仪表板

时间:2017-08-08 09:49:52

标签: java

我有一张xlsx表,其中包含近22000个数据。我必须创建一个仪表板,以图形格式表示数据。我能够通过Java程序使用Apache POI读取数据,存储在hashmap中并获取每个数据的计数。我只想知道如何进一步处理,以便在仪表板或响应图中显示这些数据。

package com.amiku.Excel;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ExcelReader {

    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream(new File("C:\\Users\\amiku\\eclipse-workspace\\Amiku\\cloudstreams-connectors-downloads.xlsx"));

        //create workInstance that refers to .xlsx file
        XSSFWorkbook wb = new XSSFWorkbook(fis);

        //create a sheet  object to retrive the sheet 
        XSSFSheet sheet = wb.getSheetAt(0);

        //that is for evalute the cell type
        FormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
        Map<String, Integer> Details = new HashMap<String,Integer>();
        int i=0;
        List<String> l = new ArrayList<String>();
        for (Row row : sheet) {
            for (Cell cell: row) {
                l.add(cell.getStringCellValue());
                /*HashMap map = new HashMap();
                map.put(cell.getStringCellValue());*/   
            }
            /*switch(formulaEvaluator.evaluateInCell(cell).getCellType())
            {*/
            /*//if cell has a numeric  format
            case Cell.CELL_TYPE_NUMERIC:
                System.out.print(cell.getNumericCellValue() + "\t\t");
                break;
            // if cell has a string format
            case Cell.CELL_TYPE_STRING:
                System.out.print(cell.getStringCellValue() + "\t\t");
                break;
            }*/
            i++;
            System.out.println();
        }
        for (int j = 0; j < l.size(); j++) {
            if (j % 2 == 1) {
                String var = l.get(j);
                if (Details.containsKey(var)) {
                    Details.put(var, Details.get(var) + 1);
                } else {
                    Details.put(var, 1);
                }
            }
        }
        Iterator it = Details.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry pair = (Map.Entry) it.next();
            System.out.println(pair.getKey() + " = " + pair.getValue());
            it.remove(); // avoids a ConcurrentModificationException
        }
    }
}

这是我的xlsx文件: enter image description here

0 个答案:

没有答案