POI隐藏行 隐藏列,EasyExcel隐藏行 EasyExcel隐藏列

因为EasyExcel基于POI的所以隐藏行用的是POI的方式,代码如下

 

@Test
    public void test1() throws Exception {
        String excelPath = "F:\\temp\\SiPrintViewNew111.xls";
        HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(excelPath));
        HSSFSheet sheet = workbook.getSheetAt(0);

        //Excel隐藏  80-120行
        for (Integer rowIndex = 80; rowIndex < 120; rowIndex++) {
            Row row = sheet.getRow(rowIndex);
            row.setZeroHeight(true);
        }

        //隐藏 第10列
        sheet.setColumnHidden(10,true);


        FileOutputStream out = null;
        try {
            out = new FileOutputStream(excelPath);
            workbook.write(out);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        System.out.println("OK");

    }

 

posted @ 2021-11-12 14:44  为乐而来  阅读(3404)  评论(0编辑  收藏  举报