jxl process excel

public class ExcelExportUtil {
  public static WritableCellFormat NUMBER_FORMAT = new WritableCellFormat(
      NumberFormats.THOUSANDS_FLOAT);
  public static WritableCellFormat HMS_DATE_FORMAT = new WritableCellFormat(
      new DateFormat("MM/dd/yyyy hh:MM:ss"));
  public static WritableCellFormat HM_DATE_FORMAT = new WritableCellFormat(
      new DateFormat("MM/dd/yyyy hh:MM"));
  public static WritableCellFormat DEFAULT_DATE_FORMAT = new WritableCellFormat(
      new DateFormat("MM/dd/yyyy"));
  public static int MAX_SIZE = 500;
  private final static String DEFAULT_SHEET_NAME = "sheet1";
  public WritableWorkbook wbook = null;

  public WritableSheet buildHeader(String title, List<String> headerList,
      OutputStream os) throws Exception {
    wbook = Workbook.createWorkbook(os);
    CellView cellView = new CellView();
    cellView.setAutosize(true);
    WritableSheet sheet = wbook.createSheet(DEFAULT_SHEET_NAME, 0);

    WritableCellFormat cellFormat = new WritableCellFormat(new WritableFont(
        WritableFont.ARIAL, 10, WritableFont.BOLD, false,
        UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLUE));
    cellFormat.setAlignment(jxl.format.Alignment.LEFT.CENTRE);
    Label titleLabel = new Label(0, 0, title, cellFormat);
    sheet.addCell(titleLabel);
    for (int i = 0; null != headerList && i < headerList.size(); i++) {
      sheet.addCell(new Label(i, 1, headerList.get(i), cellFormat));
      if (!"O/S".equals(headerList.get(i))) {
        sheet.setColumnView(i, cellView);
      }
    }
    return sheet;
  }

  public void workbookWrite() throws Exception {
    wbook.write();
    wbook.close();
  }

}


你可能感兴趣的:(jxl process excel)