Example usage for org.apache.poi.ss.util DateFormatConverter convert

List of usage examples for org.apache.poi.ss.util DateFormatConverter convert

Introduction

In this page you can find the example usage for org.apache.poi.ss.util DateFormatConverter convert.

Prototype

public static String convert(Locale locale, String format) 

Source Link

Usage

From source file:br.com.tecsinapse.dataio.ExporterFormatter.java

License:LGPL

public ExporterFormatter(Locale locale) {
    this.locale = locale;
    this.dateTimeFormat = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.MEDIUM)
            .withLocale(locale);/*from   w w  w.  ja  v a 2 s  .  c om*/
    this.dateFormat = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).withLocale(locale);
    this.timeFormat = DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM).withLocale(locale);
    this.dateTimeFormatPattern = getPatternFromDateTimeFormatter(dateTimeFormat);
    this.dateFormatPattern = getPatternFromDateTimeFormatter(dateFormat);
    this.timeFormatPattern = getPatternFromDateTimeFormatter(timeFormat);
    this.decimalFormat = (DecimalFormat) DecimalFormat.getInstance(locale);
    this.integerFormat = (DecimalFormat) DecimalFormat.getIntegerInstance(locale);
    this.currencyFormat = (DecimalFormat) DecimalFormat
            .getCurrencyInstance(locale == Locale.ENGLISH ? Locale.US : locale);
    this.cellDateTimeFormat = DateFormatConverter.convert(locale, dateTimeFormatPattern);
    this.cellDateFormat = DateFormatConverter.convert(locale, dateFormatPattern);
    this.cellTimeFormat = DateFormatConverter.convert(locale, timeFormatPattern);
    this.cellDecimalFormat = DateFormatConverter.convert(locale, decimalFormat.toPattern());
    this.cellIntegerFormat = DateFormatConverter.convert(locale, integerFormat.toPattern());
    this.cellCurrencyFormat = DateFormatConverter.convert(locale, getCurrencyFormatString());
}

From source file:br.com.tecsinapse.dataio.ExporterFormatter.java

License:LGPL

public ExporterFormatter(String dateTimeFormat, String dateFormat, String timeFormat, String decimalFormat,
        String integerFormat, String currencyFormat, Locale locale) {
    this.locale = locale;
    this.dateTimeFormat = DateTimeFormatter.ofPattern(dateTimeFormat).withLocale(locale);
    this.dateFormat = DateTimeFormatter.ofPattern(dateFormat).withLocale(locale);
    this.timeFormat = DateTimeFormatter.ofPattern(timeFormat).withLocale(locale);
    this.dateTimeFormatPattern = dateTimeFormat;
    this.dateFormatPattern = dateFormat;
    this.timeFormatPattern = timeFormat;
    this.decimalFormat = new DecimalFormat(decimalFormat, DecimalFormatSymbols.getInstance(locale));
    this.integerFormat = new DecimalFormat(integerFormat, DecimalFormatSymbols.getInstance(locale));
    this.currencyFormat = new DecimalFormat(currencyFormat, DecimalFormatSymbols.getInstance(locale));
    this.cellDateTimeFormat = DateFormatConverter.convert(locale, dateTimeFormat);
    this.cellDateFormat = DateFormatConverter.convert(locale, dateFormat);
    this.cellTimeFormat = DateFormatConverter.convert(locale, timeFormat);
    this.cellCurrencyFormat = DateFormatConverter.convert(locale, currencyFormat);
    this.cellDecimalFormat = DateFormatConverter.convert(locale, decimalFormat);
    this.cellIntegerFormat = DateFormatConverter.convert(locale, integerFormat);
}

From source file:br.com.tecsinapse.dataio.ExporterFormatter.java

License:LGPL

public ExporterFormatter(String dateTimeFormat, String dateFormat, String timeFormat, Locale locale) {
    this.locale = locale;
    this.dateTimeFormat = DateTimeFormatter.ofPattern(dateTimeFormat).withLocale(locale);
    this.dateFormat = DateTimeFormatter.ofPattern(dateFormat).withLocale(locale);
    this.timeFormat = DateTimeFormatter.ofPattern(timeFormat).withLocale(locale);
    this.dateTimeFormatPattern = dateTimeFormat;
    this.dateFormatPattern = dateFormat;
    this.timeFormatPattern = timeFormat;
    this.decimalFormat = (DecimalFormat) DecimalFormat.getInstance(locale);
    this.integerFormat = (DecimalFormat) DecimalFormat.getIntegerInstance(locale);
    this.currencyFormat = (DecimalFormat) DecimalFormat
            .getCurrencyInstance(locale == Locale.ENGLISH ? Locale.US : locale);
    this.cellDateTimeFormat = DateFormatConverter.convert(locale, dateTimeFormatPattern);
    this.cellDateFormat = DateFormatConverter.convert(locale, dateFormatPattern);
    this.cellTimeFormat = DateFormatConverter.convert(locale, timeFormatPattern);
    this.cellDecimalFormat = DateFormatConverter.convert(locale, decimalFormat.toPattern());
    this.cellIntegerFormat = DateFormatConverter.convert(locale, integerFormat.toPattern());
    this.cellCurrencyFormat = DateFormatConverter.convert(locale, getCurrencyFormatString());
}

From source file:br.com.tecsinapse.exporter.ExporterFormatter.java

License:LGPL

public ExporterFormatter(Locale locale) {
    this.locale = locale;
    this.dateTimeFormat = (SimpleDateFormat) SimpleDateFormat.getDateTimeInstance(DateFormat.MEDIUM,
            DateFormat.MEDIUM, locale);
    this.dateFormat = (SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.MEDIUM, locale);
    this.timeFormat = (SimpleDateFormat) SimpleDateFormat.getTimeInstance(DateFormat.SHORT, locale);
    this.decimalFormat = (DecimalFormat) DecimalFormat.getInstance(locale);
    this.integerFormat = (DecimalFormat) DecimalFormat.getIntegerInstance(locale);
    this.currencyFormat = (DecimalFormat) DecimalFormat.getCurrencyInstance(locale);
    this.cellDateTimeFormat = DateFormatConverter.convert(locale, dateTimeFormat.toPattern());
    this.cellDateFormat = DateFormatConverter.convert(locale, dateFormat.toPattern());
    this.cellTimeFormat = DateFormatConverter.convert(locale, timeFormat.toPattern());
    this.cellCurrencyFormat = DateFormatConverter.getPrefixForLocale(locale)
            + currencyFormat.toLocalizedPattern() + CELL_SUFIX_FORMAT;
    this.cellDecimalFormat = DateFormatConverter.getPrefixForLocale(locale) + decimalFormat.toLocalizedPattern()
            + CELL_SUFIX_FORMAT;//from  www.ja v a2  s.  co m
    this.cellIntegerFormat = DateFormatConverter.getPrefixForLocale(locale) + integerFormat.toLocalizedPattern()
            + CELL_SUFIX_FORMAT;
}

From source file:br.com.tecsinapse.exporter.ExporterFormatter.java

License:LGPL

public ExporterFormatter(String dateTimeFormat, String dateFormat, String timeFormat, String decimalFormat,
        String integerFormat, String currencyFormat, Locale locale) {
    this.locale = locale;
    this.dateTimeFormat = new SimpleDateFormat(dateTimeFormat, locale);
    this.dateFormat = new SimpleDateFormat(dateFormat, locale);
    this.timeFormat = new SimpleDateFormat(timeFormat, locale);
    this.decimalFormat = new DecimalFormat(decimalFormat, DecimalFormatSymbols.getInstance(locale));
    this.integerFormat = new DecimalFormat(integerFormat, DecimalFormatSymbols.getInstance(locale));
    this.currencyFormat = new DecimalFormat(currencyFormat, DecimalFormatSymbols.getInstance(locale));
    this.cellDateTimeFormat = DateFormatConverter.convert(locale, dateTimeFormat);
    this.cellDateFormat = DateFormatConverter.convert(locale, dateFormat);
    this.cellTimeFormat = DateFormatConverter.convert(locale, timeFormat);
    this.cellCurrencyFormat = DateFormatConverter.getPrefixForLocale(locale)
            + this.currencyFormat.toLocalizedPattern() + CELL_SUFIX_FORMAT;
    this.cellDecimalFormat = DateFormatConverter.getPrefixForLocale(locale)
            + this.decimalFormat.toLocalizedPattern() + CELL_SUFIX_FORMAT;
    this.cellIntegerFormat = DateFormatConverter.getPrefixForLocale(locale)
            + this.integerFormat.toLocalizedPattern() + CELL_SUFIX_FORMAT;
}

From source file:com.github.gaborfeher.grantmaster.framework.base.ExcelExporter.java

License:Open Source License

private void setExcelCell(HSSFWorkbook workbook, Object cellValue, Cell excelCell) {
    if (cellValue instanceof BigDecimal) {
        double doubleValue = ((BigDecimal) cellValue).doubleValue();
        excelCell.setCellValue(doubleValue);
        HSSFCellStyle cellStyle = workbook.createCellStyle();
        HSSFDataFormat hssfDataFormat = workbook.createDataFormat();
        cellStyle.setDataFormat(hssfDataFormat.getFormat("#,##0.00"));
        excelCell.setCellStyle(cellStyle);
        excelCell.setCellType(Cell.CELL_TYPE_NUMERIC);
    } else if (cellValue instanceof LocalDate) {
        LocalDate localDate = (LocalDate) cellValue;
        Calendar calendar = Calendar.getInstance();
        calendar.set(localDate.getYear(), localDate.getMonthValue() - 1, localDate.getDayOfMonth());
        excelCell.setCellValue(calendar);

        String excelFormatPattern = DateFormatConverter.convert(Locale.US, "yyyy-MM-DD");
        CellStyle cellStyle = workbook.createCellStyle();
        DataFormat poiFormat = workbook.createDataFormat();
        cellStyle.setDataFormat(poiFormat.getFormat(excelFormatPattern));
        excelCell.setCellStyle(cellStyle);
    } else if (cellValue != null) {
        excelCell.setCellValue(cellValue.toString());
    }/*from www  .ja va 2s  .  co  m*/
}

From source file:de.unioninvestment.eai.portal.portlet.crud.export.AbstractTableExportTask.java

License:Apache License

protected void applyExcelFormatForColumns(ExcelExport excelExport) {

    excelExport.setDoubleDataFormat("General");
    excelExport.setDateDataFormat(DateFormatConverter.convert(Context.getLocale(), "dd.MM.yyyy"));

    if (tableModel.getColumns() != null) {
        for (TableColumn column : tableModel.getColumns()) {
            String columnName = column.getName();
            String excelFormat = column.getExcelFormat();
            if (excelFormat == null) {
                Class<?> columnType = vaadinTable.getType(columnName);
                if (columnType != null) {
                    if (Date.class.isAssignableFrom(columnType)) {
                        String dateDisplayFormat = column.getDisplayFormat();
                        if (dateDisplayFormat != null) {
                            excelFormat = DateFormatConverter.convert(Context.getLocale(), dateDisplayFormat);
                        }/*from   w  w  w .j a  v  a2  s. c o  m*/
                    }
                }
            }
            if (excelFormat != null) {
                excelExport.setExcelFormatOfProperty(columnName, excelFormat);
            }
        }
    }
}

From source file:de.unioninvestment.eai.portal.portlet.crud.export.streaming.ExcelExporter.java

License:Apache License

private short getDataFormat(int col) {
    String excelFormat = excelFormats[col];
    if (excelFormat != null) {
        return dataFormat.getFormat(excelFormat);
    }/* w  w w  . jav  a 2  s . c om*/
    Class<?> columnType = columnTypes[col];
    if (columnType != null) {
        if (Date.class.isAssignableFrom(columnType)) {
            String dateDisplayFormat = displayFormats[col];
            if (dateDisplayFormat != null) {
                excelFormat = DateFormatConverter.convert(Context.getLocale(), dateDisplayFormat);
                return dataFormat.getFormat(excelFormat);
            }
            return dateDataFormat;
        }
    }
    return doubleDataFormat;
}

From source file:de.unioninvestment.eai.portal.portlet.crud.export.streaming.ExcelExporter.java

License:Apache License

private short defaultDateDataFormat() {
    return createHelper.createDataFormat()
            .getFormat(DateFormatConverter.convert(Context.getLocale(), "dd.MM.yyyy"));
}

From source file:org.dashbuilder.dataset.backend.DataSetBackendServicesImpl.java

License:Apache License

private Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    CellStyle style;/*from ww  w.jav  a2 s. c  o  m*/

    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 12);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFont(titleFont);
    style.setWrapText(false);
    style.setBorderBottom(CellStyle.BORDER_THIN);
    style.setBottomBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
    styles.put("header", style);

    Font cellFont = wb.createFont();
    cellFont.setFontHeightInPoints((short) 10);
    cellFont.setBoldweight(Font.BOLDWEIGHT_NORMAL);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(3)));
    styles.put("integer_number_cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat(wb.createDataFormat().getFormat(BuiltinFormats.getBuiltinFormat(4)));
    styles.put("decimal_number_cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text"));
    styles.put("text_cell", style);

    style = wb.createCellStyle();
    style.setAlignment(CellStyle.ALIGN_CENTER);
    style.setVerticalAlignment(CellStyle.VERTICAL_BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat(wb.createDataFormat()
            .getFormat(DateFormatConverter.convert(Locale.getDefault(), dateFormatPattern)));
    styles.put("date_cell", style);
    return styles;
}