poi 版本 3.17

1. 创建标题

    public void createTitleRow(HSSFSheet sheet,String title,HSSFCellStyle titleStyle,int rowNum){

        HSSFRow  titleRow =  sheet.createRow(rowNum);

        HSSFCell  titleCell ;

        titleCell =  titleRow.createCell(0);

        titleCell .setCellStyle(titleStyle);

        titleCell .setCellValue(new HSSFRichTextString(title));

    }

2.创建副标题

    public void createSubtitleRow(HSSFSheet sheet,String[] headers,HSSFCellStyle titleStyle,int rowNum){

        HSSFRow  headerRow =  sheet.createRow(rowNum);

        HSSFCell  headerCell;

        for(int i = 0;i<headers.length;i++){

            headerCell =  headerRow .createCell(i);    

            headerCell .setCellStyle(titleStyle);

            headerCell .setCellValue(new HSSFRichTextString(headers[i]));

        }

    }

poi对excel文件的操作

    3.设置百分比%样式

    public  HSSFCellStyle createPercentStyle(HSSFwork work,HSSFCellStyle  style){     //style  excel默认样式

        HSSFCellStyle  percentStyle = work.createStyle();

        percentStyle.conleStyleFrom(style);     //复制默认样式

        percentStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));  //设置%样式

 

        //percentStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));    //设置整数样式

        //percentStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));    //设置小数样式

        //percentStyle.setAlignment(HorizontalAlignment.LEFT);    //设置左对齐

        return percentStyle;

    }

 

相关文章:

  • 2021-08-16
  • 2021-11-20
  • 2021-05-30
  • 2021-12-07
  • 2022-12-23
猜你喜欢
  • 2021-04-25
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2021-07-12
  • 2021-08-28
相关资源
相似解决方案