Пример #1
0
  public void exportToExcel(OutputStream fileOut) throws IOException {
    HSSFWorkbook wb;
    try {
      wb = new HSSFWorkbook();
      HSSFSheet sheet = wb.createSheet("table-colums");

      HSSFFont boldFont = wb.createFont();
      boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

      HSSFCellStyle boldStyle = wb.createCellStyle();
      boldStyle.setFont(boldFont);

      HSSFRow row = sheet.createRow(0);
      HSSFCell cell0 = row.createCell(0);
      cell0.setCellValue("字段名称");
      cell0.setCellStyle(boldStyle);
      HSSFCell cell1 = row.createCell(1);
      cell1.setCellValue("列名");
      cell1.setCellStyle(boldStyle);
      HSSFCell cell2 = row.createCell(2);
      cell2.setCellValue("字段别名");
      cell2.setCellStyle(boldStyle);
      HSSFCell cell3 = row.createCell(3);
      cell3.setCellValue("字段类型");
      cell3.setCellStyle(boldStyle);
      HSSFCell cell4 = row.createCell(4);
      cell4.setCellValue("默认值");
      cell4.setCellStyle(boldStyle);
      HSSFCell cell5 = row.createCell(5);
      cell5.setCellValue("最大长度");
      cell5.setCellStyle(boldStyle);
      HSSFCell cell6 = row.createCell(6);
      cell6.setCellValue("显示顺序");
      cell6.setCellStyle(boldStyle);

      String value = Struts2Utils.getParameter("subTableVals");
      String[] arr = value.split("=");
      String jsonString = arr[1];
      if (jsonString != null && StringUtils.isNotEmpty(jsonString.toString())) {
        getSheetContent(jsonString, sheet);
      }
      wb.write(fileOut);
    } catch (IOException exception) {
    }
  }