poi 根据模板导出excel

public static void main(String[] args) throws Exception{
        //获取系统文档
        InputStream inp=new FileInputStream(new File("D:\\workspace\\idea\\company\\new_gljy\\ssh_gljy\\201910rjkf0241\\SharkSucker\\pm\\src\\main\\resources\\static\\file\\进度汇总对比表.xlsx"));
        //创建工作薄对象
        XSSFWorkbook workbook=new XSSFWorkbook(inp);
        //创建工作表对象
       // XSSFSheet sheet = workbook.getSheet("Sheet1");
        XSSFSheet sheet = workbook.getSheetAt(0);
        //得到Excel表格  第6行
        XSSFRow row = sheet.getRow(5);
        if(null==row){
            row=sheet.createRow(5);
        }
        //得到Excel工作表指定行的单元格 第五列
        XSSFCell cell = row.getCell(0);
        if(null==cell){
            cell=row.createCell(0);
        }
        //单元格加背景色
        cell.setCellValue("4554");
        XSSFCellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);//填充
        cellStyle.setFillForegroundColor(new XSSFColor(new java.awt.Color(169, 169, 169)));
        cell.setCellStyle(cellStyle);
        XSSFCell cell1=null;
        for (int i = 0; i < 10; i++) {
            cell1 = row.getCell(i);
            if(null==cell1){
                cell1=row.createCell(i);
            }
            if(i==9){
                //单元格加边框    
                XSSFCellStyle cellStyleBord = workbook.createCellStyle();
                cellStyleBord.setBorderLeft(BorderStyle.THIN);
                cell1.setCellStyle(cellStyleBord);
            }
        }
        //合并单元格
        CellRangeAddress cellRangeAddress=new CellRangeAddress(rowIndex,rowIndex,0,9);
        sheet.addMergedRegion(cellRangeAddress);
        FileOutputStream out = new FileOutputStream("D:\\workspace\\idea\\company\\new_gljy\\" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()).toString() +".xls");
        workbook.write(out);
        out.close();
    }

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值