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第一行为标题,从第二行开始为测 ...
随机推荐
- LMAX Disruptor—多生产者多消费者中,消息复制分发的高性能实现
解决的问题 当我们有多个消息的生产者线程,一个消费者线程时,他们之间如何进行高并发.线程安全的协调? 很简单,用一个队列. 当我们有多个消息的生产者线程,多个消费者线程,并且每一条消息需要被所有的消费 ...
- Sublime Text 3插件安装
自动安装: 1.通过快捷键 ctrl+` 或者 View > Show Console 菜单打开控制台 2.粘贴对应版本的代码后回车安装 适用于 Sublime Text 3: import ...
- 小谈一下JavaScript中的JSON
一.JSON的语法可以表示以下三种类型的值: 1.简单值:字符串,数值,布尔值,null 比如:5,"你好",false,null JSON中字符串必须用双引号,而JS中则没有强制 ...
- myeclipse连接oracle步骤
1.加载ojdbc.jar驱动(路径:E:\myoracle\oracle\product\11.2.0\dbhome_1\jdbc\lib) 2.String url = "jdbc:or ...
- font-weight -- 定义字体的粗细
font-weight -- 定义字体的粗细 取值: normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 70 ...
- C++ 11学习和掌握 ——《深入理解C++ 11:C++11新特性解析和应用》读书笔记(一)
因为偶然的机会,在图书馆看到<深入理解C++ 11:C++11新特性解析和应用>这本书,大致扫下,受益匪浅,就果断借出来,对于其中的部分内容进行详读并亲自编程测试相关代码,也就有了整理写出 ...
- windows字符串
CString在win32环境下最大的有效长度应该是INT_MAX-1 一般小于这个长度的文件,处理字符串都没问题. TCHAR字符串数组没有处理子串的相关函数,strchr(_tcschr)只是处理 ...
- 【C++】 struct结构自动对齐的问题
#pragma pack (push) #pragma pack (1) struct XXXX{}; #pragma pack (pop) 这样写就不会自动对齐了. 在写MFC下的winpcap捕a ...
- 不使用插件实现对WordPress默认编辑器的增强
四处寻觅无果.无意看了一下wordpress官方的API函数.苍天有眼啊!原来,后台的编辑器可以插入很多增强功能.果断卸载掉CK and SyntaxHighlighter编辑器插件.事实上,Word ...
- 不在折腾---hive-0.13.1-bin
Hive只在一个节点安装即可 上传tar包 解压 > tar zxvf hive-0.13.1-bin.tar.gz 配置mysql * 检查MySQL是否安装:rpm -qa | grep m ...