本文整理汇总了Java中org.apache.poi.xssf.usermodel.XSSFFont类的典型用法代码示例。如果您正苦于以下问题:Java XSSFFont类的具体用法?Java XSSFFont怎么用?Java XSSFFont使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XSSFFont类属于org.apache.poi.xssf.usermodel包,在下文中一共展示了XSSFFont类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createColorXSSFFont
import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
/**
* @param wb
* @param fontFamily
* @param height
* @param color
* @param bold
* @return
*/
public static XSSFFont createColorXSSFFont(XSSFWorkbook wb,String fontFamily,short height,XSSFColor color,boolean bold){
String message="XSSFWorkbook must not be null!";
Objects.requireNonNull(wb, () -> message);
XSSFFont cellfont=wb.createFont();
cellfont.setFontName(fontFamily);
cellfont.setFontHeightInPoints(height);
cellfont.setColor(color);
if(bold){
cellfont.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
}
return cellfont;
}
示例2: configFont
import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
private void configFont(Font font) {
font.setBold(isBold());
font.setItalic(isItalic());
font.setStrikeout(isStrikeout());
font.setUnderline(isUnderline() ? Font.U_SINGLE : Font.U_NONE);
if (getFontSize() != null) {
font.setFontHeightInPoints(fontSize.shortValue());
}
if (getFontColor() != null) {
if (font instanceof XSSFFont) {
((XSSFFont)font).setColor(new XSSFColor(toRgbByte(fontColor)));
} else {
font.setColor(fontColor.getIndex());
}
}
}
示例3: createPoiFont
import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的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;
}
示例4: addLangCell
import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
private int addLangCell(Row header, TmxSegement segment) {
int CellNum = header.getLastCellNum();
if (-1 == CellNum) {
CellNum = 0;
}
Cell createCell = header.createCell(CellNum);
CellStyle cellStyle = wb.createCellStyle();
XSSFFont headerFont = (XSSFFont) wb.createFont();
headerFont.setBold(true);
cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
cellStyle.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND);
cellStyle.setFont(headerFont);
createCell.setCellValue(segment.getLangCode());
createCell.setCellStyle(cellStyle);
sh.setColumnWidth(CellNum, (100 * 7 + 5) / 7 * 256);
return CellNum;
}
示例5: addColourToFont
import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
@Override
public void addColourToFont(Workbook workbook, Font font, String colour) {
if(colour == null) {
return ;
}
if(IStyle.TRANSPARENT_VALUE.equals(colour)) {
return ;
}
if(font instanceof XSSFFont) {
XSSFFont xFont = (XSSFFont)font;
XSSFColor xColour = getXColour(colour);
if(xColour != null) {
xFont.setColor(xColour);
}
}
}
示例6: correctFontColorIfBackground
import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
@Override
public Font correctFontColorIfBackground( FontManager fm, Workbook wb, BirtStyle birtStyle, Font font ) {
CSSValue bgColour = birtStyle.getProperty( StyleConstants.STYLE_BACKGROUND_COLOR );
int bgRgb[] = parseColour( bgColour == null ? null : bgColour.getCssText(), "white" );
XSSFColor colour = ((XSSFFont)font).getXSSFColor();
int fgRgb[] = rgbOnly( colour.getARgb() );
if( ( fgRgb[0] == 255 ) && ( fgRgb[1] == 255 ) && ( fgRgb[2] == 255 ) ) {
fgRgb[0]=fgRgb[1]=fgRgb[2]=0;
} else if( ( fgRgb[0] == 0 ) && ( fgRgb[1] == 0 ) && ( fgRgb[2] == 0 ) ) {
fgRgb[0]=fgRgb[1]=fgRgb[2]=255;
}
if( ( bgRgb[ 0 ] == fgRgb[ 0 ] ) && ( bgRgb[ 1 ] == fgRgb[ 1 ] ) && ( bgRgb[ 2 ] == fgRgb[ 2 ] ) ) {
IStyle addedStyle = new AreaStyle( fm.getCssEngine() );
addedStyle.setColor( contrastColour( bgRgb ) );
return fm.getFontWithExtraStyle( font, addedStyle );
} else {
return font;
}
}
示例7: styleHeader
import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
/**
* See http://thinktibits.blogspot.co.uk/2012/12/Java-POI-XLS-XLSX-Change-Cell-Font-Color-Example.html
* Currently only for xlsx
* @param wb
* @param sheet
*/
private static void styleHeader(Workbook wb, Sheet sheet){
if(XSSFWorkbook.class.isInstance(wb) && XSSFSheet.class.isInstance(sheet)){
XSSFWorkbook my_workbook = (XSSFWorkbook)wb;
XSSFCellStyle my_style = my_workbook.createCellStyle();
XSSFFont my_font=my_workbook.createFont();
my_font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
my_style.setFont(my_font);
Row row = sheet.getRow(0);
if(row!=null && row.getFirstCellNum()>=0){
for(int i = row.getFirstCellNum() ; i<= row.getLastCellNum();i++){
Cell cell = row.getCell(i);
if(cell!=null){
cell.setCellStyle(my_style);
}
}
}
}
}
示例8: getRepresentation
import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
/**
* Gets the string representation of the given <code>Font</code>.
* @param f A <code>Font</code>.
* @return The string representation.
*/
private String getRepresentation(Font f)
{
// Colors that need an instanceof check
Color fontColor;
if (f instanceof HSSFFont)
{
HSSFFont hf = (HSSFFont) f;
fontColor = hf.getHSSFColor((HSSFWorkbook) myWorkbook);
}
else if (f instanceof XSSFFont)
{
XSSFFont xf = (XSSFFont) f;
fontColor = xf.getXSSFColor();
}
else
throw new IllegalArgumentException("Bad Font type: " + f.getClass().getName());
return getRepresentation(f.getBoldweight(), f.getItalic(), fontColor, f.getFontName(),
f.getFontHeightInPoints(), f.getUnderline(), f.getStrikeout(), f.getCharSet(), f.getTypeOffset());
}
示例9: findFont
import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
private static Font findFont(Workbook workbook, Font font)
{
int numFonts = workbook.getNumberOfFonts();
for (short i = 0; i < numFonts; i++)
{
Font f = workbook.getFontAt(i);
if (f.getBoldweight() == font.getBoldweight() &&
f.getItalic() == font.getItalic() &&
f.getColor() == font.getColor() &&
f.getFontHeight() == font.getFontHeight() &&
f.getUnderline() == font.getUnderline() &&
f.getFontName().equals(font.getFontName()) &&
f.getTypeOffset() == font.getTypeOffset()
)
{
if (!(font instanceof XSSFFont && f instanceof XSSFFont) ||
((XSSFFont) font).getXSSFColor().getARGBHex().equals(((XSSFFont) f).getXSSFColor().getARGBHex()))
{
if (DEBUG)
System.err.println(" Found existing, matching Font!");
return f;
}
}
}
if (DEBUG)
System.err.println(" Did NOT find existing, matching Font!");
return null;
}
示例10: XLSXTranslatorOutputFormat
import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
/**
* Public constructor.
* @param os output stream
*/
public XLSXTranslatorOutputFormat(final OutputStream os) {
if (os == null) {
throw new NullPointerException("The output stream is null");
}
this.os = os;
// Temporary files will be compressed
this.wb.setCompressTempFiles(true);
// Define default style
Font defaultFont = this.wb.createFont();
defaultFont.setFontName("Arial");
defaultFont.setFontHeightInPoints((short) 10);
this.defaultStyle = this.wb.createCellStyle();
this.defaultStyle.setFont(defaultFont);
// Define header style
Font headerFont = this.wb.createFont();
headerFont.setFontName(defaultFont.getFontName());
headerFont.setFontHeightInPoints(defaultFont.getFontHeightInPoints());
headerFont.setItalic(true);
this.headerStyle = this.wb.createCellStyle();
this.headerStyle.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
this.headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
this.headerStyle.setFont(headerFont);
// Define link style
Font linkfont = this.wb.createFont();
linkfont.setFontName(defaultFont.getFontName());
linkfont.setFontHeightInPoints(defaultFont.getFontHeightInPoints());
linkfont.setUnderline(XSSFFont.U_SINGLE);
linkfont.setColor(IndexedColors.BLUE.getIndex());
this.linkStyle = this.wb.createCellStyle();
this.linkStyle.setFont(linkfont);
}
示例11: createXSSFFont
import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
/**
* @param wb
* @return {code XSSFFont}
*/
public static XSSFFont createXSSFFont(XSSFWorkbook wb){
String message="XSSFWorkbook must not be null!";
Objects.requireNonNull(wb, () -> message);
XSSFFont cellfont=wb.createFont();
cellfont.setFontName("新宋体");
cellfont.setFontHeightInPoints((short) 12);
cellfont.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
cellfont.setColor(new XSSFColor(new Color(50,73,38)));
return cellfont;
}
示例12: setCell
import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
/**
* @param sheet
* @param pos 位置【row,col】
* @param style
* @param v
*/
public static void setCell(final XSSFWorkbook wb,final XSSFSheet sheet,int[] pos,CellStyle style,FontStyle font,String v){
XSSFRow row = sheet.getRow(pos[0]);
XSSFCell cell = CellValueUtil.createCellIfNotPresent(row, pos[1]);
XSSFCellStyle _style = Objects
.requireNonNull(new XSSFCellStyleLib(wb).get(style),
"specified style not defined!");
XSSFFont _font = Objects
.requireNonNull(new XSSFFontStyleLib(wb).get(font),
"specified font not defined!");
_style.setFont(_font);
setCellProperties(cell, v, _style);
}
示例13: getCaptionCellStyle
import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
/**
* 返回副标题字体样式
* @param wb
* @return
*/
public static XSSFCellStyle getCaptionCellStyle(XSSFWorkbook wb){
//default cellStyle
XSSFCellStyle cellStyle=createXSSFCellStyle(wb);
//default font
XSSFFont cellfont=XSSFontUtil.createXSSFFont(wb);
cellStyle.setFont(cellfont);
return cellStyle;
}
示例14: getcontentCellStyle
import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
/**
* 返回excel内容字体样式
* @param wb
* @return
*/
public static XSSFCellStyle getcontentCellStyle(XSSFWorkbook wb){
String message="XSSFWorkbook must not be null!";
Objects.requireNonNull(wb, () -> message);
XSSFCellStyle contentStyle=createCenterXSSFCellStyle(wb);
//fill enlarged font
XSSFFont enlargedFont=XSSFontUtil.createColorXSSFFont(wb, "新宋体", (short) 16, new XSSFColor(Color.WHITE), true);
contentStyle.setFont(enlargedFont);
return contentStyle;
}
示例15: get
import org.apache.poi.xssf.usermodel.XSSFFont; //导入依赖的package包/类
public XSSFFont get(FontStyle k){
XSSFFont v=FONT_STYLE_MAP.get(k);
if(null==v){
throw new FontStyleNotFoundException("the font style have not been defined!");
}
return v;
}