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