//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. Openfire Strophe IE跨域问题

    Openfire和Strophejs网站 域名不同如何进行通信,这个问题总算解决,下面是解决步骤. 解决方案一: Chrome浏览器默认支持跨域访问 IE浏览器需要做配置:点击IE浏览器的的“工具-& ...

  2. Observer,Observable实现观察者模式

    (#)个人对于观察者的理解:观察者与发布订阅模式是非常的相似的,例如当多个威信使用者订阅了同一个主题之后,那么这个主题就是一个被观察者,而这些用户就是观察 者,当这个主题更新了新的内容以后,就要通知所 ...

  3. TestNG BeforeClass BeforeMethod Test AfterClass AfterMethod

    http://topmanopensource.iteye.com/blog/1983729 1.TestNG测试注解和Junit注解的不同以及生命周期: TestNG测试的一个方法的生命周期: @B ...

  4. plist基本操作

    重要概念:某些路径下“只能读,不能写”的原因 iPhone.ipad真机上 Resouces文件夹:是只读的,无法写入. document 和temp文件夹:可读,可写. 一.工程结构

  5. JS刷新父窗口的几种方式<转>

    常用的有:   window.opener.location.reload();    和  window.location.reload(); 浮层内嵌iframe及frame集合窗口,刷新父页面的 ...

  6. AX2012单元格显示颜色 displayOption

    public void displayOption(HV_WMSLocationStatusHistory _record, FormRowDisplayOption _options){    #d ...

  7. SPSS数据分析—二分类Logistic回归模型

    对于分类变量,我们知道通常使用卡方检验,但卡方检验仅能分析因素的作用,无法继续分析其作用大小和方向,并且当因素水平过多时,单元格被划分的越来越细,频数有可能为0,导致结果不准确,最重要的是卡方检验不能 ...

  8. Sprint3总结和成员个人总结

    Sprint3总结 一.类名:软件工程-第三阶段 二.时间:至12.18 三.选题内容:web版-餐厅到店点餐系统 四.(1)团队博客地址: http://www.cnblogs.com/queenj ...

  9. 十天精通CSS3学习笔记 part3

    第8章 CSS3中的变形与动画(上) 变形--旋转 rotate() 旋转rotate()函数通过指定的角度参数使元素相对原点进行旋转.它主要在二维空间内进行操作,设置一个角度值,用来指定旋转的幅度. ...

  10. php案列4

    一个最简单的利用php生成随机数或者随机字符串的函数.$chars变量中的字符自己修改就能达到数字或者字符串的目的     $len表示长度,代码如下: 复制代码 代码如下: /** * 产生随机字符 ...