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

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

本文整理了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

  1. private HSSFFont matchFont( Font matchFont )
  2. {
  3. HSSFColor hssfColor = workbook.getCustomPalette()
  4. .findColor((byte)foreground.getRed(), (byte)foreground.getGreen(), (byte)foreground.getBlue());
  5. if (hssfColor == null)
  6. hssfColor = workbook.getCustomPalette().findSimilarColor((byte)foreground.getRed(), (byte)foreground.getGreen(), (byte)foreground.getBlue());
  7. boolean bold = (matchFont.getStyle() & Font.BOLD) != 0;
  8. boolean italic = (matchFont.getStyle() & Font.ITALIC) != 0;
  9. HSSFFont hssfFont = workbook.findFont(bold,
  10. hssfColor.getIndex(),
  11. (short)(matchFont.getSize() * 20),
  12. matchFont.getName(),
  13. italic,
  14. false,
  15. (short)0,
  16. (byte)0);
  17. if (hssfFont == null)
  18. {
  19. hssfFont = workbook.createFont();
  20. hssfFont.setBold(bold);
  21. hssfFont.setColor(hssfColor.getIndex());
  22. hssfFont.setFontHeight((short)(matchFont.getSize() * 20));
  23. hssfFont.setFontName(matchFont.getName());
  24. hssfFont.setItalic(italic);
  25. hssfFont.setStrikeout(false);
  26. hssfFont.setTypeOffset((short) 0);
  27. hssfFont.setUnderline((byte) 0);
  28. }
  29. return hssfFont;
  30. }

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

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

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

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

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

  1. // Set up a rudimentary worksheet with a cell in it
  2. HSSFWorkbook wb = new HSSFWorkbook();
  3. HSSFSheet sheet = wb.createSheet(“sheet1”);
  4. HSSFRow row = sheet.createRow(0);
  5. HSSFCell cell = row.createCell(0);
  6. // Set up fonts
  7. HSSFFont blueFont = workbook.createFont();
  8. blueFont.setColor(HSSFColor.BLUE.index);
  9. HSSFFont greenFont = workbook.createFont();
  10. greenFont.setColor(HSSFColor.GREEN.index);
  11. // create a cell style and assign the first font to it
  12. HSSFCellStyle style = workbook.createCellStyle();
  13. style.setFont(blueFont);
  14. // assign the style to the cell
  15. cell.setCellStyle(style);
  16. // override the parts of the text that you want to
  17. // color differently by applying a different font.
  18. HSSFRichTextString richString = new HSSFRichTextString("Hello, World!");
  19. richString.applyFont(6, 13, greenFont);
  20. cell.setCellValue(richString);

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

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

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

  1. private HSSFFont setFontColor(HSSFWorkbook wb, HSSFFont font, String colorCode) {
  2. HSSFPalette palette = wb.getCustomPalette();
  3. // if format is rgb(x,y,z) form, retrieve the 3 numbers within the
  4. // parentheses
  5. colorCode = colorCode.trim();
  6. if (colorCode.toLowerCase().startsWith("rgb")) {
  7. String rgbNumString = colorCode.substring(3, colorCode.length()).trim();
  8. rgbNumString = rgbNumString.substring(1, rgbNumString.length()-1).trim();
  9. String[] rgbNums = StringUtils.split(rgbNumString, ",");
  10. int[] rgbInts = { Integer.parseInt(rgbNums[0].trim()),
  11. Integer.parseInt(rgbNums[1].trim()),
  12. Integer.parseInt(rgbNums[2].trim()) };
  13. HSSFColor color = palette.findSimilarColor(rgbInts[0], rgbInts[1], rgbInts[2]);
  14. short palIndex = color.getIndex();
  15. font.setColor(palIndex);
  16. return font;
  17. }
  18. return font;
  19. }

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

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

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

  1. private static HSSFFont createCustomFont(short colorIndex, Byte underlineWeight) {
  2. HSSFFont font = wb1.createFont();
  3. font.setFontName(HSSFFont.FONT_ARIAL);
  4. font.setFontHeightInPoints((short) 10);
  5. font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  6. font.setColor(colorIndex);
  7. font.setUnderline(underlineWeight);
  8. return font;
  9. }

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

  1. private static HSSFCellStyle createCommentStyle(HSSFWorkbook wb) {
  2. HSSFFont commentFont = wb.createFont();
  3. commentFont.setColor(HSSFColor.GREEN.index);
  4. commentFont.setItalic(true);
  5. commentFont.setFontHeightInPoints((short)12);
  6. HSSFCellStyle commentStyle = wb.createCellStyle();
  7. commentStyle.setFont(commentFont);
  8. return commentStyle;
  9. }

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

  1. private static HSSFCellStyle createPlurarStyle(HSSFWorkbook wb) {
  2. HSSFFont commentFont = wb.createFont();
  3. commentFont.setColor(HSSFColor.GREY_50_PERCENT.index);
  4. commentFont.setItalic(true);
  5. commentFont.setFontHeightInPoints((short)12);
  6. HSSFCellStyle commentStyle = wb.createCellStyle();
  7. commentStyle.setFont(commentFont);
  8. return commentStyle;
  9. }

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

  1. /**
  2. * 设置Excel表头字体颜色
  3. * @param wb Excel文件
  4. * @return: 字体对象
  5. */
  6. private HSSFCellStyle createRedFont(HSSFWorkbook wb){
  7. HSSFCellStyle style = wb.createCellStyle();
  8. HSSFFont font = wb.createFont();
  9. font.setColor(HSSFColor.BLACK.index);
  10. //font.setBoldweight(Font.BOLDWEIGHT_BOLD);
  11. style.setFont(font);
  12. style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
  13. style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
  14. return style;
  15. }

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

  1. private HSSFCellStyle createHeaderStyle(){
  2. //TO-DO read style information from sakai.properties
  3. HSSFFont font = gradesWorkbook.createFont();
  4. font.setFontName(HSSFFont.FONT_ARIAL);
  5. font.setColor(IndexedColors.PLUM.getIndex());
  6. font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  7. HSSFCellStyle cellStyle = gradesWorkbook.createCellStyle();
  8. cellStyle.setFont(font);
  9. return cellStyle;
  10. }

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

  1. /**
  2. * Obtain the style used to render a header or footer.
  3. * @return The style used to render a header or footer.
  4. */
  5. private HSSFCellStyle getHeaderFooterStyle()
  6. {
  7. HSSFCellStyle style = this.wb.createCellStyle();
  8. style.setFillPattern(HSSFCellStyle.FINE_DOTS);
  9. style.setFillBackgroundColor(HSSFColor.BLUE_GREY.index);
  10. HSSFFont bold = this.wb.createFont();
  11. bold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  12. bold.setColor(HSSFColor.WHITE.index);
  13. style.setFont(bold);
  14. return style;
  15. }

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

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

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

  1. /**
  2. * 设置Excel表头字体颜色
  3. *
  4. * @param wb Excel文件
  5. * @return: 字体对象
  6. */
  7. private HSSFCellStyle createRedFont(HSSFWorkbook wb) {
  8. HSSFCellStyle style = wb.createCellStyle();
  9. HSSFFont font = wb.createFont();
  10. font.setColor(HSSFColor.BLACK.index);
  11. font.setBoldweight(Font.BOLDWEIGHT_BOLD);
  12. style.setFont(font);
  13. style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
  14. style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
  15. return style;
  16. }

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

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

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

  1. HSSFWorkbook wb = new HSSFWorkbook();
  2. HSSFSheet sheet = wb.createSheet();
  3. HSSFRow row = sheet.createRow((short) 0);
  4. HSSFCell cell = row.createCell((short) 0);
  5. cell.setCellValue("Default Palette");
  6. //apply some colors from the standard palette,
  7. // as in the previous examples.
  8. //we'll use red text on a lime background
  9. HSSFCellStyle style = wb.createCellStyle();
  10. style.setFillForegroundColor(HSSFColor.LIME.index);
  11. style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
  12. HSSFFont font = wb.createFont();
  13. font.setColor(HSSFColor.RED.index);
  14. style.setFont(font);
  15. cell.setCellStyle(style);

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

  1. private void createDefaultHeaderCellStyle() {
  2. headerCellStyle = workbook.createCellStyle();
  3. HSSFFont font = workbook.createFont();
  4. font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  5. font.setColor(HSSFColor.WHITE.index);
  6. headerCellStyle.setFont(font);
  7. headerCellStyle
  8. .setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index);
  9. headerCellStyle.setFillPattern(HSSFCellStyle.FINE_DOTS);
  10. headerCellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
  11. headerCellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  12. }

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

  1. //////////////////////Excel Header Style/////////////////////////
  2. HSSFCellStyle headerlabelcs = wb.createCellStyle();
  3. headerlabelcs.setFillForegroundColor(HSSFColor.PALE_BLUE.index);
  4. headerlabelcs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
  5. headerlabelcs.setBorderLeft((short)1);
  6. headerlabelcs.setBorderRight((short)1);
  7. HSSFFont headerlabelfont = wb.createFont();
  8. headerlabelfont.setFontHeightInPoints((short)12);
  9. headerlabelfont.setFontName("Calibri");
  10. headerlabelfont.setColor(HSSFColor.BLACK.index);
  11. headerlabelfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  12. headerlabelcs.setFont(headerlabelfont);
  13. //////////////////////Excel Header Style/////////////////////////

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

  1. /**
  2. * Templated method that is called for all header cells.
  3. *
  4. * @param wb the wb
  5. * @param headerCell the header cell
  6. * @return the HSSF cell style
  7. */
  8. public HSSFCellStyle createHeaderStyle(HSSFWorkbook wb, HeaderCell headerCell)
  9. {
  10. HSSFCellStyle headerStyle = getNewCellStyle();
  11. headerStyle.setFillPattern(FillPatternType.FINE_DOTS);
  12. headerStyle.setFillBackgroundColor(HSSFColorPredefined.BLUE_GREY.getIndex());
  13. HSSFFont bold = wb.createFont();
  14. bold.setBold(true);
  15. bold.setColor(HSSFColorPredefined.WHITE.getIndex());
  16. headerStyle.setFont(bold);
  17. return headerStyle;
  18. }

相关文章