根据Map <string,list <=“”>&gt;解析excel数据并存储结构体

时间:2018-03-13 10:35:57

标签: java apache-poi

我有一张excel表,如下所示

Date    Amount  Client
13/03/2018  79  0017F00000Ujs3C
13/03/2018  86  0017F00000Ujs3C
13/03/2018  50  0017F00000Ujs3C

我需要使用apache POI解析excel文件并按列存储数据

并按照此地图&gt;存储数据结构

这是程序

import java.io.File;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataFormatter;
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[])
    {
        try
        {
        File myFile = new File("C:\\Users\\xxx\\Desktop\\test.xlsx");
        FileInputStream fis = new FileInputStream(myFile);

         Map<String, List<String>> myMaps = new HashMap<String, List<String>>();

        XSSFWorkbook workBook = new XSSFWorkbook(fis);
        int numberofsheetspresent = workBook.getNumberOfSheets();
        DataFormatter dataFormatter = new DataFormatter();
        for (int i = 0; i < numberofsheetspresent; i++) {
            String sheetname = workBook.getSheetName(i);
            XSSFSheet sheet = workBook.getSheet(sheetname);
            for (Row eachRow : sheet) {
                //List rowDataList = new LinkedList();
                for (Cell cellData : eachRow) {
                    String cellValue = dataFormatter.formatCellValue(cellData);
                        System.out.println(cellValue);
                }
            }
        }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }


}

它正在逐行读取数据。你能帮助我如何创建一个 地图&GT;具有上述excel的结构

String   : List

Date     :  {13/03/2018  , 13/03/2018 , 13/03/2018 }
Amount      :  {79  , 86, 50}
Client     :  {0017F00000Ujs3C , 0017F00000Ujs3C, 0017F00000Ujs3C}

0 个答案:

没有答案