Read excel and put cell data into HashMap
//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的更多相关文章
- java 读取excel poi 和cell 方法
http://poi.apache.org/spreadsheet/quick-guide.html http://www.aspose.com/docs/display/cellsjava/Eval ...
- excel vba 当cell的值变化时 进行判断操作
示例效果: ----------- 在excel的sheet1中, 当A列的值 大于100时 ,其对应B列背景显示红色,C列显示"有数据" 否则,B列背景色正常,C列清空相应的数据 ...
- 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 ...
- 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 ...
- Excel异常Cannot get a text value from a numeric cell
POI操作Excel时数据Cell有不同的类型,当我们试图从一个数字类型的Cell读取出一个字符串并写入数据库时,就会出现Cannot get a text value from a numeric ...
- 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 ...
- Aspose.Cell和NPOI生成Excel文件
1.使用Aspose.Cell生成Excel文件,Aspose.Cell是.NET组件控件,不依赖COM组件 1首先一点需要使用新建好的空Excel文件做模板,否则容易产生一个多出的警告Sheet 1 ...
- 如何把excel 数据做dataprovide
1. 新建一个类,实现接口Iterator import java.io.FileInputStream; import java.io.FileNotFoundException; import ...
- selenium webdriver读取excel进行数据驱动测试
最近做自动化需要从文件读取数据做参数化,网上发现一个不错的解决方案. 准备:新建一个excel文件,文件名为测试类名,sheet名为测试方法名 excel第一行为标题,从第二行开始为测 ...
随机推荐
- 学习UFT11.5历程(一)
博主三年来测试都是功能测试 看了虫师的文章,感觉是要学点东西.所以,听从虫师的话,不被眼花瞭乱的测试技术打扰,先学习UFT,再学习python. 再不学习感觉要被淘汰了...... 也不想有谈工资的时 ...
- Rigidbody相关的操作最好放在FixedUpdate中,update中可能会无效果
void Turning() { // Create a ray from the mouse cursor on screen in the direction of the camera. Ray ...
- IP首部校验和的计算
ip抓包结果:0000: 00 e0 0f 7d 1e ba 00 13 8f 54 3b 70 08 00 45 00 0010: 00 2e be 55 00 00 7a 11 51 ac de ...
- markdown小记
一直听说用markdown写文档比较符合程序员的逼格,没事就倒腾了下,附上近期整理的精华,留自己以方便查阅. 1.常用指令 单个回车 视为空格. 连续回车 才能分段. 行尾加两个空格,这里-> ...
- NodeJS中的异步I/O、事件驱动
nodejs的主要特点是单线程.异步I/O.事件驱动.让我们先大概了解一下这些名词的意思. 单线程 单线程是任务按照顺序执行的,并且每次只执行一个任务,只有前面的任务执行完成以后,后面的任务才执行.在 ...
- 学习笔记找到多个具有相同 ID“_header”的控件,FindControl 要求控件具有唯一的 ID.
解决 找到多个具有相同 ID“_header”的控件,FindControl 要求控件具有唯一的 ID. private void DisplayHotBooks() { //获取 ...
- Jfreechart初案例--饼图
1.action @Controller(value = "pieAction") @Scope("prototype") public class PieAc ...
- Javascript学习笔记2.1 Javascript与DOM简介
DOM(文档对象模型)简介 DOM(文档对象模型)针对HTML和XML文档的一个API. DOM可以将任何HTML或XML文档描绘成由多层节点构成的树形结构,它是中立于平台和语言的接口,允许程序和脚本 ...
- AutoCAD安装失败
问题一: Installing .NET Framework Runtime 4.0: D:\安装包\CAD\cad2012(x64)\Map3D2012(x64)\3rdParty\NET\4\wc ...
- 关于博弈论中的一硬币正反问题的分析<二>
昨天分析了一下硬币正反的问题,其中说到一点是求美女收益期望E(女)=-8xy+3y+3x-1 最大化,当然结果我们是说的一个范围内的变化以及可以针对性的调整.这里再次说明一下,不是简单的求二元函数的最 ...