Search in sources :

Example 1 with Colour

use of jxl.format.Colour 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

Dimension (java.awt.Dimension)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Colour (jxl.format.Colour)1 UnderlineStyle (jxl.format.UnderlineStyle)1 BiffException (jxl.read.biff.BiffException)1 WritableCellFormat (jxl.write.WritableCellFormat)1 WritableFont (jxl.write.WritableFont)1 FontName (jxl.write.WritableFont.FontName)1 WritableImage (jxl.write.WritableImage)1 FileObject (org.apache.commons.vfs2.FileObject)1 KettleException (org.pentaho.di.core.exception.KettleException)1