Java Code Examples for org.apache.poi.ss.usermodel.CellStyle#cloneStyleFrom()

The following examples show how to use org.apache.poi.ss.usermodel.CellStyle#cloneStyleFrom() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QbeXLSExporter.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
private CellStyle getDecimalNumberFormat(int j, Sheet sheet, CreationHelper createHelper, CellStyle dCellStyle) {

		if (decimalFormats.get(j) != null)
			return decimalFormats.get(j);
		String decimals = "";
		for (int i = 0; i < j; i++) {
			decimals += "0";
		}

		CellStyle cellStyleDoub = this.buildCellStyle(sheet); // cellStyleDoub is the default cell style for doubles
		cellStyleDoub.cloneStyleFrom(dCellStyle);
		DataFormat df = createHelper.createDataFormat();
		String format = "#,##0";
		if (decimals.length() > 0) {
			format += "." + decimals;
		}
		cellStyleDoub.setDataFormat(df.getFormat(format));

		decimalFormats.put(j, cellStyleDoub);
		return cellStyleDoub;
	}
 
Example 2
Source File: ExcelUtils.java    From onetwo with Apache License 2.0 6 votes vote down vote up
public static void copyCellStyle(Cell source, Cell target){
	CellStyle style = source.getCellStyle();
	if(style!=null){
		//TODO:会影响性能, 可缓存。。。
		CellStyle newCellStyle = source.getRow().getSheet().getWorkbook().createCellStyle();
		newCellStyle.cloneStyleFrom(style);
		target.setCellStyle(style);
	}
	if(source.getCellComment()!=null){
		target.setCellComment(source.getCellComment());
	}
	if(source.getHyperlink()!=null){
		target.setHyperlink(source.getHyperlink());
	}
	target.setCellType(source.getCellType());
}
 
Example 3
Source File: AnnoFormulaTest.java    From xlsmapper with Apache License 2.0 6 votes vote down vote up
@XlsPostSave
public void handlePostSave(final Sheet sheet) {

    if(!name.equals("平均")) {
        return;
    }

    final Workbook book = sheet.getWorkbook();

    for(Point address : positions.values()) {
        Cell cell = POIUtils.getCell(sheet, address);

        CellStyle style = book.createCellStyle();
        style.cloneStyleFrom(cell.getCellStyle());

        // 塗りつぶし
        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);

        // 罫線の上部を変更
        style.setBorderTop(BorderStyle.DOUBLE);

        cell.setCellStyle(style);
    }

}
 
Example 4
Source File: ExcelUtil.java    From supplierShop with MIT License 5 votes vote down vote up
/**
 * 创建表格样式
 * 
 * @param wb 工作薄对象
 * @return 样式列表
 */
private Map<String, CellStyle> createStyles(Workbook wb)
{
    // 写入各条记录,每条记录对应excel表中的一行
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    CellStyle style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.CENTER);
    style.setBorderRight(BorderStyle.THIN);
    style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderLeft(BorderStyle.THIN);
    style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderTop(BorderStyle.THIN);
    style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderBottom(BorderStyle.THIN);
    style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    Font dataFont = wb.createFont();
    dataFont.setFontName("Arial");
    dataFont.setFontHeightInPoints((short) 10);
    style.setFont(dataFont);
    styles.put("data", style);

    style = wb.createCellStyle();
    style.cloneStyleFrom(styles.get("data"));
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    Font headerFont = wb.createFont();
    headerFont.setFontName("Arial");
    headerFont.setFontHeightInPoints((short) 10);
    headerFont.setBold(true);
    headerFont.setColor(IndexedColors.WHITE.getIndex());
    style.setFont(headerFont);
    styles.put("header", style);

    return styles;
}
 
Example 5
Source File: ExcelUtil.java    From RuoYi-Vue with MIT License 5 votes vote down vote up
/**
 * 创建表格样式
 * 
 * @param wb 工作薄对象
 * @return 样式列表
 */
private Map<String, CellStyle> createStyles(Workbook wb)
{
    // 写入各条记录,每条记录对应excel表中的一行
    Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
    CellStyle style = wb.createCellStyle();
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.CENTER);
    style.setBorderRight(BorderStyle.THIN);
    style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderLeft(BorderStyle.THIN);
    style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderTop(BorderStyle.THIN);
    style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setBorderBottom(BorderStyle.THIN);
    style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
    Font dataFont = wb.createFont();
    dataFont.setFontName("Arial");
    dataFont.setFontHeightInPoints((short) 10);
    style.setFont(dataFont);
    styles.put("data", style);

    style = wb.createCellStyle();
    style.cloneStyleFrom(styles.get("data"));
    style.setAlignment(HorizontalAlignment.CENTER);
    style.setVerticalAlignment(VerticalAlignment.CENTER);
    style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    Font headerFont = wb.createFont();
    headerFont.setFontName("Arial");
    headerFont.setFontHeightInPoints((short) 10);
    headerFont.setBold(true);
    headerFont.setColor(IndexedColors.WHITE.getIndex());
    style.setFont(headerFont);
    styles.put("header", style);

    return styles;
}
 
Example 6
Source File: ExcelWriterTransform.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * Set specified cell format
 *
 * @param excelFieldFormat the specified format
 * @param cell             the cell to set up format
 */
private void setDataFormat( String excelFieldFormat, Cell cell ) {
  if ( log.isDebug() ) {
    logDebug( BaseMessages.getString( PKG, "ExcelWriterTransform.Log.SetDataFormat", excelFieldFormat, CellReference.convertNumToColString( cell.getColumnIndex() ), cell.getRowIndex() ) );
  }

  DataFormat format = data.wb.createDataFormat();
  short formatIndex = format.getFormat( excelFieldFormat );
  CellStyle style = data.wb.createCellStyle();
  style.cloneStyleFrom( cell.getCellStyle() );
  style.setDataFormat( formatIndex );
  cell.setCellStyle( style );
}
 
Example 7
Source File: ExcelMatrixWriter.java    From sailfish-core with Apache License 2.0 5 votes vote down vote up
@Override
public void writeCells(SimpleCell[] cells) {

    column = 0;

    sheet.createRow(row);

    for (SimpleCell sc : cells) {
        
        sheet.getRow(row).createCell(column);

        Cell cell = sheet.getRow(row).getCell(column);

        cell.setCellValue(sc != null ? sc.getValue(): null);

        if (sc != null && sc.getCellStyle() != null) {
            CellStyle style = null;
            
            if (stylesCashe.containsKey(sc.getCellStyle())) {
                style = stylesCashe.get(sc.getCellStyle());
            } else {
                style = workbook.createCellStyle();
                style.cloneStyleFrom(sc.getCellStyle());
                stylesCashe.put(sc.getCellStyle(), style);
            }
            
         cell.setCellStyle(style);
        }
        column++;
    }
    row++;
}
 
Example 8
Source File: CellStyleProxy.java    From xlsmapper with Apache License 2.0 5 votes vote down vote up
private void cloneStyle() {
    if(updated) {
        // 既に更新済みの場合
        return;
    }

    CellStyle style = cell.getSheet().getWorkbook().createCellStyle();
    style.cloneStyleFrom(cell.getCellStyle());
    cell.setCellStyle(style);

    // 更新フラグをtrueにする
    this.updated = true;
}
 
Example 9
Source File: ExcelWriterStep.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Set specified cell format
 *
 * @param excelFieldFormat the specified format
 * @param cell             the cell to set up format
 */
private void setDataFormat( String excelFieldFormat, Cell cell ) {
  if ( log.isDebug() ) {
    logDebug( BaseMessages.getString( PKG, "ExcelWriterStep.Log.SetDataFormat", excelFieldFormat, CellReference.convertNumToColString( cell.getColumnIndex() ), cell.getRowIndex() ) );
  }

  DataFormat format = data.wb.createDataFormat();
  short formatIndex = format.getFormat( excelFieldFormat );
  CellStyle style = data.wb.createCellStyle();
  style.cloneStyleFrom( cell.getCellStyle() );
  style.setDataFormat( formatIndex );
  cell.setCellStyle( style );
}
 
Example 10
Source File: ExcelExport.java    From frpMgr with MIT License 4 votes vote down vote up
/**
	 * 创建表格样式
	 * @param wb 工作薄对象
	 * @return 样式列表
	 */
	private Map<String, CellStyle> createStyles(Workbook wb) {
		Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
		
		CellStyle style = wb.createCellStyle();
		style.setAlignment(CellStyle.ALIGN_CENTER);
		style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
		Font titleFont = wb.createFont();
		titleFont.setFontName("Arial");
		titleFont.setFontHeightInPoints((short) 16);
		titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
		style.setFont(titleFont);
		styles.put("title", style);

		style = wb.createCellStyle();
		style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
		style.setBorderRight(CellStyle.BORDER_THIN);
		style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
		style.setBorderLeft(CellStyle.BORDER_THIN);
		style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
		style.setBorderTop(CellStyle.BORDER_THIN);
		style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
		style.setBorderBottom(CellStyle.BORDER_THIN);
		style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
		Font dataFont = wb.createFont();
		dataFont.setFontName("Arial");
		dataFont.setFontHeightInPoints((short) 10);
		style.setFont(dataFont);
		styles.put("data", style);
		
		style = wb.createCellStyle();
		style.cloneStyleFrom(styles.get("data"));
		style.setAlignment(CellStyle.ALIGN_LEFT);
		styles.put("data1", style);

		style = wb.createCellStyle();
		style.cloneStyleFrom(styles.get("data"));
		style.setAlignment(CellStyle.ALIGN_CENTER);
		styles.put("data2", style);

		style = wb.createCellStyle();
		style.cloneStyleFrom(styles.get("data"));
		style.setAlignment(CellStyle.ALIGN_RIGHT);
		styles.put("data3", style);
		
		style = wb.createCellStyle();
		style.cloneStyleFrom(styles.get("data"));
//		style.setWrapText(true);
		style.setAlignment(CellStyle.ALIGN_CENTER);
		style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
		style.setFillPattern(CellStyle.SOLID_FOREGROUND);
		Font headerFont = wb.createFont();
		headerFont.setFontName("Arial");
		headerFont.setFontHeightInPoints((short) 10);
		headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
		headerFont.setColor(IndexedColors.WHITE.getIndex());
		style.setFont(headerFont);
		styles.put("header", style);
		
		return styles;
	}
 
Example 11
Source File: ExcelWriter_StyleFormatTest.java    From hop with Apache License 2.0 4 votes vote down vote up
/**
 * Setup the data necessary for Excel Writer transform
 *
 * @param fileType
 * @throws HopException
 */
private void createTransformData( String fileType ) throws HopException {
  transformData = new ExcelWriterData();
  transformData.inputRowMeta = transform.getInputRowMeta().clone();
  transformData.outputRowMeta = transform.getInputRowMeta().clone();

  // we don't run pipeline so ExcelWriter.processRow() doesn't get executed
  // we populate the ExcelWriterData with bare minimum required values
  //
  CellReference cellRef = new CellReference( transformMeta.getStartingCell() );
  transformData.startingRow = cellRef.getRow();
  transformData.startingCol = cellRef.getCol();
  transformData.posX = transformData.startingCol;
  transformData.posY = transformData.startingRow;

  int numOfFields = transformData.inputRowMeta.size();
  transformData.fieldnrs = new int[ numOfFields ];
  transformData.linkfieldnrs = new int[ numOfFields ];
  transformData.commentfieldnrs = new int[ numOfFields ];
  for ( int i = 0; i < numOfFields; i++ ) {
    transformData.fieldnrs[ i ] = i;
    transformData.linkfieldnrs[ i ] = -1;
    transformData.commentfieldnrs[ i ] = -1;
  }

  // we avoid reading/writing Excel files, so ExcelWriter.prepareNextOutputFile() doesn't get executed
  // create Excel workbook object
  //
  transformData.wb = transformMeta.getExtension().equalsIgnoreCase( "xlsx" ) ? new XSSFWorkbook() : new HSSFWorkbook();
  transformData.sheet = transformData.wb.createSheet();
  transformData.file = null;
  transformData.clearStyleCache( numOfFields );

  // we avoid reading template file from disk
  // so set beforehand cells with custom style and formatting
  DataFormat format = transformData.wb.createDataFormat();
  Row xlsRow = transformData.sheet.createRow( 0 );

  // Cell F1 has custom style applied, used as template
  Cell cell = xlsRow.createCell( 5 );
  CellStyle cellStyle = transformData.wb.createCellStyle();
  cellStyle.setBorderRight( BorderStyle.THICK );
  cellStyle.setFillPattern( FillPatternType.FINE_DOTS );
  cell.setCellStyle( cellStyle );

  // Cell G1 has same style, but also a custom data format
  cellStyle = transformData.wb.createCellStyle();
  cellStyle.cloneStyleFrom( cell.getCellStyle() );
  cell = xlsRow.createCell( 6 );
  cellStyle.setDataFormat( format.getFormat( "##0,000.0" ) );
  cell.setCellStyle( cellStyle );
}
 
Example 12
Source File: ExcelWriterTransform_StyleFormatTest.java    From hop with Apache License 2.0 4 votes vote down vote up
/**
 * Setup the data necessary for Excel Writer transform
 *
 * @param fileType
 * @throws HopException
 */
private void createTransformData( String fileType ) throws HopException {
  data = new ExcelWriterTransformData();
  data.inputRowMeta = inputRowMeta.clone();
  data.outputRowMeta = inputRowMeta.clone();

  // we don't run pipeline so ExcelWriterTransform.processRow() doesn't get executed
  // we populate the ExcelWriterTransformData with bare minimum required values
  CellReference cellRef = new CellReference( meta.getStartingCell() );
  data.startingRow = cellRef.getRow();
  data.startingCol = cellRef.getCol();
  data.posX = data.startingCol;
  data.posY = data.startingRow;

  int numOfFields = data.inputRowMeta.size();
  data.fieldnrs = new int[ numOfFields ];
  data.linkfieldnrs = new int[ numOfFields ];
  data.commentfieldnrs = new int[ numOfFields ];
  for ( int i = 0; i < numOfFields; i++ ) {
    data.fieldnrs[ i ] = i;
    data.linkfieldnrs[ i ] = -1;
    data.commentfieldnrs[ i ] = -1;
  }

  // we avoid reading/writing Excel files, so ExcelWriterTransform.prepareNextOutputFile() doesn't get executed
  // create Excel workbook object
  data.wb = meta.getExtension().equalsIgnoreCase( "xlsx" ) ? new XSSFWorkbook() : new HSSFWorkbook();
  data.sheet = data.wb.createSheet();
  data.file = null;
  data.clearStyleCache( numOfFields );

  // we avoid reading template file from disk
  // so set beforehand cells with custom style and formatting
  DataFormat format = data.wb.createDataFormat();
  Row xlsRow = data.sheet.createRow( 0 );

  // Cell F1 has custom style applied, used as template
  Cell cell = xlsRow.createCell( 5 );
  CellStyle cellStyle = data.wb.createCellStyle();
  cellStyle.setBorderRight( BorderStyle.THICK );
  cellStyle.setFillPattern( FillPatternType.FINE_DOTS );
  cell.setCellStyle( cellStyle );

  // Cell G1 has same style, but also a custom data format
  cellStyle = data.wb.createCellStyle();
  cellStyle.cloneStyleFrom( cell.getCellStyle() );
  cell = xlsRow.createCell( 6 );
  cellStyle.setDataFormat( format.getFormat( "##0,000.0" ) );
  cell.setCellStyle( cellStyle );
}
 
Example 13
Source File: ExportExcel.java    From Shop-for-JavaWeb with MIT License 4 votes vote down vote up
/**
	 * 创建表格样式
	 * @param wb 工作薄对象
	 * @return 样式列表
	 */
	private Map<String, CellStyle> createStyles(Workbook wb) {
		Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
		
		CellStyle style = wb.createCellStyle();
		style.setAlignment(CellStyle.ALIGN_CENTER);
		style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
		Font titleFont = wb.createFont();
		titleFont.setFontName("Arial");
		titleFont.setFontHeightInPoints((short) 16);
		titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
		style.setFont(titleFont);
		styles.put("title", style);

		style = wb.createCellStyle();
		style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
		style.setBorderRight(CellStyle.BORDER_THIN);
		style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
		style.setBorderLeft(CellStyle.BORDER_THIN);
		style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
		style.setBorderTop(CellStyle.BORDER_THIN);
		style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
		style.setBorderBottom(CellStyle.BORDER_THIN);
		style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
		Font dataFont = wb.createFont();
		dataFont.setFontName("Arial");
		dataFont.setFontHeightInPoints((short) 10);
		style.setFont(dataFont);
		styles.put("data", style);
		
		style = wb.createCellStyle();
		style.cloneStyleFrom(styles.get("data"));
		style.setAlignment(CellStyle.ALIGN_LEFT);
		styles.put("data1", style);

		style = wb.createCellStyle();
		style.cloneStyleFrom(styles.get("data"));
		style.setAlignment(CellStyle.ALIGN_CENTER);
		styles.put("data2", style);

		style = wb.createCellStyle();
		style.cloneStyleFrom(styles.get("data"));
		style.setAlignment(CellStyle.ALIGN_RIGHT);
		styles.put("data3", style);
		
		style = wb.createCellStyle();
		style.cloneStyleFrom(styles.get("data"));
//		style.setWrapText(true);
		style.setAlignment(CellStyle.ALIGN_CENTER);
		style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
		style.setFillPattern(CellStyle.SOLID_FOREGROUND);
		Font headerFont = wb.createFont();
		headerFont.setFontName("Arial");
		headerFont.setFontHeightInPoints((short) 10);
		headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
		headerFont.setColor(IndexedColors.WHITE.getIndex());
		style.setFont(headerFont);
		styles.put("header", style);
		
		return styles;
	}
 
Example 14
Source File: ExcelUtils.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public static void copyRow(Sheet worksheet, Row newRow, Row sourceRow) {
Workbook workbook = worksheet.getWorkbook();
      for (int i = 0; i < sourceRow.getLastCellNum(); i++) {
          Cell oldCell = sourceRow.getCell(i);
          Cell newCell = newRow.createCell(i);

          if (oldCell == null) {
              newCell = null;
              continue;
          }

          CellStyle newCellStyle = workbook.createCellStyle();
          newCellStyle.cloneStyleFrom(oldCell.getCellStyle());
          newCell.setCellStyle(newCellStyle);

          if (oldCell.getCellComment() != null) {
              newCell.setCellComment(oldCell.getCellComment());
          }

          if (oldCell.getHyperlink() != null) {
              newCell.setHyperlink(oldCell.getHyperlink());
          }

          newCell.setCellType(oldCell.getCellType());

          switch (oldCell.getCellType()) {
              case Cell.CELL_TYPE_BLANK:
                  newCell.setCellValue(oldCell.getStringCellValue());
                  break;
              case Cell.CELL_TYPE_BOOLEAN:
                  newCell.setCellValue(oldCell.getBooleanCellValue());
                  break;
              case Cell.CELL_TYPE_ERROR:
                  newCell.setCellErrorValue(oldCell.getErrorCellValue());
                  break;
              case Cell.CELL_TYPE_FORMULA:
                  newCell.setCellFormula(oldCell.getCellFormula());
                  break;
              case Cell.CELL_TYPE_NUMERIC:
                  newCell.setCellValue(oldCell.getNumericCellValue());
                  break;
              case Cell.CELL_TYPE_STRING:
                  newCell.setCellValue(oldCell.getRichStringCellValue());
                  break;
          }
      }

      for (int i = 0; i < worksheet.getNumMergedRegions(); i++) {
          CellRangeAddress cellRangeAddress = worksheet.getMergedRegion(i);
          if (cellRangeAddress.getFirstRow() == sourceRow.getRowNum()) {
              CellRangeAddress newCellRangeAddress = new CellRangeAddress(newRow.getRowNum(),
                      (newRow.getRowNum() +
                              (cellRangeAddress.getLastRow() - cellRangeAddress.getFirstRow()
                                      )),
                      cellRangeAddress.getFirstColumn(),
                      cellRangeAddress.getLastColumn());
              worksheet.addMergedRegion(newCellRangeAddress);
          }
      }
  }
 
Example 15
Source File: ExcelCell.java    From objectlabkit with Apache License 2.0 4 votes vote down vote up
public CellStyle cloneStyle() {
    final CellStyle cellStyle = poiWorkbook().createCellStyle();
    cellStyle.cloneStyleFrom(currentCell.getCellStyle());
    return cellStyle;
}
 
Example 16
Source File: ExcelWriterStep_StyleFormatTest.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Setup the data necessary for Excel Writer step
 *
 * @param fileType
 * @throws KettleException
 */
private void createStepData( String fileType ) throws KettleException {
  stepData = new ExcelWriterStepData();
  stepData.inputRowMeta = step.getInputRowMeta().clone();
  stepData.outputRowMeta = step.getInputRowMeta().clone();

  // we don't run transformation so ExcelWriterStep.processRow() doesn't get executed
  // we populate the ExcelWriterStepData with bare minimum required values
  CellReference cellRef = new CellReference( stepMeta.getStartingCell() );
  stepData.startingRow = cellRef.getRow();
  stepData.startingCol = cellRef.getCol();
  stepData.posX = stepData.startingCol;
  stepData.posY = stepData.startingRow;

  int numOfFields = stepData.inputRowMeta.size();
  stepData.fieldnrs = new int[numOfFields];
  stepData.linkfieldnrs = new int[numOfFields];
  stepData.commentfieldnrs = new int[numOfFields];
  for ( int i = 0; i < numOfFields; i++ ) {
    stepData.fieldnrs[i] = i;
    stepData.linkfieldnrs[i] = -1;
    stepData.commentfieldnrs[i] = -1;
  }

  // we avoid reading/writing Excel files, so ExcelWriterStep.prepareNextOutputFile() doesn't get executed
  // create Excel workbook object
  stepData.wb = stepMeta.getExtension().equalsIgnoreCase( "xlsx" ) ? new XSSFWorkbook() : new HSSFWorkbook();
  stepData.sheet = stepData.wb.createSheet();
  stepData.file = null;
  stepData.clearStyleCache( numOfFields );

  // we avoid reading template file from disk
  // so set beforehand cells with custom style and formatting
  DataFormat format = stepData.wb.createDataFormat();
  Row xlsRow = stepData.sheet.createRow( 0 );

  // Cell F1 has custom style applied, used as template
  Cell cell = xlsRow.createCell( 5 );
  CellStyle cellStyle = stepData.wb.createCellStyle();
  cellStyle.setBorderRight( BorderStyle.THICK );
  cellStyle.setFillPattern( FillPatternType.FINE_DOTS );
  cell.setCellStyle( cellStyle );

  // Cell G1 has same style, but also a custom data format
  cellStyle = stepData.wb.createCellStyle();
  cellStyle.cloneStyleFrom( cell.getCellStyle() );
  cell = xlsRow.createCell( 6 );
  cellStyle.setDataFormat( format.getFormat( "##0,000.0" ) );
  cell.setCellStyle( cellStyle );
}