Search in sources :

Example 1 with XSSFDataFormat

use of org.apache.poi.xssf.usermodel.XSSFDataFormat in project cubrid-manager by CUBRID.

the class XlsxWriterHelper method getStyles.

/**
	 * create the cell style which is used for the head or date type cell
	 *
	 * @param workbook the instance of XSSFWorkbook
	 * @return Map<String, XSSFCellStyle>
	 */
public Map<String, XSSFCellStyle> getStyles(XSSFWorkbook workbook) {
    Map<String, XSSFCellStyle> styles = new HashMap<String, XSSFCellStyle>();
    XSSFDataFormat fmt = workbook.createDataFormat();
    XSSFCellStyle datetimeStyle = workbook.createCellStyle();
    datetimeStyle.setAlignment((short) 3);
    datetimeStyle.setDataFormat(fmt.getFormat("yyyy-mmm-dd h:mm:ss.ss"));
    styles.put("datetime", datetimeStyle);
    XSSFCellStyle timestampStyle = workbook.createCellStyle();
    timestampStyle.setAlignment((short) 3);
    timestampStyle.setDataFormat(fmt.getFormat("yyyy-mmm-dd h:mm:ss"));
    styles.put("timestamp", timestampStyle);
    XSSFCellStyle dateStyle = workbook.createCellStyle();
    dateStyle.setAlignment((short) 3);
    dateStyle.setDataFormat(fmt.getFormat("yyyy-mmm-dd"));
    styles.put("date", dateStyle);
    XSSFCellStyle timeStyle = workbook.createCellStyle();
    timeStyle.setAlignment((short) 3);
    timeStyle.setDataFormat(fmt.getFormat("h:mm:ss"));
    styles.put("time", timeStyle);
    XSSFCellStyle headerStyle = workbook.createCellStyle();
    XSSFFont headerFont = workbook.createFont();
    headerFont.setBold(true);
    headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    headerStyle.setFillPattern((short) 1);
    headerStyle.setFont(headerFont);
    styles.put("header", headerStyle);
    return styles;
}
Also used : XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) HashMap(java.util.HashMap) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) XSSFDataFormat(org.apache.poi.xssf.usermodel.XSSFDataFormat)

Example 2 with XSSFDataFormat

use of org.apache.poi.xssf.usermodel.XSSFDataFormat in project poi by apache.

the class BigGridDemo method createStyles.

/**
     * Create a library of cell styles.
     */
private static Map<String, XSSFCellStyle> createStyles(XSSFWorkbook wb) {
    Map<String, XSSFCellStyle> styles = new HashMap<String, XSSFCellStyle>();
    XSSFDataFormat fmt = wb.createDataFormat();
    XSSFCellStyle style1 = wb.createCellStyle();
    style1.setAlignment(HorizontalAlignment.RIGHT);
    style1.setDataFormat(fmt.getFormat("0.0%"));
    styles.put("percent", style1);
    XSSFCellStyle style2 = wb.createCellStyle();
    style2.setAlignment(HorizontalAlignment.CENTER);
    style2.setDataFormat(fmt.getFormat("0.0X"));
    styles.put("coeff", style2);
    XSSFCellStyle style3 = wb.createCellStyle();
    style3.setAlignment(HorizontalAlignment.RIGHT);
    style3.setDataFormat(fmt.getFormat("$#,##0.00"));
    styles.put("currency", style3);
    XSSFCellStyle style4 = wb.createCellStyle();
    style4.setAlignment(HorizontalAlignment.RIGHT);
    style4.setDataFormat(fmt.getFormat("mmm dd"));
    styles.put("date", style4);
    XSSFCellStyle style5 = wb.createCellStyle();
    XSSFFont headerFont = wb.createFont();
    headerFont.setBold(true);
    style5.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style5.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style5.setFont(headerFont);
    styles.put("header", style5);
    return styles;
}
Also used : XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) HashMap(java.util.HashMap) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) XSSFDataFormat(org.apache.poi.xssf.usermodel.XSSFDataFormat)

Aggregations

HashMap (java.util.HashMap)2 XSSFCellStyle (org.apache.poi.xssf.usermodel.XSSFCellStyle)2 XSSFDataFormat (org.apache.poi.xssf.usermodel.XSSFDataFormat)2 XSSFFont (org.apache.poi.xssf.usermodel.XSSFFont)2