本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFFont類的典型用法代碼示例。如果您正苦於以下問題:Java HSSFFont類的具體用法?Java HSSFFont怎麽用?Java HSSFFont使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HSSFFont類屬於org.apache.poi.hssf.usermodel包,在下文中一共展示了HSSFFont類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createHSSFCellStyle
import org.apache.poi.hssf.usermodel.HSSFFont; //導入依賴的package包/類
private HSSFCellStyle createHSSFCellStyle(Workbook wb, int[] bgColor, int[] fontColor, int fontSize) {
HSSFWorkbook workbook = (HSSFWorkbook) wb;
HSSFPalette palette = workbook.getCustomPalette();
palette.setColorAtIndex((short) 9, (byte) fontColor[0], (byte) fontColor[1], (byte) fontColor[2]);
palette.setColorAtIndex((short) 10, (byte) bgColor[0], (byte) bgColor[1], (byte) bgColor[2]);
HSSFFont titleFont = workbook.createFont();
titleFont.setCharSet(HSSFFont.DEFAULT_CHARSET);
titleFont.setFontName("宋體");
titleFont.setColor((short) 9);
titleFont.setBold(true);
titleFont.setFontHeightInPoints((short) fontSize);
HSSFCellStyle titleStyle = (HSSFCellStyle) createBorderCellStyle(workbook, true);
titleStyle.setFont(titleFont);
titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
titleStyle.setFillForegroundColor((short) 10);
titleStyle.setAlignment(HorizontalAlignment.CENTER);
titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
return titleStyle;
}
示例2: createColumnHeaders
import org.apache.poi.hssf.usermodel.HSSFFont; //導入依賴的package包/類
/**
*/
protected void createColumnHeaders() {
final HSSFRow headersRow = this.sheet.createRow(0);
final HSSFFont font = this.workbook.createFont();
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
final HSSFCellStyle style = this.workbook.createCellStyle();
style.setFont(font);
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
int counter = 1;
for (int i = 0; i < this.model.getColumnCount(); i++) {
final HSSFCell cell = headersRow.createCell(counter++);
// cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(this.model.getColumnName(i));
cell.setCellStyle(style);
}
}
示例3: getRichTextString
import org.apache.poi.hssf.usermodel.HSSFFont; //導入依賴的package包/類
protected HSSFRichTextString getRichTextString(JRStyledText styledText, short forecolor, JRFont defaultFont, Locale locale)
{
String text = styledText.getText();
HSSFRichTextString richTextStr = new HSSFRichTextString(text);
int runLimit = 0;
AttributedCharacterIterator iterator = styledText.getAttributedString().getIterator();
while(runLimit < styledText.length() && (runLimit = iterator.getRunLimit()) <= styledText.length())
{
Map<Attribute,Object> attributes = iterator.getAttributes();
JRFont runFont = attributes.isEmpty()? defaultFont : new JRBaseFont(attributes);
short runForecolor = attributes.get(TextAttribute.FOREGROUND) != null ?
getWorkbookColor((Color)attributes.get(TextAttribute.FOREGROUND)).getIndex() :
forecolor;
HSSFFont font = getLoadedFont(runFont, runForecolor, attributes, locale);
richTextStr.applyFont(iterator.getIndex(), runLimit, font);
iterator.setIndex(runLimit);
}
return richTextStr;
}
示例4: getLoadedCellStyle
import org.apache.poi.hssf.usermodel.HSSFFont; //導入依賴的package包/類
protected HSSFCellStyle getLoadedCellStyle(
FillPatternType mode,
short backcolor,
HorizontalAlignment horizontalAlignment,
VerticalAlignment verticalAlignment,
short rotation,
HSSFFont font,
BoxStyle box,
boolean isWrapText,
boolean isCellLocked,
boolean isCellHidden,
boolean isShrinkToFit
)
{
StyleInfo style = new StyleInfo(mode, backcolor, horizontalAlignment, verticalAlignment, rotation, font, box, isWrapText, isCellLocked, isCellHidden, isShrinkToFit);
return getLoadedCellStyle(style);
}
示例5: StyleInfo
import org.apache.poi.hssf.usermodel.HSSFFont; //導入依賴的package包/類
public StyleInfo(
FillPatternType mode,
short backcolor,
HorizontalAlignment horizontalAlignment,
VerticalAlignment verticalAlignment,
short rotation,
HSSFFont font,
JRExporterGridCell gridCell,
boolean wrapText,
boolean cellLocked,
boolean cellHidden,
boolean shrinkToFit
)
{
this(mode,
backcolor,
horizontalAlignment,
verticalAlignment,
rotation,
font,
(gridCell == null ? null : new BoxStyle(gridCell)),
wrapText,
cellLocked,
cellHidden,
shrinkToFit);
}
示例6: getRichTextString
import org.apache.poi.hssf.usermodel.HSSFFont; //導入依賴的package包/類
protected HSSFRichTextString getRichTextString(JRStyledText styledText, short forecolor, JRFont defaultFont, Locale locale) {
String text = styledText.getText();
HSSFRichTextString richTextStr = new HSSFRichTextString(text);
int runLimit = 0;
AttributedCharacterIterator iterator = styledText.getAttributedString().getIterator();
while(runLimit < styledText.length() && (runLimit = iterator.getRunLimit()) <= styledText.length()) {
Map<Attribute,Object> attributes = iterator.getAttributes();
JRFont runFont = attributes.isEmpty()? defaultFont : new JRBaseFont(attributes);
short runForecolor = attributes.get(TextAttribute.FOREGROUND) != null
? getWorkbookColor((Color)attributes.get(TextAttribute.FOREGROUND)).getIndex()
: forecolor;
HSSFFont font = getLoadedFont(runFont, runForecolor, attributes, locale);
richTextStr.applyFont(iterator.getIndex(), runLimit, font);
iterator.setIndex(runLimit);
}
return richTextStr;
}
示例7: copyFont
import org.apache.poi.hssf.usermodel.HSSFFont; //導入依賴的package包/類
public static HSSFFont copyFont(final HSSFWorkbook workbook, final HSSFFont font) {
final HSSFFont newFont = workbook.createFont();
// newFont.setBoldweight(font.getBoldweight());
// newFont.setCharSet(font.getCharSet());
// newFont.setColor(font.getColor());
// newFont.setFontHeight(font.getFontHeight());
// newFont.setFontHeightInPoints(font.getFontHeightInPoints());
// newFont.setFontName(font.getFontName());
// newFont.setItalic(font.getItalic());
// newFont.setStrikeout(font.getStrikeout());
// newFont.setTypeOffset(font.getTypeOffset());
// newFont.setUnderline(font.getUnderline());
return newFont;
}
示例8: getHeadCellStyle
import org.apache.poi.hssf.usermodel.HSSFFont; //導入依賴的package包/類
/**
*
* @Title: getCellStyle
* @Description: TODO(設置表頭樣式)
* @param wb
* @return
*/
private CellStyle getHeadCellStyle(Workbook wb) {
CellStyle style = wb.createCellStyle();
Font font = wb.createFont();
font.setFontName("宋體");
font.setFontHeightInPoints((short) 12);// 設置字體大小
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);// 加粗
style.setFillForegroundColor(HSSFColor.LIME.index);// 設置背景色
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
style.setAlignment(HSSFCellStyle.SOLID_FOREGROUND);// 讓單元格居中
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
style.setBorderTop(CellStyle.BORDER_THIN);
style.setBorderLeft(CellStyle.BORDER_THIN);
style.setBorderRight(CellStyle.BORDER_THIN);
style.setBorderBottom(CellStyle.BORDER_THIN);
// style.setWrapText(true);//設置自動換行
style.setFont(font);
return style;
}
示例9: getFontMetrics
import org.apache.poi.hssf.usermodel.HSSFFont; //導入依賴的package包/類
private FontMetrics getFontMetrics(HSSFFont hf){
FontMetrics fm;
Short pFont = new Short(hf.getIndex());
fm = (FontMetrics) fontMetrics.get(pFont);
if (fm == null) {
int style;
if((hf.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) || hf.getItalic()) { style = 0; if(hf.getBoldweight() == HSSFFont.BOLDWEIGHT_BOLD) style ^= Font.BOLD; if(hf.getItalic()) style ^= Font.ITALIC; } else { style = Font.PLAIN; }
Font f = new java.awt.Font(hf.getFontName(), style, hf.getFontHeightInPoints());
if (graphics == null) {
BufferedImage i = new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_GRAY); graphics = i.createGraphics(); }
fm = graphics.getFontMetrics(f);
fontMetrics.put(pFont, fm);
}
return fm;
}
示例10: notifyCellValue
import org.apache.poi.hssf.usermodel.HSSFFont; //導入依賴的package包/類
public void notifyCellValue(String val, HSSFFont font) {
if (val == null || val.length() == 0) return;
if (font == null) throw new IllegalArgumentException("font is null");
short width;
{
FontMetrics fm = getFontMetrics(font);
int w = fm.stringWidth(val);
width = (w > Short.MAX_VALUE) ? Short.MAX_VALUE : (short) w;
// TODO - this gives an underestimate with large font-sizes.
// TODO - What we *should* be considering is the 'display width'.
// This means we'd have to take into account cell type & format.
}
if (width > currentWidth) {
currentWidth = width;
}
}
示例11: createCellStyleForColumnHeading
import org.apache.poi.hssf.usermodel.HSSFFont; //導入依賴的package包/類
public static HSSFCellStyle createCellStyleForColumnHeading(HSSFWorkbook workBook) {
HSSFCellStyle cellStyle = workBook.createCellStyle();
HSSFFont fontObj = workBook.createFont();
cellStyle.setBorderBottom(BorderStyle.THIN);
cellStyle.setBorderTop(BorderStyle.THIN);
cellStyle.setBorderLeft(BorderStyle.THIN);
cellStyle.setBorderRight(BorderStyle.THIN);
cellStyle.setWrapText(true);
cellStyle.setAlignment(HorizontalAlignment.CENTER);
cellStyle.setFillBackgroundColor(Short.valueOf("22").shortValue());
cellStyle.setFillPattern(FillPatternType.BIG_SPOTS);
cellStyle.setFillForegroundColor(Short.valueOf("22").shortValue());
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
fontObj.setFontName("Calibri");
fontObj.setFontHeightInPoints(Short.valueOf("12").shortValue());
fontObj.setBold(true);
fontObj.setColor(Short.valueOf("8").shortValue());
cellStyle.setFont(fontObj);
return cellStyle;
}
示例12: copyFont
import org.apache.poi.hssf.usermodel.HSSFFont; //導入依賴的package包/類
public static HSSFFont copyFont(HSSFWorkbook workbook, HSSFFont font) {
HSSFFont newFont = workbook.createFont();
// newFont.setBoldweight(font.getBoldweight());
// newFont.setCharSet(font.getCharSet());
// newFont.setColor(font.getColor());
// newFont.setFontHeight(font.getFontHeight());
// newFont.setFontHeightInPoints(font.getFontHeightInPoints());
// newFont.setFontName(font.getFontName());
// newFont.setItalic(font.getItalic());
// newFont.setStrikeout(font.getStrikeout());
// newFont.setTypeOffset(font.getTypeOffset());
// newFont.setUnderline(font.getUnderline());
return newFont;
}
示例13: createPoiFont
import org.apache.poi.hssf.usermodel.HSSFFont; //導入依賴的package包/類
private static org.apache.poi.ss.usermodel.Font createPoiFont(PoiWorkbook workbook, Font other) {
org.apache.poi.ss.usermodel.Font poiFont = workbook.getPoiWorkbook().createFont();
poiFont.setFontHeightInPoints((short) Math.round(other.getSizeInPoints()));
poiFont.setFontName(other.getFamily());
final org.apache.poi.ss.usermodel.Color poiTextColor = workbook.getPoiColor(other.getColor());
if (poiFont instanceof HSSFFont && poiTextColor instanceof HSSFColor) {
poiFont.setColor(((HSSFColor) poiTextColor).getIndex());
} else if (poiFont instanceof XSSFFont && poiTextColor instanceof XSSFColor) {
((XSSFFont) poiFont).setColor((XSSFColor) poiTextColor);
} else {
// it should both either be XSSF _or_ HSSF implementations so this
// line should never be reached.
throw new IllegalStateException();
}
poiFont.setBold(other.isBold());
poiFont.setItalic(other.isItalic());
poiFont.setStrikeout(other.isStrikeThrough());
poiFont.setUnderline(other.isUnderlined() ? org.apache.poi.ss.usermodel.Font.U_SINGLE
: org.apache.poi.ss.usermodel.Font.U_NONE);
return poiFont;
}
示例14: getHeaderStyle
import org.apache.poi.hssf.usermodel.HSSFFont; //導入依賴的package包/類
private HSSFCellStyle getHeaderStyle(final 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;
}
示例15: createSecondTitleStyle
import org.apache.poi.hssf.usermodel.HSSFFont; //導入依賴的package包/類
private HSSFCellStyle createSecondTitleStyle(HSSFWorkbook wb){
HSSFCellStyle style = wb.createCellStyle();
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
style.setBorderBottom(HSSFCellStyle.BORDER_NONE);
style.setBorderLeft(HSSFCellStyle.BORDER_NONE);
style.setBorderRight(HSSFCellStyle.BORDER_NONE);
style.setBorderTop(HSSFCellStyle.BORDER_NONE);
style.setWrapText(true);
HSSFFont font = wb.createFont();
//font.setFontHeightInPoints((short)20);
font.setFontName("����");
style.setFont(font);
return style;
}