use of org.apache.poi.hssf.usermodel.HSSFFont in project adempiere by adempiere.
the class AbstractExcelExporter method getStyle.
private HSSFCellStyle getStyle(int row, int col) {
int displayType = getDisplayType(row, col);
String key = "cell-" + col + "-" + displayType;
HSSFCellStyle cs = m_styles.get(key);
if (cs == null) {
boolean isHighlightNegativeNumbers = true;
cs = m_workbook.createCellStyle();
HSSFFont font = getFont(false);
cs.setFont(font);
// Border
cs.setBorderLeft((short) 1);
cs.setBorderTop((short) 1);
cs.setBorderRight((short) 1);
cs.setBorderBottom((short) 1);
//
if (DisplayType.isDate(displayType)) {
cs.setDataFormat(m_dataFormat.getFormat("DD.MM.YYYY"));
} else if (DisplayType.isNumeric(displayType)) {
DecimalFormat df = DisplayType.getNumberFormat(displayType, getLanguage());
String format = getFormatString(df, isHighlightNegativeNumbers);
cs.setDataFormat(m_dataFormat.getFormat(format));
}
m_styles.put(key, cs);
}
return cs;
}
use of org.apache.poi.hssf.usermodel.HSSFFont in project adempiere by adempiere.
the class AbstractExcelExporter method getHeaderStyle.
private HSSFCellStyle getHeaderStyle(int col) {
String key = "header-" + col;
HSSFCellStyle cs_header = m_styles.get(key);
if (cs_header == null) {
HSSFFont font_header = getFont(true);
cs_header = m_workbook.createCellStyle();
cs_header.setFont(font_header);
cs_header.setBorderLeft((short) 2);
cs_header.setBorderTop((short) 2);
cs_header.setBorderRight((short) 2);
cs_header.setBorderBottom((short) 2);
cs_header.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
cs_header.setWrapText(true);
m_styles.put(key, cs_header);
}
return cs_header;
}
use of org.apache.poi.hssf.usermodel.HSSFFont in project poi by apache.
the class NewLinesInCells method main.
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet s = wb.createSheet();
HSSFRow r = null;
HSSFCell c = null;
HSSFCellStyle cs = wb.createCellStyle();
HSSFFont f2 = wb.createFont();
cs = wb.createCellStyle();
cs.setFont(f2);
// Word Wrap MUST be turned on
cs.setWrapText(true);
r = s.createRow(2);
r.setHeight((short) 0x349);
c = r.createCell(2);
c.setCellType(CellType.STRING);
c.setCellValue("Use \n with word wrap on to create a new line");
c.setCellStyle(cs);
s.setColumnWidth(2, (int) ((50 * 8) / ((double) 1 / 20)));
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
wb.close();
}
use of org.apache.poi.hssf.usermodel.HSSFFont in project poi by apache.
the class SVTableCellEditor method getTableCellEditorComponent.
/**
* Gets the tableCellEditorComponent attribute of the SVTableCellEditor object
*
* @return The tableCellEditorComponent value
*/
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
System.out.println("GetTableCellEditorComponent");
HSSFCell cell = (HSSFCell) value;
if (cell != null) {
HSSFCellStyle style = cell.getCellStyle();
HSSFFont f = wb.getFontAt(style.getFontIndex());
boolean isbold = f.getBold();
boolean isitalics = f.getItalic();
int fontstyle = Font.PLAIN;
if (isbold) {
fontstyle = Font.BOLD;
}
if (isitalics) {
fontstyle = fontstyle | Font.ITALIC;
}
int fontheight = f.getFontHeightInPoints();
if (fontheight == 9) {
//fix for stupid ol Windows
fontheight = 10;
}
Font font = new Font(f.getFontName(), fontstyle, fontheight);
editor.setFont(font);
if (style.getFillPatternEnum() == FillPatternType.SOLID_FOREGROUND) {
editor.setBackground(getAWTColor(style.getFillForegroundColor(), white));
} else {
editor.setBackground(white);
}
editor.setForeground(getAWTColor(f.getColor(), black));
//Set the value that is rendered for the cell
switch(cell.getCellTypeEnum()) {
case BLANK:
editor.setText("");
break;
case BOOLEAN:
if (cell.getBooleanCellValue()) {
editor.setText("true");
} else {
editor.setText("false");
}
break;
case NUMERIC:
editor.setText(Double.toString(cell.getNumericCellValue()));
break;
case STRING:
editor.setText(cell.getRichStringCellValue().getString());
break;
case FORMULA:
default:
editor.setText("?");
}
switch(style.getAlignmentEnum()) {
case LEFT:
case JUSTIFY:
case FILL:
editor.setHorizontalAlignment(SwingConstants.LEFT);
break;
case CENTER:
case CENTER_SELECTION:
editor.setHorizontalAlignment(SwingConstants.CENTER);
break;
case GENERAL:
case RIGHT:
editor.setHorizontalAlignment(SwingConstants.RIGHT);
break;
default:
editor.setHorizontalAlignment(SwingConstants.LEFT);
break;
}
}
return editor;
}
use of org.apache.poi.hssf.usermodel.HSSFFont in project poi by apache.
the class SVTableCellRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
boolean isBorderSet = false;
//If the JTables default cell renderer has been setup correctly the
//value will be the HSSFCell that we are trying to render
HSSFCell c = (HSSFCell) value;
if (c != null) {
HSSFCellStyle s = c.getCellStyle();
HSSFFont f = wb.getFontAt(s.getFontIndex());
setFont(SVTableUtils.makeFont(f));
if (s.getFillPatternEnum() == FillPatternType.SOLID_FOREGROUND) {
setBackground(SVTableUtils.getAWTColor(s.getFillForegroundColor(), SVTableUtils.white));
} else
setBackground(SVTableUtils.white);
setForeground(SVTableUtils.getAWTColor(f.getColor(), SVTableUtils.black));
cellBorder.setBorder(SVTableUtils.getAWTColor(s.getTopBorderColor(), SVTableUtils.black), SVTableUtils.getAWTColor(s.getRightBorderColor(), SVTableUtils.black), SVTableUtils.getAWTColor(s.getBottomBorderColor(), SVTableUtils.black), SVTableUtils.getAWTColor(s.getLeftBorderColor(), SVTableUtils.black), s.getBorderTopEnum(), s.getBorderRightEnum(), s.getBorderBottomEnum(), s.getBorderLeftEnum(), hasFocus);
setBorder(cellBorder);
isBorderSet = true;
//Set the value that is rendered for the cell
switch(c.getCellTypeEnum()) {
case BLANK:
setValue("");
break;
case BOOLEAN:
if (c.getBooleanCellValue()) {
setValue("true");
} else {
setValue("false");
}
break;
case NUMERIC:
short format = s.getDataFormat();
double numericValue = c.getNumericCellValue();
if (cellFormatter.useRedColor(format, numericValue))
setForeground(Color.red);
else
setForeground(null);
setValue(cellFormatter.format(format, c.getNumericCellValue()));
break;
case STRING:
setValue(c.getRichStringCellValue().getString());
break;
case FORMULA:
default:
setValue("?");
}
//Set the text alignment of the cell
switch(s.getAlignmentEnum()) {
case LEFT:
case JUSTIFY:
case FILL:
setHorizontalAlignment(SwingConstants.LEFT);
break;
case CENTER:
case CENTER_SELECTION:
setHorizontalAlignment(SwingConstants.CENTER);
break;
case GENERAL:
case RIGHT:
setHorizontalAlignment(SwingConstants.RIGHT);
break;
default:
setHorizontalAlignment(SwingConstants.LEFT);
break;
}
} else {
setValue("");
setBackground(SVTableUtils.white);
}
if (hasFocus) {
if (!isBorderSet) {
//This is the border to paint when there is no border
//and the cell has focus
cellBorder.setBorder(SVTableUtils.black, SVTableUtils.black, SVTableUtils.black, SVTableUtils.black, BorderStyle.NONE, BorderStyle.NONE, BorderStyle.NONE, BorderStyle.NONE, isSelected);
setBorder(cellBorder);
}
if (table.isCellEditable(row, column)) {
setForeground(UIManager.getColor("Table.focusCellForeground"));
setBackground(UIManager.getColor("Table.focusCellBackground"));
}
} else if (!isBorderSet) {
setBorder(noFocusBorder);
}
// ---- begin optimization to avoid painting background ----
Color back = getBackground();
boolean colorMatch = (back != null) && (back.equals(table.getBackground())) && table.isOpaque();
setOpaque(!colorMatch);
// ---- end optimization to aviod painting background ----
return this;
}
Aggregations