java利用poi简单解析excel

一般工作当中会有一些数据进行分析拼接之类,通过贴到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());
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值