use of jxl.write.WritableCellFormat in project cubrid-manager by CUBRID.
the class RunSQLProcessManager method createaWritableSheet.
/**
* create excel sheet
* @param wwb
* @param fileName
* @param index
* @return
*/
public WritableSheet createaWritableSheet(WritableWorkbook wwb, String fileName, int index) {
// FIXME logic code move to core module
WritableSheet ws = null;
try {
ws = wwb.createSheet(fileName, index);
WritableCellFormat normalCellStyle = getNormalCell();
jxl.write.Label header = new jxl.write.Label(0, 0, Messages.failedSQLlineNumber, normalCellStyle);
ws.addCell(header);
jxl.write.Label header1 = new jxl.write.Label(1, 0, Messages.failedSQL, normalCellStyle);
ws.addCell(header1);
jxl.write.Label header2 = new jxl.write.Label(2, 0, Messages.failedErrorMessage, normalCellStyle);
ws.addCell(header2);
ws.setColumnView(1, 100);
ws.setColumnView(2, 80);
} catch (Exception e) {
ws = null;
LOGGER.error("create WritableSheet error", e);
}
return ws;
}
use of jxl.write.WritableCellFormat in project aws-doc-sdk-examples by awsdocs.
the class WriteExcel method createLabel.
// Create headings in the Excel spreadsheet.
private void createLabel(WritableSheet sheet) throws WriteException {
// Create a Times font.
WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10);
// Define the cell format.
times = new WritableCellFormat(times10pt);
// Automatically wrap the cells.
times.setWrap(true);
// Create a bold font with underlining.
WritableFont times10ptBoldUnderline = new WritableFont(WritableFont.TIMES, 10, WritableFont.BOLD, false, UnderlineStyle.SINGLE);
timesBoldUnderline = new WritableCellFormat(times10ptBoldUnderline);
// Automatically wrap the cells.
timesBoldUnderline.setWrap(true);
CellView cv = new CellView();
cv.setFormat(times);
cv.setFormat(timesBoldUnderline);
cv.setAutosize(true);
// Write a few headers.
addCaption(sheet, 0, 0, "Writer");
addCaption(sheet, 1, 0, "Date");
addCaption(sheet, 2, 0, "Guide");
addCaption(sheet, 3, 0, "Description");
addCaption(sheet, 4, 0, "Status");
}
use of jxl.write.WritableCellFormat in project network-monitor by caarmen.
the class ExcelExport method createCellFormats.
/**
* In order to set text to bold, red, or green, we need to create cell
* formats for each style.
*/
private void createCellFormats() {
// Insert a dummy empty cell, so we can obtain its cell. This allows to
// start with a default cell format.
Label cell = new Label(0, 0, " ");
CellFormat cellFormat = cell.getCellFormat();
try {
// Center all cells.
mDefaultFormat = new WritableCellFormat(cellFormat);
mDefaultFormat.setAlignment(Alignment.CENTRE);
// Create the bold format
final WritableFont boldFont = new WritableFont(cellFormat.getFont());
mBoldFormat = new WritableCellFormat(mDefaultFormat);
boldFont.setBoldStyle(WritableFont.BOLD);
mBoldFormat.setFont(boldFont);
mBoldFormat.setWrap(true);
mBoldFormat.setAlignment(Alignment.CENTRE);
// Create the red format
mRedFormat = new WritableCellFormat(mDefaultFormat);
final WritableFont redFont = new WritableFont(cellFormat.getFont());
redFont.setColour(Colour.RED);
mRedFormat.setFont(redFont);
// Create the green format
mGreenFormat = new WritableCellFormat(mDefaultFormat);
final WritableFont greenFont = new WritableFont(cellFormat.getFont());
greenFont.setColour(Colour.GREEN);
mGreenFormat.setFont(greenFont);
// Create the amber format
mAmberFormat = new WritableCellFormat(mDefaultFormat);
final WritableFont amberFont = new WritableFont(cellFormat.getFont());
amberFont.setColour(Colour.LIGHT_ORANGE);
mAmberFormat.setFont(amberFont);
} catch (WriteException e) {
Log.e(TAG, "createCellFormats Could not create cell formats", e);
}
}
use of jxl.write.WritableCellFormat in project pentaho-kettle by pentaho.
the class ExcelOutput method writeField.
/**
* Write a value to Excel, increasing data.positionX with one afterwards.
*
* @param v
* The value to write
* @param vMeta
* The valueMeta to write
* @param excelField
* the field information (if any, otherwise : null)
* @param column
* the excel column for getting the template format
* @param isHeader
* true if this is part of the header/footer
* @return <code>true</code> if write succeeded
*/
private boolean writeField(Object v, ValueMetaInterface vMeta, ExcelField excelField, int column, boolean isHeader) {
try {
String hashName = vMeta.getName();
if (isHeader) {
// all strings, can map to the same format.
hashName = "____header_field____";
}
WritableCellFormat cellFormat = data.formats.get(hashName);
// when template is used, take over the column format
if (cellFormat == null && meta.isTemplateEnabled() && !isHeader) {
try {
if (column < data.templateColumns) {
CellFormat format = data.sheet.getColumnView(column).getFormat();
if (format != null) {
cellFormat = new WritableCellFormat(format);
// save for next time around...
data.formats.put(hashName, cellFormat);
}
}
} catch (RuntimeException e) {
// ignore if the column is not found, format as usual
}
}
if (meta.isAutoSizeColumns()) {
// prepare auto size columns
int vlen = vMeta.getName().length();
if (!isHeader && v != null) {
vlen = v.toString().trim().length();
}
if (vlen > 0 && vlen > data.fieldsWidth[column]) {
data.fieldsWidth[column] = vlen + 1;
}
}
// Do we need to use a specific format to header?
if (isHeader) {
// Set font for header and footer+
// row to write in
int rowNumber = data.sheet.getColumn(data.positionX).length;
data.sheet.addCell(new Label(data.positionX, rowNumber, vMeta.getName(), data.headerCellFormat));
if (cellFormat == null) {
// save for next time around...
data.formats.put(hashName, data.headerCellFormat);
}
} else {
// Will write new row after existing ones in current column
data.positionY = data.sheet.getColumn(data.positionX).length;
switch(vMeta.getType()) {
case ValueMetaInterface.TYPE_DATE:
{
if (v != null && vMeta.getDate(v) != null) {
if (cellFormat == null) {
if (excelField != null && excelField.getFormat() != null) {
DateFormat dateFormat = new DateFormat(excelField.getFormat());
if (data.writableFont != null) {
cellFormat = new WritableCellFormat(data.writableFont, dateFormat);
if (data.rowFontBackgoundColour != null) {
cellFormat.setBackground(data.rowFontBackgoundColour);
}
} else {
cellFormat = new WritableCellFormat(dateFormat);
}
} else {
if (data.writableFont != null) {
cellFormat = new WritableCellFormat(data.writableFont, DateFormats.FORMAT9);
if (data.rowFontBackgoundColour != null) {
cellFormat.setBackground(data.rowFontBackgoundColour);
}
} else {
cellFormat = new WritableCellFormat(DateFormats.FORMAT9);
}
}
// save for next time around...
data.formats.put(hashName, cellFormat);
}
DateTime dateTime = new DateTime(data.positionX, data.positionY, vMeta.getDate(v), cellFormat);
data.sheet.addCell(dateTime);
} else if (!meta.isNullBlank()) {
data.sheet.addCell(new Label(data.positionX, data.positionY, ""));
}
break;
}
default:
// Output the data value as a string
case ValueMetaInterface.TYPE_STRING:
case ValueMetaInterface.TYPE_BOOLEAN:
case ValueMetaInterface.TYPE_BINARY:
{
if (cellFormat == null) {
cellFormat = new WritableCellFormat(data.writableFont);
if (data.rowFontBackgoundColour != null) {
cellFormat.setBackground(data.rowFontBackgoundColour);
}
data.formats.put(hashName, cellFormat);
}
if (v != null) {
Label label = new Label(data.positionX, data.positionY, vMeta.getString(v), cellFormat);
data.sheet.addCell(label);
} else if (!meta.isNullBlank()) {
data.sheet.addCell(new Label(data.positionX, data.positionY, ""));
}
break;
}
case ValueMetaInterface.TYPE_NUMBER:
case ValueMetaInterface.TYPE_BIGNUMBER:
case ValueMetaInterface.TYPE_INTEGER:
{
if (v != null) {
if (cellFormat == null) {
String format;
if (excelField != null && excelField.getFormat() != null) {
format = excelField.getFormat();
} else {
format = "###,###.00";
}
NumberFormat numberFormat = new NumberFormat(format);
if (data.writableFont != null) {
cellFormat = new WritableCellFormat(data.writableFont, numberFormat);
if (data.rowFontBackgoundColour != null) {
cellFormat.setBackground(data.rowFontBackgoundColour);
}
} else {
cellFormat = new WritableCellFormat(numberFormat);
}
// save for next time around...
data.formats.put(vMeta.getName(), cellFormat);
}
jxl.write.Number number = new jxl.write.Number(data.positionX, data.positionY, vMeta.getNumber(v), cellFormat);
data.sheet.addCell(number);
} else if (!meta.isNullBlank()) {
data.sheet.addCell(new Label(data.positionX, data.positionY, ""));
}
break;
}
}
}
} catch (Exception e) {
logError("Error writing field (" + data.positionX + "," + data.positionY + ") : " + e.toString());
logError(Const.getStackTracker(e));
return false;
} finally {
// always advance :-)
data.positionX++;
}
return true;
}
use of jxl.write.WritableCellFormat 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