org.apache.poi.hssf.usermodel.HSSFFont类的使用及代码示例

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

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

HSSFFont介绍

[英]Represents a Font used in a workbook.
[中]表示工作簿中使用的字体。

代码示例

代码示例来源: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. HSSFCellStyle style = wb.createCellStyle();
  7. style.setFillForegroundColor(HSSFColor.LIME.index);
  8. style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
  9. HSSFFont font = wb.createFont();
  10. font.setColor(HSSFColor.RED.index);
  11. style.setFont(font);
  12. cell.setCellStyle(style);
  13. cell.setCellValue("Modified Palette");

代码示例来源:origin: rakam-io/rakam

  1. private CompletableFuture<byte[]> exportAsExcel(CompletableFuture<QueryResult> queryResult) {
  2. return queryResult.thenApply(result -> {
  3. HSSFWorkbook workbook = new HSSFWorkbook();
  4. HSSFSheet sheet = workbook.createSheet("Users generated by Rakam");
  5. HSSFFont boldFont = workbook.createFont();
  6. boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  7. HSSFCellStyle headerSyle = workbook.createCellStyle();
  8. headerSyle.setBorderBottom(CellStyle.BORDER_THIN);
  9. headerSyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
  10. headerSyle.setFont(boldFont);
  11. Row headerRow = sheet.createRow(0);
  12. headerRow.setRowStyle(headerSyle);
  13. Row row = sheet.createRow(i + 1);
  14. for (int c = 0; c < metadata.size(); c++) {
  15. final FieldType type = metadata.get(c).getType();

代码示例来源: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: org.apache.poi/poi

  1. /**
  2. * Finds a font that matches the one with the supplied attributes
  3. */
  4. @Override
  5. public HSSFFont findFont(boolean bold, short color, short fontHeight,
  6. String name, boolean italic, boolean strikeout,
  7. short typeOffset, byte underline)
  8. {
  9. int numberOfFonts = getNumberOfFontsAsInt();
  10. for (int i = 0; i <= numberOfFonts; i++) {
  11. // Remember - there is no 4!
  12. if(i == 4) {
  13. continue;
  14. }
  15. HSSFFont hssfFont = getFontAt(i);
  16. if (hssfFont.getBold() == bold
  17. && hssfFont.getColor() == color
  18. && hssfFont.getFontHeight() == fontHeight
  19. && hssfFont.getFontName().equals(name)
  20. && hssfFont.getItalic() == italic
  21. && hssfFont.getStrikeout() == strikeout
  22. && hssfFont.getTypeOffset() == typeOffset
  23. && hssfFont.getUnderline() == underline)
  24. {
  25. return hssfFont;
  26. }
  27. }
  28. return null;
  29. }

代码示例来源:origin: riotfamily/riot

  1. private void createHeadings(String... labels) {
  2. HSSFCellStyle style = wb.createCellStyle();
  3. HSSFFont font = wb.createFont();
  4. font.setFontName("Trebuchet MS");
  5. font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  6. style.setFont(font);
  7. HSSFRow row = sheet.createRow(0);
  8. int col = 0;
  9. for (String label : labels) {
  10. HSSFCell cell = row.createCell(col++);
  11. cell.setCellStyle(style);
  12. cell.setCellValue(new HSSFRichTextString(label));
  13. }
  14. }

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

  1. try (HSSFWorkbook wb = new HSSFWorkbook()) {
  2. HSSFSheet s = wb.createSheet();
  3. HSSFCellStyle cs = wb.createCellStyle();
  4. f.setFontHeightInPoints((short) 12);
  5. f.setColor((short) 0xA);
  6. f.setBold(true);
  7. f2.setFontHeightInPoints((short) 10);
  8. f2.setColor((short) 0xf);
  9. f2.setBold(true);
  10. cs.setFont(f);
  11. cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)"));
  12. cs2.setBorderBottom(BorderStyle.THIN);
  13. int rownum;
  14. for (rownum = 0; rownum < 300; rownum++) {
  15. HSSFRow r = s.createRow(rownum);
  16. if ((rownum % 2) == 0) {
  17. r.setHeight((short) 0x249);
  18. c = r.createCell(cellnum + 1);
  19. c.setCellValue(new HSSFRichTextString("TEST"));
  20. s.setColumnWidth(cellnum + 1, (int) (50 * 8 / 0.05));
  21. HSSFRow r = s.createRow(rownum);

代码示例来源:origin: org.tentackle/tentackle-swing

  1. HSSFWorkbook wb = new HSSFWorkbook();
  2. HSSFSheet sheet = wb.createSheet();
  3. HSSFRow row = sheet.createRow(srow);
  4. HSSFFont font = wb.createFont();
  5. font.setBold(true);
  6. HSSFCellStyle cs = wb.createCellStyle();
  7. cs.setAlignment(HorizontalAlignment.CENTER);
  8. cs.setFont(font);
  9. HSSFCell cell = row.createCell(0);
  10. cell.setCellStyle(cs);
  11. cell.setCellValue(new HSSFRichTextString(xTitle));
  12. sheet.addMergedRegion(new CellRangeAddress(0, srow, 0, cols - 1));
  13. srow++;
  14. cell.setCellStyle(cs);
  15. if (onlySelected) {
  16. if (xIntro == null) {
  17. font.setItalic(true);
  18. font.setBold(true);
  19. HSSFCell cell = row.createCell(c);

代码示例来源:origin: com.haulmont.yarg/yarg

  1. BandData bandData = dataObject.bandData;
  2. HSSFWorkbook resultWorkbook = resultCell.getSheet().getWorkbook();
  3. HSSFWorkbook templateWorkbook = templateCell.getSheet().getWorkbook();
  4. String templateCellValue = templateCell.getStringCellValue();
  5. HSSFCellStyle newStyle = resultWorkbook.createCellStyle();
  6. newStyle.setFillBackgroundColor(cellStyle.getFillBackgroundColor());
  7. newStyle.setFillForegroundColor(cellStyle.getFillForegroundColor());
  8. newStyle.setFillPattern(cellStyle.getFillPattern());
  9. newStyle.setVerticalAlignment(cellStyle.getVerticalAlignment());
  10. newFont = resultWorkbook.createFont();
  11. newFont.setFontName(cellFont.getFontName());
  12. newFont.setItalic(cellFont.getItalic());
  13. newFont.setStrikeout(cellFont.getStrikeout());
  14. newFont.setTypeOffset(cellFont.getTypeOffset());
  15. newFont.setBoldweight(cellFont.getBoldweight());
  16. newFont.setCharSet(cellFont.getCharSet());
  17. newFont.setColor(cellFont.getColor());
  18. newFont.setUnderline(cellFont.getUnderline());
  19. newFont.setFontHeight(cellFont.getFontHeight());
  20. newFont.setFontHeightInPoints(cellFont.getFontHeightInPoints());
  21. fontCache.addCachedFont(cellFont, newFont);

代码示例来源:origin: cuba-platform/yarg

  1. BandData bandData = dataObject.bandData;
  2. HSSFWorkbook resultWorkbook = resultCell.getSheet().getWorkbook();
  3. HSSFWorkbook templateWorkbook = templateCell.getSheet().getWorkbook();
  4. String templateCellValue = templateCell.getStringCellValue();
  5. HSSFCellStyle newStyle = resultWorkbook.createCellStyle();
  6. newStyle.setFillBackgroundColor(cellStyle.getFillBackgroundColor());
  7. newStyle.setFillForegroundColor(cellStyle.getFillForegroundColor());
  8. newStyle.setFillPattern(cellStyle.getFillPatternEnum());
  9. newStyle.setVerticalAlignment(cellStyle.getVerticalAlignmentEnum());
  10. newFont = resultWorkbook.createFont();
  11. newFont.setFontName(cellFont.getFontName());
  12. newFont.setItalic(cellFont.getItalic());
  13. newFont.setStrikeout(cellFont.getStrikeout());
  14. newFont.setTypeOffset(cellFont.getTypeOffset());
  15. newFont.setBold(cellFont.getBold());
  16. newFont.setCharSet(cellFont.getCharSet());
  17. newFont.setColor(cellFont.getColor());
  18. newFont.setUnderline(cellFont.getUnderline());
  19. newFont.setFontHeight(cellFont.getFontHeight());
  20. newFont.setFontHeightInPoints(cellFont.getFontHeightInPoints());
  21. fontCache.addCachedFont(cellFont, newFont);

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

  1. HSSFWorkbook wb = new HSSFWorkbook();
  2. HSSFSheet sheet = wb.createSheet("-");
  3. HSSFRow xlsRow = sheet.createRow(rowNum++);
  4. HSSFCellStyle headerStyle = wb.createCellStyle();
  5. headerStyle.setFillPattern(HSSFCellStyle.FINE_DOTS);
  6. headerStyle.setFillBackgroundColor(HSSFColor.BLUE_GREY.index);
  7. HSSFFont bold = wb.createFont();
  8. bold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  9. bold.setColor(HSSFColor.WHITE.index);
  10. headerStyle.setFont(bold);
  11. HSSFCell cell = xlsRow.createCell(colNum++);
  12. cell.setCellValue(new HSSFRichTextString(columnHeader));
  13. cell.setCellStyle(headerStyle);
  14. HSSFRow xlsRow = sheet.createRow(rowNum++);
  15. colNum = 0;
  16. HSSFCell cell = xlsRow.createCell(colNum++);
  17. while (colCount <= colNum)
  18. sheet.autoSizeColumn((short) colCount++);

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

  1. HSSFWorkbook wb = new HSSFWorkbook();
  2. FileOutputStream fileOut = new FileOutputStream(f);
  3. HSSFSheet sheet = wb.createSheet();
  4. HSSFRow headingsRow = sheet.createRow((short)0);
  5. HSSFFont headingFont = wb.createFont();
  6. headingFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  7. HSSFCellStyle headingStyle = wb.createCellStyle();
  8. headingStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
  9. headingStyle.setFont(headingFont);
  10. HSSFCell headingA = headingsRow.createCell((short)0);
  11. headingA.setCellValue("Heading");
  12. headingA.setCellStyle(headingStyle);
  13. HSSFRow row = sheet.createRow((short)i);
  14. HSSFCell cellRunway = row.createCell((short)0);
  15. cellRunway.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
  16. cellRunway.setCellValue("Whateva");
  17. cellRunway.setCellStyle(standardStyle);
  18. sheet.setColumnWidth((short)1, (short)4000);

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

  1. HSSFWorkbook workbook = new HSSFWorkbook();
  2. HSSFSheet sheet = workbook.createSheet();
  3. HSSFCellStyle style = workbook.createCellStyle();
  4. style.setBorderTop((short) 6); // double lines border
  5. style.setBorderBottom((short) 1); // single line border
  6. style.setFillBackgroundColor(HSSFColor.GREY_25_PERCENT.index);
  7. HSSFFont font = workbook.createFont();
  8. font.setFontName(HSSFFont.FONT_ARIAL);
  9. font.setFontHeightInPoints((short) 20);
  10. font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  11. font.setColor(HSSFColor.BLUE.index);
  12. HSSFRow row = sheet.createRow(1);
  13. HSSFCell cell = row.createCell(1);
  14. cell.setCellValue(new HSSFRichTextString("Doing some excel crazy stuff!"));
  15. sheet.autoSizeColumn((short) 1);

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

  1. public static void main(String[] args) throws IOException {
  2. try (HSSFWorkbook wb = new HSSFWorkbook()) {
  3. HSSFSheet sheet = wb.createSheet("new sheet");
  4. // Create a row and put some cells in it. Rows are 0 based.
  5. HSSFRow row = sheet.createRow(1);
  6. // Create a new font and alter it.
  7. HSSFFont font = wb.createFont();
  8. font.setFontHeightInPoints((short) 24);
  9. font.setFontName("Courier New");
  10. font.setItalic(true);
  11. font.setStrikeout(true);
  12. // Fonts are set into a style so create a new one to use.
  13. HSSFCellStyle style = wb.createCellStyle();
  14. style.setFont(font);
  15. // Create a cell and put a value in it.
  16. HSSFCell cell = row.createCell(1);
  17. cell.setCellValue("This is a test of fonts");
  18. cell.setCellStyle(style);
  19. // Write the output to a file
  20. try (FileOutputStream fileOut = new FileOutputStream("workbook.xls")) {
  21. wb.write(fileOut);
  22. }
  23. }
  24. }
  25. }

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

  1. public static void main(String[] args) throws IOException {
  2. try (HSSFWorkbook wb = new HSSFWorkbook()) {
  3. HSSFCreationHelper helper = wb.getCreationHelper();
  4. HSSFCellStyle hlink_style = wb.createCellStyle();
  5. HSSFFont hlink_font = wb.createFont();
  6. hlink_font.setUnderline(Font.U_SINGLE);
  7. hlink_font.setColor(HSSFColorPredefined.BLUE.getIndex());
  8. hlink_style.setFont(hlink_font);
  9. cell = sheet.createRow(0).createCell(0);
  10. cell.setCellValue("URL Link");
  11. HSSFHyperlink link = helper.createHyperlink(HyperlinkType.URL);
  12. link.setAddress("http://poi.apache.org/");
  13. cell.setHyperlink(link);
  14. cell.setCellStyle(hlink_style);
  15. cell = sheet.createRow(1).createCell(0);
  16. cell.setCellValue("File Link");
  17. link = helper.createHyperlink(HyperlinkType.FILE);
  18. cell = sheet.createRow(2).createCell(0);
  19. cell.setCellValue("Email Link");
  20. link = helper.createHyperlink(HyperlinkType.EMAIL);

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

  1. public static void main(String[] args) throws IOException {
  2. try (HSSFWorkbook wb = new HSSFWorkbook()) {
  3. HSSFSheet sheet1 = wb.createSheet("first sheet");
  4. HSSFSheet sheet2 = wb.createSheet("second sheet");
  5. HSSFSheet sheet3 = wb.createSheet("third sheet");
  6. HSSFFont boldFont = wb.createFont();
  7. boldFont.setFontHeightInPoints((short) 22);
  8. boldFont.setBold(true);
  9. HSSFCellStyle boldStyle = wb.createCellStyle();
  10. boldStyle.setFont(boldFont);
  11. HSSFRow row = sheet1.createRow(1);
  12. HSSFCell cell = row.createCell(0);
  13. cell.setCellValue("This quick brown fox");
  14. cell.setCellStyle(boldStyle);
  15. sheet1.setRepeatingColumns(CellRangeAddress.valueOf("A:C"));
  16. sheet2.setRepeatingRows(CellRangeAddress.valueOf("1:3"));

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

  1. wb.setSheetName(0, this.getCustomer().getClass().getSimpleName());
  2. HSSFSheet sheet = wb.getSheetAt(0);
  3. sheet.setColumnWidth(0, 1500);
  4. sheet.setColumnWidth(1, 4500);
  5. sheet.setColumnWidth(2, 6500);
  6. HSSFCellStyle styleHeader = (HSSFCellStyle) wb.createCellStyle();
  7. styleHeader.setAlignment(HSSFCellStyle.ALIGN_CENTER);
  8. HSSFFont fontHeader = (HSSFFont) wb.createFont();
  9. fontHeader.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  10. fontHeader.setColor(HSSFColor.WHITE.index);
  11. styleHeader.setFillForegroundColor(HSSFColor.DARK_BLUE.index);
  12. styleHeader.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
  13. HSSFCell indice = rowUser0.createCell((short) 0);
  14. indice.setCellValue("N°");
  15. indice.setCellStyle(styleHeader);
  16. HSSFCell hnro = rowUser0.createCell((short) nro);
  17. hnro.setCellValue(column.getDescripcion());
  18. fontCellWhite.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
  19. for (int i=0; i<row.getPhysicalNumberOfCells(); i++) {

代码示例来源:origin: org.onap.portal.sdk/epsdk-analytics

  1. HtmlStripper strip = new HtmlStripper();
  2. HSSFCellStyle styleName = wb.createCellStyle();
  3. styleName.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
  4. styleName.setAlignment(HSSFCellStyle.ALIGN_CENTER);
  5. styleName.setBorderBottom(HSSFCellStyle.BORDER_THIN);
  6. HSSFFont font = wb.createFont();
  7. font.setFontHeight((short) (font_size / 0.05));
  8. font.setFontName("Tahoma");
  9. font.setColor(HSSFColor.BLACK.index);
  10. font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  11. HSSFFont fontDefault = wb.createFont();
  12. fontDefault.setColor((short) HSSFFont.COLOR_NORMAL);
  13. fontDefault.setFontHeight((short) (font_size / 0.05));
  14. fontDefault.setFontName("Tahoma");
  15. fontDefault.setItalic(true);
  16. fontDescr.setFontHeight((short) (font_size / 0.05)); //14
  17. fontDescr.setFontName("Tahoma");
  18. fontDescr.setColor(HSSFColor.BLACK.index);
  19. fontDescr.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  20. cellNum = 0;

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

  1. HSSFWorkbook wb = new HSSFWorkbook();
  2. HSSFSheet sheet = wb.createSheet("New sheet");
  3. HSSFFont font = wb.createFont();
  4. font.setFontName("Arial Unicode MS");
  5. HSSFCellStyle style = wb.createCellStyle();
  6. style.setFont(font);
  7. HSSFRow row = sheet.createRow((short) 0);
  8. HSSFCell cell = row.createCell((short) 0);
  9. cell.setEncoding(HSSFCell.ENCODING_UTF_16);
  10. cell.setCellStyle(style);
  11. cell.setCellValue("\u53f8");

代码示例来源: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. HSSFWorkbook wb = new HSSFWorkbook();
  2. HSSFSheet sheet = wb.createSheet("FirstSheet");
  3. HSSFRow rowhead = sheet.createRow(0);
  4. HSSFCellStyle style = wb.createCellStyle();
  5. HSSFFont font = wb.createFont();
  6. font.setFontName(HSSFFont.FONT_ARIAL);
  7. font.setFontHeightInPoints((short)10);
  8. font.setBold(true);
  9. style.setFont(font);
  10. rowhead.createCell(0).setCellValue("ID");
  11. rowhead.createCell(1).setCellValue("First");
  12. rowhead.createCell(2).setCellValue("Second");
  13. rowhead.createCell(3).setCellValue("Third");
  14. for(int j = 0; j<=3; j++)
  15. rowhead.getCell(j).setCellStyle(style);

相关文章