//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. Jmeter学习(一)

    最近测了一个导出功能,感觉应该学习下Jmeter,WEB系统的性能系统还是需要有一定累积. 选择Jmeter而不是LR,很简单的原因是QTP和LR不能装一台机器上. 也有很多测试人员推荐Jmeter, ...

  2. Android获取网络图片

    /** * * 访问网络的操作,必须放在工作线程中完成 * */ public class MainActivity extends Activity { static List<HashMap ...

  3. 转-阿里云CentOS Linux服务器上用postfix搭建邮件服务器

    http://www.cnblogs.com/dudu/archive/2012/12/12/linux-postfix-mailserver.html 注:本文的邮件服务器只用于发送邮件,也就是ST ...

  4. AutoCAD .NET API 之——DimStyleTableRecord 的属性列表

    DimStyleTableRecord Properties: Properties Description(描述) Dimadec 角度标注保留的有效位数 Dimalt 控制是否显示换算单位标注值中 ...

  5. java模拟面试 试题

    java 四类八种基本数据类型 第一类:整型 byte short int long 第二类:浮点型 float double 第三类:逻辑型 Boolean(取值为 true false) 第四类: ...

  6. centos 6.5重置Root密码

    按任意键进入菜单界面 在开始引导的时候,进入开机启动界面(如下图) 然后按一下键盘上面的"e" 3.进入如下图界面,我这边选择第二个按下键盘上的"e"键.(不同 ...

  7. wmware 怎么 跟主机相互通信

    VMnet1和VMware8其实就是软件模拟出来的两块网卡提供DHCP服务,两块网卡对应VMware的两种不同的模式VMWare提供了三种工作模式,它们是bridged(桥接模式).NAT(网络地址转 ...

  8. ajax中使用post传值数组array

    如果我们在data中想放入array的参数,根据在网上搜索的结果有如下方法,但是没有一个成功的……我还是贴出来,别人成功了,也许是我哪里不对,日后也许还有机会研究..在文章的最后贴出了转化为json的 ...

  9. [转]Python os.path模块

    os.path模块 原文链接:http://my.oschina.net/cuffica/blog/33494 basename('文件路径')    去掉目录路径,返回fname文件名 import ...

  10. 为了防止采集,把文章中出现的URL链接随机大小写(PHP实现)

    <?php $string = "http://www.kxblogs.com/n/20161115/74439155.html"; $string = explode('/ ...