java怎么存入集合,如何将值从Excel存储到Java中的某些集合

本文介绍如何使用Java代码读取Excel文件,存储MethodName, StatusCode及密码等信息,并以用户输入的用户名为索引,实现高效检索。作者寻求一种方法来存储和访问这些细节,以便处理不同用户权限的订单操作。
摘要由CSDN通过智能技术生成

我有一个如下的Excel文件,

**Method Name** **Status Code** **user** **password**

getLoggedinUserDetails 400 anto test

createRequisition 400 mayank hexgen

excelMDM 400 xxxxx hexgen

createOrder 400 yyyyy hexgen

confirmOrder 400 zzzzz hexgen

我想将上述详细信息保存一些,collection以便我可以访问details by providing username and get the

details like Method Name, Status code,and password.

我尝试过这样的事情,只能存储 method name and status code

package com.hexgen.tools;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;

import java.util.Iterator;

import java.util.LinkedHashMap;

import java.util.Map;

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.Row;

public class TestMethodsDetails {

public Map getKnownGoodMap(String filePath) {

String key = "";

int value = 0;

//filePath="TestMethodDetails.xls";

Map knownGoodMap = new LinkedHashMap();

try {

FileInputStream file = new FileInputStream(new File(filePath));

// Get the workbook instance for XLS file

HSSFWorkbook workbook = new HSSFWorkbook(file);

// Get first sheet from the workbook

HSSFSheet sheet = workbook.getSheetAt(0);

// Iterate through each rows from first sheet

Iterator rowIterator = sheet.iterator();

while (rowIterator.hasNext()) {

Row row = rowIterator.next();

// For each row, iterate through each columns

Iterator cellIterator = row.cellIterator();

while (cellIterator.hasNext()) {

Cell cell = cellIterator.next();

switch (cell.getCellType()) {

case Cell.CELL_TYPE_NUMERIC:

value = (int) cell.getNumericCellValue();

break;

case Cell.CELL_TYPE_STRING:

key = cell.getStringCellValue();

break;

}

if (key != null && value != Integer.MIN_VALUE) {

knownGoodMap.put(key, value);

key = null;

value = Integer.MIN_VALUE;

}

}

}

file.close();

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

return knownGoodMap;

}

public static void main(String[] args) {

TestMethodsDetails details = new TestMethodsDetails();

System.out.println("Method Details : "+details.getKnownGoodMap("TestMethodDetails.xls"));

}

}

上面的代码显示以下内容:

Method Details : {Method Name=0, getLoggedinUserDetails=400, createRequisition=400, excelMDM=400, createOrder=400, confirmOrder=400}

to be frank i really don't know what mechanism to use to store these details so that i enables easy access for me to process details, the user name and password will be different, i have given here some user and password for sample only

请帮助我做到这一点。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值