Search in sources :

Example 26 with WritableFont

use of jxl.write.WritableFont in project pentaho-kettle by pentaho.

the class ExcelOutput method setFonts.

private void setFonts() throws Exception {
    // --- Set Header font
    int headerFontSize = Const.toInt(environmentSubstitute(meta.getHeaderFontSize()), ExcelOutputMeta.DEFAULT_FONT_SIZE);
    // Set font name
    FontName headerFontName = ExcelFontMap.getFontName(meta.getHeaderFontName());
    // Set UnderlineStyle
    UnderlineStyle underline = ExcelFontMap.getUnderlineStyle(meta.getHeaderFontUnderline());
    WritableFont writableHeaderFont = null;
    if (meta.isHeaderFontBold()) {
        writableHeaderFont = new WritableFont(headerFontName, headerFontSize, WritableFont.BOLD, meta.isHeaderFontItalic(), underline);
    } else {
        writableHeaderFont = new WritableFont(headerFontName, headerFontSize, WritableFont.NO_BOLD, meta.isHeaderFontItalic(), underline);
    }
    // Header font color
    Colour fontHeaderColour = ExcelFontMap.getColour(meta.getHeaderFontColor(), Colour.BLACK);
    if (!fontHeaderColour.equals(Colour.BLACK)) {
        writableHeaderFont.setColour(fontHeaderColour);
    }
    data.headerCellFormat = new WritableCellFormat(writableHeaderFont);
    // Header background color
    if (meta.getHeaderBackGroundColor() != ExcelOutputMeta.FONT_COLOR_NONE) {
        data.headerCellFormat.setBackground(ExcelFontMap.getColour(meta.getHeaderBackGroundColor(), null));
    }
    // Set alignment
    data.headerCellFormat = ExcelFontMap.getAlignment(meta.getHeaderAlignment(), data.headerCellFormat);
    data.headerCellFormat = ExcelFontMap.getOrientation(meta.getHeaderFontOrientation(), data.headerCellFormat);
    // Do we need to put a image on the header
    if (!Utils.isEmpty(data.realHeaderImage)) {
        InputStream imageStream = null;
        try (FileObject imageFile = KettleVFS.getFileObject(data.realHeaderImage)) {
            if (!imageFile.exists()) {
                throw new KettleException(BaseMessages.getString(PKG, "ExcelInputLog.ImageFileNotExists", data.realHeaderImage));
            }
            data.realHeaderImage = KettleVFS.getFilename(imageFile);
            // Put an image
            Dimension m = ExcelFontMap.getImageDimension(data.realHeaderImage);
            data.headerImageWidth = m.getWidth() * 0.016;
            data.headerImageHeight = m.getHeight() * 0.0625;
            byte[] imageData = new byte[(int) imageFile.getContent().getSize()];
            imageStream = KettleVFS.getInputStream(imageFile);
            imageStream.read(imageData);
            data.headerImage = new WritableImage(0, 0, data.headerImageWidth, data.headerImageHeight, imageData);
        } catch (Exception e) {
            throw new KettleException(e);
        }
    }
    // --- Set rows font
    // Set font size
    int rowFontSize = Const.toInt(environmentSubstitute(meta.getRowFontSize()), ExcelOutputMeta.DEFAULT_FONT_SIZE);
    // Set font name
    FontName rowFontName = ExcelFontMap.getFontName(meta.getRowFontName());
    data.writableFont = new WritableFont(rowFontName, rowFontSize, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE);
    // Row font color
    Colour rowFontColour = ExcelFontMap.getColour(meta.getRowFontColor(), Colour.BLACK);
    if (!fontHeaderColour.equals(Colour.BLACK)) {
        data.writableFont.setColour(rowFontColour);
    }
    // Set rows background color if needed
    if (meta.getRowBackGroundColor() != ExcelOutputMeta.FONT_COLOR_NONE) {
        data.rowFontBackgoundColour = ExcelFontMap.getColour(meta.getRowBackGroundColor(), null);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) WritableFont(jxl.write.WritableFont) InputStream(java.io.InputStream) UnderlineStyle(jxl.format.UnderlineStyle) Dimension(java.awt.Dimension) WritableCellFormat(jxl.write.WritableCellFormat) KettleException(org.pentaho.di.core.exception.KettleException) BiffException(jxl.read.biff.BiffException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Colour(jxl.format.Colour) WritableImage(jxl.write.WritableImage) FontName(jxl.write.WritableFont.FontName) FileObject(org.apache.commons.vfs2.FileObject)

Aggregations

WritableCellFormat (jxl.write.WritableCellFormat)26 WritableFont (jxl.write.WritableFont)26 WriteException (jxl.write.WriteException)15 CellView (jxl.CellView)5 Label (jxl.write.Label)5 WorkbookSettings (jxl.WorkbookSettings)4 WritableSheet (jxl.write.WritableSheet)4 WritableWorkbook (jxl.write.WritableWorkbook)4 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Date (java.util.Date)2 CellFormat (jxl.format.CellFormat)2 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)1 DatabaseEditorConfig (com.cubrid.common.ui.spi.model.DatabaseEditorConfig)1 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)1 CUBRIDResultSetMetaDataProxy (com.cubrid.jdbc.proxy.driver.CUBRIDResultSetMetaDataProxy)1 CCell (eu.ggnet.lucidcalc.CCell)1 CColumnView (eu.ggnet.lucidcalc.CColumnView)1 CFormat (eu.ggnet.lucidcalc.CFormat)1 CRowView (eu.ggnet.lucidcalc.CRowView)1