从数据库中读出的字段有数字和字符,字符默认为左对齐,数字默认为右对齐。如何将字符设为右对齐?谢谢!在线等!

解决方案 »

  1.   


    HSSFFont font = wb.createFont();
    // create a cell style object
    HSSFCellStyle cellStyleLeft = wb.createCellStyle();
    cellStyleLeft.setAlignment(HSSFCellStyle.ALIGN_LEFT);
    cellStyleLeft.setVerticalAlignment(MIDDLE);
    cellStyleLeft.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    cellStyleLeft.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    cellStyleLeft.setBorderTop(HSSFCellStyle.BORDER_THIN);
    cellStyleLeft.setBorderRight(HSSFCellStyle.BORDER_THIN);
    cellStyleLeft.setFillForegroundColor(WHITE);
    cellStyleLeft.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    cellStyleLeft.setFont(font);
    // create a cell style object
    HSSFCellStyle cellStyleRight = wb.createCellStyle();
    cellStyleRight.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    cellStyleRight.setVerticalAlignment(MIDDLE);
    cellStyleRight.setBorderBottom(HSSFCellStyle.BORDER_THIN);
    cellStyleRight.setBorderLeft(HSSFCellStyle.BORDER_THIN);
    cellStyleRight.setBorderTop(HSSFCellStyle.BORDER_THIN);
    cellStyleRight.setBorderRight(HSSFCellStyle.BORDER_THIN);
    cellStyleRight.setFillForegroundColor(WHITE);
    cellStyleRight.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    cellStyleRight.setFont(font);createCell( row, (short) j, cellStyleRight, plist.get(j));