Example usage for org.apache.poi.ss.usermodel Workbook createCellStyle

List of usage examples for org.apache.poi.ss.usermodel Workbook createCellStyle

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Workbook createCellStyle.

Prototype

CellStyle createCellStyle();

Source Link

Document

Create a new Cell style and add it to the workbook's style table

Usage

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  w  w w  .  j av  a 2s. c  om

    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;
}

From source file:org.dashbuilder.dataset.service.DataSetExportServicesImpl.java

License:Apache License

private Map<String, CellStyle> createStyles(Workbook wb) {
    Map<String, CellStyle> styles = new HashMap<>();
    CellStyle style;/*from  ww w.  ja v a  2 s  .  co  m*/

    Font titleFont = wb.createFont();
    titleFont.setFontHeightInPoints((short) 12);
    titleFont.setBold(true);
    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    style.setFont(titleFont);
    style.setWrapText(false);
    style.setBorderBottom(BorderStyle.THIN);
    style.setBottomBorderColor(IndexedColors.GREY_80_PERCENT.getIndex());
    styles.put("header", style);

    Font cellFont = wb.createFont();
    cellFont.setFontHeightInPoints((short) 10);
    cellFont.setBold(true);

    style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.RIGHT);
    style.setVerticalAlignment(VerticalAlignment.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(HorizontalAlignment.RIGHT);
    style.setVerticalAlignment(VerticalAlignment.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(HorizontalAlignment.LEFT);
    style.setVerticalAlignment(VerticalAlignment.BOTTOM);
    style.setFont(cellFont);
    style.setWrapText(false);
    style.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text"));
    styles.put(TEXT_CELL, style);

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

From source file:org.dbunit.dataset.excel.XlsDataSetWriter.java

License:Open Source License

protected static CellStyle findCellStyle(Workbook workbook, Short formatCode, Map<Short, CellStyle> map) {
    CellStyle cellStyle = map.get(formatCode);
    if (cellStyle == null) {
        cellStyle = workbook.createCellStyle();
        cellStyle.setDataFormat(formatCode);
        map.put(formatCode, cellStyle);//from www  .j  a  v  a  2  s.  co  m
    }

    return cellStyle;
}

From source file:org.dhatim.fastexcel.Benchmarks.java

License:Apache License

private int poiPopulate(org.apache.poi.ss.usermodel.Workbook wb) throws Exception {
    Sheet ws = wb.createSheet("Sheet 1");
    CellStyle dateStyle = wb.createCellStyle();
    dateStyle.setDataFormat(wb.getCreationHelper().createDataFormat().getFormat("yyyy-mm-dd hh:mm:ss"));
    for (int r = 0; r < NB_ROWS; ++r) {
        Row row = ws.createRow(r);/*from w w  w  .j a  v  a2s  .c o  m*/
        row.createCell(0).setCellValue(r);
        row.createCell(1).setCellValue(Integer.toString(r % 1000));
        row.createCell(2).setCellValue(r / 87.0);
        Cell c = row.createCell(3);
        c.setCellStyle(dateStyle);
        c.setCellValue(new Date(1549915044));
    }
    CountingOutputStream count = new CountingOutputStream(new NullOutputStream());
    wb.write(count);
    return count.getCount();
}

From source file:org.eclipse.emfforms.internal.spreadsheet.core.converter.EMFFormsSpreadsheetMultiAttributeConverter_Test.java

License:Open Source License

@Before
public void before() {
    converter = new EMFFormsSpreadsheetMultiAttributeConverter();
    reportService = mock(ReportService.class);
    databinding = mock(EMFFormsDatabindingEMF.class);
    domainObject = mock(EObject.class);
    dmr = mock(VDomainModelReference.class);

    final Workbook wb = new HSSFWorkbook();
    final CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text")); //$NON-NLS-1$

    final Sheet sheet = wb.createSheet("test"); //$NON-NLS-1$

    // Create a row and put some cells in it. Rows are 0 based.
    final Row row = sheet.createRow((short) 0);
    cell = row.createCell(0);//from  www .j  a va  2  s.  com

    viewModelContext = mock(ViewModelContext.class);
    when(viewModelContext.getContextValue(EMFFormsCellStyleConstants.TEXT)).thenReturn(cellStyle);
}

From source file:org.eclipse.emfforms.internal.spreadsheet.core.converter.EMFFormsSpreadsheetMultiReferenceConverter_Test.java

License:Open Source License

@Before
public void before() {
    converter = new EMFFormsSpreadsheetMultiReferenceConverter();
    reportService = mock(ReportService.class);
    databinding = mock(EMFFormsDatabindingEMF.class);
    domainObject = mock(EObject.class);
    dmr = mock(VDomainModelReference.class);

    final Workbook wb = new HSSFWorkbook();
    final CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text")); //$NON-NLS-1$

    final Sheet sheet = wb.createSheet("test"); //$NON-NLS-1$

    // Create a row and put some cells in it. Rows are 0 based.
    final Row row = sheet.createRow((short) 0);
    cell = row.createCell(0);/*from  ww  w . jav a 2 s  . c  om*/

    viewModelContext = mock(ViewModelContext.class);
    when(viewModelContext.getContextValue(EMFFormsCellStyleConstants.TEXT)).thenReturn(cellStyle);
}

From source file:org.eclipse.emfforms.internal.spreadsheet.core.converter.EMFFormsSpreadsheetSingleAttributeConverter_Test.java

License:Open Source License

@Before
public void setup() {
    final Workbook wb = new HSSFWorkbook();
    cellStyle = wb.createCellStyle();
    cellStyle.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text")); //$NON-NLS-1$

    cellStyle2 = wb.createCellStyle();//from  w w w .j  a v a  2 s  .c  om
    cellStyle2.setDataFormat((short) BuiltinFormats.getBuiltinFormat("m/d/yy")); //$NON-NLS-1$

    final Sheet sheet = wb.createSheet("test"); //$NON-NLS-1$

    // Create a row and put some cells in it. Rows are 0 based.
    final Row row = sheet.createRow((short) 0);
    cell = row.createCell(0);

    viewModelContext = mock(ViewModelContext.class);
    when(viewModelContext.getContextValue(EMFFormsCellStyleConstants.TEXT)).thenReturn(cellStyle);
    when(viewModelContext.getContextValue(EMFFormsCellStyleConstants.DATE)).thenReturn(cellStyle2);

    converter = new EMFFormsSpreadsheetSingleAttributeConverter();
    reportService = mock(ReportService.class);
    databinding = mock(EMFFormsDatabindingEMF.class);
    domainObject = mock(EObject.class);
    dmr = mock(VDomainModelReference.class);
}

From source file:org.eclipse.emfforms.internal.spreadsheet.core.converter.EMFFormsSpreadsheetSingleReferenceConverter_Test.java

License:Open Source License

@Before
public void before() {
    converter = new EMFFormsSpreadsheetSingleReferenceConverter();
    reportService = mock(ReportService.class);
    databinding = mock(EMFFormsDatabindingEMF.class);
    domainObject = mock(EObject.class);
    dmr = mock(VDomainModelReference.class);

    final Workbook wb = new HSSFWorkbook();
    final CellStyle cellStyle = wb.createCellStyle();
    cellStyle.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text")); //$NON-NLS-1$

    final Sheet sheet = wb.createSheet("test"); //$NON-NLS-1$

    // Create a row and put some cells in it. Rows are 0 based.
    final Row row = sheet.createRow((short) 0);
    cell = row.createCell(0);/*w  w w.  ja  v a  2 s  .  c  om*/

    viewModelContext = mock(ViewModelContext.class);
    when(viewModelContext.getContextValue(EMFFormsCellStyleConstants.TEXT)).thenReturn(cellStyle);
}

From source file:org.eclipse.emfforms.internal.spreadsheet.core.transfer.EMFFormsSpreadsheetExporterImpl.java

License:Open Source License

private void addDefaultCellStyles(Workbook workbook, Map<String, CellStyle> keyStyleMap) {
    final CellStyle cellStyle = workbook.createCellStyle();
    cellStyle.setLocked(true);/*from  w w  w  . j  a va 2  s  . c o m*/
    keyStyleMap.put(EMFFormsCellStyleConstants.LOCKED, cellStyle);
    final CellStyle cellStyle2 = workbook.createCellStyle();
    cellStyle2.setLocked(true);
    cellStyle2.setWrapText(true);
    keyStyleMap.put(EMFFormsCellStyleConstants.LOCKED_AND_WRAPPED, cellStyle2);
    final CellStyle cellStyle3 = workbook.createCellStyle();
    cellStyle3.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text")); //$NON-NLS-1$
    keyStyleMap.put(EMFFormsCellStyleConstants.TEXT, cellStyle3);
    final CellStyle cellStyle4 = workbook.createCellStyle();
    cellStyle4.setDataFormat((short) BuiltinFormats.getBuiltinFormat("m/d/yy")); //$NON-NLS-1$
    keyStyleMap.put(EMFFormsCellStyleConstants.DATE, cellStyle4);
}

From source file:org.eclipse.emfforms.internal.spreadsheet.core.transfer.EMFFormsSpreadsheetExporterImpl.java

License:Open Source License

private void prepareNumberCellStyles(Workbook workbook, Set<String> retrievedFormats,
        Map<String, CellStyle> keyStyleMap) {
    final DataFormat dataFormat = workbook.createDataFormat();
    for (final String format : retrievedFormats) {
        final CellStyle cellStyleNumberFormat = workbook.createCellStyle();
        cellStyleNumberFormat.setDataFormat(dataFormat.getFormat(format));
        keyStyleMap.put(format, cellStyleNumberFormat);
    }//from ww  w  .  ja  v a 2  s. com
}