//Read excel row by row, put cell name and cell value to a map for each row.
HashMap getExpectedResult(int rowNum, String filePath, String sheetName){
HashMap<String,String> map = new HashMap<String,String>();
ArrayList<String> cellNames = getCellValues(0,filePath, sheetName);
ArrayList<String> cellValues = getCellValues(rowNum,filePath, sheetName); for(int i=0; i<cellNames.size(); i++){
String dataPointName = cellNames.get(i);
String dataPointValue = cellValues.get(i);
map.put(dataPointName, dataPointValue);
}
return map;
} ArrayList<String> getCellValues(int rowNum, String filePath, String sheetName){
ArrayList<String> cellValues = new ArrayList<String>();
try{
File file = new File(filePath);
XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(filePath));
XSSFSheet sheet = wb.getSheet(sheetName);
Row row = sheet.getRow(rowNum);
String cellValue; if (row != null){
for (int i=8; i<row.getPhysicalNumberOfCells(); i++){
if(rowNum==0){
cellValue = row.getCell(i).getStringCellValue();
}else{
            //if the cell value is blank
if(row.getCell(i).getCellType()==3){
cellValue = row.getCell(i).getStringCellValue();
}else{
cellValue = formatDecimal(row.getCell(i).getNumericCellValue());
}
}
cellValues.add(cellValue);
}
}
return cellValues;
}
catch (Exception e){
e.printStackTrace();
return null;
}
} String formatDecimal(double value){
DecimalFormat df = new DecimalFormat("#.#####");
return df.format(value);
}
accountId Pref Stock % (Long) Other % (Long) Cash   % (Short)
50000642   49.127922356 14.3256467556

Read excel and put cell data into HashMap的更多相关文章

  1. java 读取excel poi 和cell 方法

    http://poi.apache.org/spreadsheet/quick-guide.html http://www.aspose.com/docs/display/cellsjava/Eval ...

  2. excel vba 当cell的值变化时 进行判断操作

    示例效果: ----------- 在excel的sheet1中, 当A列的值 大于100时 ,其对应B列背景显示红色,C列显示"有数据" 否则,B列背景色正常,C列清空相应的数据 ...

  3. NetSuite SuiteScript 2.0 export data to Excel file(xls)

    In NetSuite SuiteScript, We usually do/implement export data to CSV, that's straight forward: Collec ...

  4. Excel: assign label to scatter chart using specific cell values

    ref: https://www.get-digital-help.com/custom-data-labels-in-x-y-scatter-chart/ Improve your X Y Scat ...

  5. Excel异常Cannot get a text value from a numeric cell

    POI操作Excel时数据Cell有不同的类型,当我们试图从一个数字类型的Cell读取出一个字符串并写入数据库时,就会出现Cannot get a text value from a numeric ...

  6. POI操作Excel异常Cannot get a text value from a numeric cell

    控制台抛出异常:java.lang.IllegalStateException: Cannot get a text value from a numeric cell 在java中用POI解析exc ...

  7. Aspose.Cell和NPOI生成Excel文件

    1.使用Aspose.Cell生成Excel文件,Aspose.Cell是.NET组件控件,不依赖COM组件 1首先一点需要使用新建好的空Excel文件做模板,否则容易产生一个多出的警告Sheet 1 ...

  8. 如何把excel 数据做dataprovide

    1.  新建一个类,实现接口Iterator import java.io.FileInputStream; import java.io.FileNotFoundException; import ...

  9. selenium webdriver读取excel进行数据驱动测试

    最近做自动化需要从文件读取数据做参数化,网上发现一个不错的解决方案. 准备:新建一个excel文件,文件名为测试类名,sheet名为测试方法名         excel第一行为标题,从第二行开始为测 ...

随机推荐

  1. DBUTIL 调用存储过程例子

    执行存储过程和执行select查询相比,无非就是SQL语句不同.下面是一个用存储过程查记录的例子.根据你的数据库不同和域对象不同,此代码要修改 Java code   ? 1 2 3 4 5 Quer ...

  2. jquery ajax的error错误信息

    项目开发中ajax的异常处理起来算是比较头疼的,因为是异步请求,所以即使ajax异常程序依然会继续执行,导致找ajax的异常比较麻烦. 今天处理ajax异常时搜到一篇文章,提到error可以返回aja ...

  3. jmeter for循环嵌套if学习2

    if语句中勾选Evaluate选项,每执行一句都会判断result的值是否为true. 执行结果: three没有执行,到debug时变量的值变成tom了

  4. pip常见操作收录

    由于这些东西比较容易忘掉,在这里几下吧 1. pip 对应用进行安装: sudo pip install  your_app 2. pip 对应用进行update sudo pip install   ...

  5. 一步一步将Vim打造成C++超级IDE

    文/嶽永鹏 最近从MS Windows 转到了Liunx,花了一段时间熟悉和学习Liunx环境.有时候,真的很是怀念MS Vistual Studio那种超级智能的开发环境,总是想在Vim拾起那些曾进 ...

  6. WinDbg 蓝屏dump分析教程

    一.WinDbg是什么?它能做什么? WinDbg是在windows平台下,强大的用户态和内核态调试工具.它能够通过dmp文件轻松的定位到问题根源,可用于分析蓝屏.程序崩溃(IE崩溃)原因,是我们日常 ...

  7. Scala练习(二)

    3.计算指定目录下以".txt"为扩展名的文件个数.注:随便建个目录,建几个.txt文件即可. 4.计算"input_4.txt"文件中搜索词的出现次数,并按次 ...

  8. MDI窗体容器、权限设置

    一.MDI窗体容器: 1.功能: 它可以让其它窗体在它的内部打开,无法超出它的范围 将某个窗体的属性:IsMdiContainer设置为true - 窗口样式 2.问题: (1)如何将其它窗体在它的内 ...

  9. Linux Shell 学习总结

    1. -bash: ./dd.sh: /bin/bash^M: bad interpreter: 没有那个文件或目录 当出现上面这问题的时候,首先看你的.profile 里面是否配置对了,一般配置为: ...

  10. Linux mount的使用

    大家在使用Linux系统的时候,肯定用过一些共享文件的东西,比如FTP,Mount 等等,接下来我重点说一下Mount的用法: 现在有一台测试环境上面需要部署Mount服务器(10.10.10.27) ...