一般工作当中会有一些数据进行分析拼接之类,通过贴到excel中然后利用poi解析。还是有些用途的。
jar包poi-3.15.jar
public class ExcelUtls {
public static Map<String, String> repeatMap = new HashMap<>();
public static void main(String[] args) throws IOException {
//获取数据
getRepeatDB();
}
static void getRepeatDB() {
File file = new File("E:/201810_work/ids.xls");//版本是excel2003才行
// 获取excel文档
POIFSFileSystem fs;
HSSFWorkbook wb;
HSSFSheet sheetMain;
try {
fs = new POIFSFileSystem(new FileInputStream(file));
wb = new HSSFWorkbook(fs);
// 读取第一个Sheet
sheetMain = wb.getSheetAt(0);
int totalRow = sheetMain.getLastRowNum() + 1;
int anlyzeExcelStart = 0;
CallRecordDTO callDto = null;
SeatDTO seatDto = null;
DecimalFormat df = new DecimalFormat("0");
Cell temp = null;
for (int i = anlyzeExcelStart; i < 378; i++) {//这里是遍历行数
HSSFRow row = sheetMain.getRow(i);
temp = row.getCell(0);//这里是获取列数
String tempStr = temp == null ? "" : temp.toString();
//String tempStr = df.format(temp.getNumericCellValue());//长度很大的数字字符串防止变成e通过这个方式获取值。
repeatMap.put(tempStr, tempStr);
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(repeatMap.size());
}
}