org.apache.poi.hssf.usermodel.HSSFFont.setColor()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(273)

本文整理了Java中org.apache.poi.hssf.usermodel.HSSFFont.setColor()方法的一些代码示例,展示了HSSFFont.setColor()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HSSFFont.setColor()方法的具体详情如下:
包路径:org.apache.poi.hssf.usermodel.HSSFFont
类名称:HSSFFont
方法名:setColor

HSSFFont.setColor介绍

[英]set the color for the font
[中]设置字体的颜色

代码示例

代码示例来源:origin: org.apache.poi/poi

private HSSFFont matchFont( Font matchFont )
{
  HSSFColor hssfColor = workbook.getCustomPalette()
      .findColor((byte)foreground.getRed(), (byte)foreground.getGreen(), (byte)foreground.getBlue());
  if (hssfColor == null)
    hssfColor = workbook.getCustomPalette().findSimilarColor((byte)foreground.getRed(), (byte)foreground.getGreen(), (byte)foreground.getBlue());
  boolean bold = (matchFont.getStyle() & Font.BOLD) != 0;
  boolean italic = (matchFont.getStyle() & Font.ITALIC) != 0;
  HSSFFont hssfFont = workbook.findFont(bold,
        hssfColor.getIndex(),
        (short)(matchFont.getSize() * 20),
        matchFont.getName(),
        italic,
        false,
        (short)0,
        (byte)0);
  if (hssfFont == null)
  {
    hssfFont = workbook.createFont();
    hssfFont.setBold(bold);
    hssfFont.setColor(hssfColor.getIndex());
    hssfFont.setFontHeight((short)(matchFont.getSize() * 20));
    hssfFont.setFontName(matchFont.getName());
    hssfFont.setItalic(italic);
    hssfFont.setStrikeout(false);
    hssfFont.setTypeOffset((short) 0);
    hssfFont.setUnderline((byte) 0);
  }
  return hssfFont;
}

代码示例来源:origin: primefaces/primefaces

Color color = Color.decode(cellFontColor);
HSSFColor cellColor = palette.findSimilarColor(color.getRed(), color.getGreen(), color.getBlue());
((HSSFFont) cellFont).setColor(cellColor.getIndex());

代码示例来源:origin: primefaces/primefaces

color = Color.decode(facetFontColor);
HSSFColor facetColor = palette.findSimilarColor(color.getRed(), color.getGreen(), color.getBlue());
((HSSFFont) facetFont).setColor(facetColor.getIndex());

代码示例来源:origin: stackoverflow.com

// Set up a rudimentary worksheet with a cell in it
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet(“sheet1”);
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell(0);

// Set up fonts
HSSFFont blueFont = workbook.createFont();
blueFont.setColor(HSSFColor.BLUE.index);

HSSFFont greenFont = workbook.createFont();
greenFont.setColor(HSSFColor.GREEN.index);

// create a cell style and assign the first font to it
HSSFCellStyle style = workbook.createCellStyle();
style.setFont(blueFont);

// assign the style to the cell
cell.setCellStyle(style);

// override the parts of the text that you want to
// color differently by applying a different font.
HSSFRichTextString richString = new HSSFRichTextString("Hello, World!");
richString.applyFont(6, 13, greenFont);
cell.setCellValue(richString);

代码示例来源:origin: stackoverflow.com

font.setColor(HSSFColor.RED.index);
style.setFont(font);

代码示例来源:origin: stackoverflow.com

private HSSFFont setFontColor(HSSFWorkbook wb, HSSFFont font, String colorCode) {
  HSSFPalette palette = wb.getCustomPalette();

  // if format is rgb(x,y,z) form, retrieve the 3 numbers within the
  // parentheses
  colorCode = colorCode.trim();
  if (colorCode.toLowerCase().startsWith("rgb")) {
    String rgbNumString = colorCode.substring(3, colorCode.length()).trim();
    rgbNumString = rgbNumString.substring(1, rgbNumString.length()-1).trim();
    String[] rgbNums = StringUtils.split(rgbNumString, ",");
    int[] rgbInts = { Integer.parseInt(rgbNums[0].trim()),
        Integer.parseInt(rgbNums[1].trim()),
        Integer.parseInt(rgbNums[2].trim()) };
    HSSFColor color = palette.findSimilarColor(rgbInts[0], rgbInts[1], rgbInts[2]);
    short palIndex = color.getIndex();
    font.setColor(palIndex);
    return font;
  } 
  return font;
}

代码示例来源:origin: stackoverflow.com

HSSFCellStyle cellStyle = workBook.createCellStyle();        
  HSSFFont font = wb.createFont();
  font.setFontName(XSSFFont.DEFAULT_FONT_NAME);
  font.setFontHeightInPoints((short)10);
  font.setColor(IndexedColors.BLUE.getIndex());
  cellStyle.setFont(font);
 //the version i am using is poi-3.8

代码示例来源:origin: paypal/SeLion

private static HSSFFont createCustomFont(short colorIndex, Byte underlineWeight) {
  HSSFFont font = wb1.createFont();
  font.setFontName(HSSFFont.FONT_ARIAL);
  font.setFontHeightInPoints((short) 10);
  font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  font.setColor(colorIndex);
  font.setUnderline(underlineWeight);
  return font;
}

代码示例来源:origin: TomasKypta/android-lang-tool

private static HSSFCellStyle createCommentStyle(HSSFWorkbook wb) {
  HSSFFont commentFont = wb.createFont();
  commentFont.setColor(HSSFColor.GREEN.index);
  commentFont.setItalic(true);
  commentFont.setFontHeightInPoints((short)12);
  HSSFCellStyle commentStyle = wb.createCellStyle();
  commentStyle.setFont(commentFont);
  return commentStyle;
}

代码示例来源:origin: TomasKypta/android-lang-tool

private static HSSFCellStyle createPlurarStyle(HSSFWorkbook wb) {
  HSSFFont commentFont = wb.createFont();
  commentFont.setColor(HSSFColor.GREY_50_PERCENT.index);
  commentFont.setItalic(true);
  commentFont.setFontHeightInPoints((short)12);
  HSSFCellStyle commentStyle = wb.createCellStyle();
  commentStyle.setFont(commentFont);
  return commentStyle;
}

代码示例来源:origin: com.github.mg365/mg-common

/**
 * 设置Excel表头字体颜色
 * @param wb    Excel文件
 * @return:     字体对象
 */
private HSSFCellStyle createRedFont(HSSFWorkbook wb){
  HSSFCellStyle style = wb.createCellStyle();
  HSSFFont font = wb.createFont();
  font.setColor(HSSFColor.BLACK.index);
  //font.setBoldweight(Font.BOLDWEIGHT_BOLD);
  style.setFont(font);
  style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
  style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
  return style;
}

代码示例来源:origin: org.sakaiproject.assignment/sakai-assignment-impl

private HSSFCellStyle createHeaderStyle(){
  //TO-DO read style information from sakai.properties
  HSSFFont font = gradesWorkbook.createFont();
  font.setFontName(HSSFFont.FONT_ARIAL);
  font.setColor(IndexedColors.PLUM.getIndex());
  font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  HSSFCellStyle cellStyle = gradesWorkbook.createCellStyle();
  cellStyle.setFont(font);
  return cellStyle;
}

代码示例来源:origin: displaytag/displaytag-export-poi

/**
 * Obtain the style used to render a header or footer.
 * @return The style used to render a header or footer.
 */
private HSSFCellStyle getHeaderFooterStyle()
{
  HSSFCellStyle style = this.wb.createCellStyle();
  style.setFillPattern(HSSFCellStyle.FINE_DOTS);
  style.setFillBackgroundColor(HSSFColor.BLUE_GREY.index);
  HSSFFont bold = this.wb.createFont();
  bold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  bold.setColor(HSSFColor.WHITE.index);
  style.setFont(bold);
  return style;
}

代码示例来源:origin: youseries/ureport

font.setColor(fontColor.getIndex());
String fontFamily=cellStyle.getFontFamily();
if(customStyle!=null && customStyle.getFontFamily()!=null){

代码示例来源:origin: com.github.mg365/mg-common

/**
 * 设置Excel表头字体颜色
 *
 * @param wb Excel文件
 * @return: 字体对象
 */
private HSSFCellStyle createRedFont(HSSFWorkbook wb) {
  HSSFCellStyle style = wb.createCellStyle();
  HSSFFont font = wb.createFont();
  font.setColor(HSSFColor.BLACK.index);
  font.setBoldweight(Font.BOLDWEIGHT_BOLD);
  style.setFont(font);
  style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
  style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
  return style;
}

代码示例来源:origin: io.choerodon/choerodon-starter-core

/**
   * 设置Excel图片的格式:字体居中、变粗、蓝色、12号
   *
   * @param headerStyle 头部样式
   * @param book        生产的excel book      HSSFWorkbook对象
   * @author chenssy
   * @date 2014年6月16日 下午8:46:49
   * @version 1.0
   */
  private static void setHeaderStyle(HSSFCellStyle headerStyle, HSSFWorkbook book) {
    headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);   //水平居中
    headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//垂直居中
    //设置字体
    HSSFFont font = book.createFont();
    font.setFontHeightInPoints((short) 12);     //字号:12号
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);   //变粗
    font.setColor(HSSFColor.BLUE.index);   //蓝色

    headerStyle.setFont(font);
  }
}

代码示例来源:origin: stackoverflow.com

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFRow row = sheet.createRow((short) 0);
HSSFCell cell = row.createCell((short) 0);
cell.setCellValue("Default Palette");

//apply some colors from the standard palette,
// as in the previous examples.
//we'll use red text on a lime background

HSSFCellStyle style = wb.createCellStyle();
style.setFillForegroundColor(HSSFColor.LIME.index);
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

HSSFFont font = wb.createFont();
font.setColor(HSSFColor.RED.index);
style.setFont(font);

cell.setCellStyle(style);

代码示例来源:origin: org.seasar.tuigwaa/tuigwaa-ext

private void createDefaultHeaderCellStyle() {
  headerCellStyle = workbook.createCellStyle();
  HSSFFont font = workbook.createFont();
  font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  font.setColor(HSSFColor.WHITE.index);
  headerCellStyle.setFont(font);
  headerCellStyle
      .setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index);
  headerCellStyle.setFillPattern(HSSFCellStyle.FINE_DOTS);
  headerCellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
  headerCellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
}

代码示例来源:origin: stackoverflow.com

//////////////////////Excel Header Style/////////////////////////   
   HSSFCellStyle headerlabelcs = wb.createCellStyle();
   headerlabelcs.setFillForegroundColor(HSSFColor.PALE_BLUE.index);
   headerlabelcs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
   headerlabelcs.setBorderLeft((short)1);
   headerlabelcs.setBorderRight((short)1);
   HSSFFont headerlabelfont = wb.createFont();
   headerlabelfont.setFontHeightInPoints((short)12);
   headerlabelfont.setFontName("Calibri");
   headerlabelfont.setColor(HSSFColor.BLACK.index);
   headerlabelfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
   headerlabelcs.setFont(headerlabelfont); 
       //////////////////////Excel Header Style/////////////////////////

代码示例来源:origin: com.github.hazendaz/displaytag

/**
 * Templated method that is called for all header cells.
 *
 * @param wb the wb
 * @param headerCell the header cell
 * @return the HSSF cell style
 */
public HSSFCellStyle createHeaderStyle(HSSFWorkbook wb, HeaderCell headerCell)
{
  HSSFCellStyle headerStyle = getNewCellStyle();
  headerStyle.setFillPattern(FillPatternType.FINE_DOTS);
  headerStyle.setFillBackgroundColor(HSSFColorPredefined.BLUE_GREY.getIndex());
  HSSFFont bold = wb.createFont();
  bold.setBold(true);
  bold.setColor(HSSFColorPredefined.WHITE.getIndex());
  headerStyle.setFont(bold);
  return headerStyle;
}

相关文章