java poi 读取有合并单元格的EXCEL文件

数据的样子是这样的



public String addReportByExcel(Long userId,InputStream inputStream,String fileName)  
			throws BusinessException{
		String message = "Import success";
		
		boolean isE2007 = false;    //判断是否是excel2007格式  
        if(fileName.endsWith("xlsx")){
        	isE2007 = true;
        }
		
		int rowIndex = 0;
    	int columnIndex = 0;
        try {
            InputStream input = inputStream;  //建立输入流  
            Workbook wb  = null;  
            //根据文件格式(2003或者2007)来初始化  
            if(isE2007){ 
                wb = new XSSFWorkbook(input);
            }else{  
                wb = new HSSFWorkbook(input);
            }
            Sheet sheet = wb.getSheetAt(0);    //获得第一个表单  
            
            //System.out.println("总行数:"+sheet.getLastRowNum());
            
            List<CellRangeAddress> cras = getCombineCell(sheet);
            //isMergedRegion(Sheet sheet,int row ,int column);判断是不是合并单元格\
            int count = sheet.getLastRowNum()+1;//总行数
           
            List<InspectionReport> irs = new ArrayList<>();
            for(int i = 1; i < count;i++){
            	rowIndex = i;
            	Row row = sheet.getRow(i);
            	InspectionReport ir = new InspectionReport();
            	
            	ir.setReportName(getCellValue(row.getCell(0)));
            	ir.setShift(Double.valueOf(getCellValue(row.getCell(1))).intValue());
            	ir.setLine(getCellValue(row.getCell(2)));
            	ir.setStationCode(getCellValue(row.getCell(3)));
            	ir.setArea(Double.valueOf(getCellValue(row.getCell(4))).intValue());
   
评论 20
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值