zoukankan      html  css  js  c++  java
  • struts2导出excel

    //创建workbook
    HSSFWorkbook workbook = new HSSFWorkbook();
    //创建sheet页
    HSSFSheet sheet = workbook.createSheet("开票");
    //================================================================================================================================
    // //设置样式对象
    HSSFCellStyle cellStyle = workbook.createCellStyle();
    cellStyle.setFillForegroundColor(HSSFColor.TAN.index);// 设置背景色
    cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);//设置在上中下位置(此属性如果不设置,那么上中下左右等就不会起作用)
    cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直
    cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 居中
    cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
    cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
    cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
    cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框

    //表头标题样式
    HSSFFont font = workbook.createFont();
    font.setFontName("黑体");
    font.setFontHeightInPoints((short) 12);//设置字体大小
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);//粗体显示
    cellStyle.setFont(font);//====================将字体样式添加到样式对象里
    cellStyle.setLocked(true);

    //表头样式
    HSSFFont ft = workbook.createFont();
    ft.setFontName("宋体");
    ft.setFontHeightInPoints((short) 12);// 字体大小
    HSSFCellStyle style = workbook.createCellStyle();
    style.setFillForegroundColor(HSSFColor.LEMON_CHIFFON.index);// 设置背景色
    style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);//设置在上中下位置(此属性如果不设置,那么上中下左右等就不会起作用)
    style.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
    style.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
    style.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
    style.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
    style.setFont(ft);
    style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中
    style.setWrapText(true); // 换行
    style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中
    // style.setLocked(true);

    // 普通单元格样式(中文)
    HSSFFont font2 = workbook.createFont();
    font2.setFontName("宋体");
    font2.setFontHeightInPoints((short) 12);
    HSSFCellStyle style2 = workbook.createCellStyle();
    style2.setFillForegroundColor(HSSFColor.LIGHT_TURQUOISE.index);
    style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);//设置在上中下位置(此属性如果不设置,那么上中下左右等就不会起作用)
    style2.setBorderBottom(HSSFCellStyle.BORDER_THIN); //下边框
    style2.setBorderLeft(HSSFCellStyle.BORDER_THIN);//左边框
    style2.setBorderTop(HSSFCellStyle.BORDER_THIN);//上边框
    style2.setBorderRight(HSSFCellStyle.BORDER_THIN);//右边框
    style2.setFont(font2);
    style2.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 左右居中
    style2.setWrapText(true); // 换行
    style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 上下居中

    //==================================================================================================================================
    //创建单元格
    HSSFRow row = sheet.createRow(0); //创建第一行 ;依次往下新建行
    this.createCellTitle(row,0,"序号",cellStyle);
    this.createCellTitle(row,1,"开票单号",cellStyle);
      ....

    this.mergeCell(sheet,0, 0, 23,29);//??
    this.createCellTitle(row,23,"xxxxx",cellStyle);
    for (int k = 0; k < 23; k++)
    {
    this.mergeCell(sheet,0, 1, k, k);
    }

    row = sheet.createRow(rowIndex);
    this.createCellTitle(row,0,(i+1)+"",dataStyle);
    this.createCellTitle(row,1,info.getInvoiceNo(),dataStyle);

    ........

    /**
    * 合并单元格
    */
    public void mergeCell(HSSFSheet sheet,int firstRow,int lastRow,int firstCol,int lastCol)
    {
    CellRangeAddress address = new CellRangeAddress(firstRow, lastRow, firstCol, lastCol);
    sheet.addMergedRegion(address);
    }

  • 相关阅读:
    mac 切换 默认xcode 版本
    mac 查看jenkins 管理员密码地址
    解决 mac ox 终端显示bogon 的问题
    eclipse 修改默认作者信息
    mac 查看 本地网络代理
    appium 解决 启动case 时不 重装 setting 和 unlock.apk的解决方案实践
    appium 输入时间慢的解决方案
    命令 关闭 appium 命令
    解决 appium could not start ios-webkit-debug-proxy
    PPT总结
  • 原文地址:https://www.cnblogs.com/lingding/p/10985264.html
Copyright © 2011-2022 走看看