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

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

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

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFRow row = sheet.createRow((short) 0);
HSSFCell cell = row.createCell((short) 0);
cell.setCellValue("Default Palette");
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);
cell.setCellValue("Modified Palette");

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

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

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

/**
 * Finds a font that matches the one with the supplied attributes
 */
@Override
public HSSFFont findFont(boolean bold, short color, short fontHeight,
             String name, boolean italic, boolean strikeout,
             short typeOffset, byte underline)
{
  int numberOfFonts = getNumberOfFontsAsInt();
  for (int i = 0; i <= numberOfFonts; i++) {
    // Remember - there is no 4!
    if(i == 4) {
      continue;
    }
    HSSFFont hssfFont = getFontAt(i);
    if (hssfFont.getBold() == bold
        && hssfFont.getColor() == color
        && hssfFont.getFontHeight() == fontHeight
        && hssfFont.getFontName().equals(name)
        && hssfFont.getItalic() == italic
        && hssfFont.getStrikeout() == strikeout
        && hssfFont.getTypeOffset() == typeOffset
        && hssfFont.getUnderline() == underline)
    {
      return hssfFont;
    }
  }
  return null;
}

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

private void createHeadings(String... labels) {
  HSSFCellStyle style = wb.createCellStyle();
  HSSFFont font = wb.createFont();
  font.setFontName("Trebuchet MS");
  font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  style.setFont(font);
  
  HSSFRow row = sheet.createRow(0);
  int col = 0;
  for (String label : labels) {
     HSSFCell cell = row.createCell(col++);
     cell.setCellStyle(style);
     cell.setCellValue(new HSSFRichTextString(label));
  }
}

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

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

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

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
 HSSFRow row = sheet.createRow(srow);
 HSSFFont font = wb.createFont();
 font.setBold(true);
 HSSFCellStyle cs = wb.createCellStyle();
 cs.setAlignment(HorizontalAlignment.CENTER);
 cs.setFont(font);
 HSSFCell cell = row.createCell(0);
 cell.setCellStyle(cs);
 cell.setCellValue(new HSSFRichTextString(xTitle));
 sheet.addMergedRegion(new CellRangeAddress(0, srow, 0, cols - 1));
 srow++;
 cell.setCellStyle(cs);
 if (onlySelected) {
  if (xIntro == null) {
font.setItalic(true);
font.setBold(true);
 HSSFCell cell = row.createCell(c);

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

BandData bandData = dataObject.bandData;
HSSFWorkbook resultWorkbook = resultCell.getSheet().getWorkbook();
HSSFWorkbook templateWorkbook = templateCell.getSheet().getWorkbook();
String templateCellValue = templateCell.getStringCellValue();
    HSSFCellStyle newStyle = resultWorkbook.createCellStyle();
    newStyle.setFillBackgroundColor(cellStyle.getFillBackgroundColor());
    newStyle.setFillForegroundColor(cellStyle.getFillForegroundColor());
    newStyle.setFillPattern(cellStyle.getFillPattern());
    newStyle.setVerticalAlignment(cellStyle.getVerticalAlignment());
      newFont = resultWorkbook.createFont();
      newFont.setFontName(cellFont.getFontName());
      newFont.setItalic(cellFont.getItalic());
      newFont.setStrikeout(cellFont.getStrikeout());
      newFont.setTypeOffset(cellFont.getTypeOffset());
      newFont.setBoldweight(cellFont.getBoldweight());
      newFont.setCharSet(cellFont.getCharSet());
      newFont.setColor(cellFont.getColor());
      newFont.setUnderline(cellFont.getUnderline());
      newFont.setFontHeight(cellFont.getFontHeight());
      newFont.setFontHeightInPoints(cellFont.getFontHeightInPoints());
      fontCache.addCachedFont(cellFont, newFont);

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

BandData bandData = dataObject.bandData;
HSSFWorkbook resultWorkbook = resultCell.getSheet().getWorkbook();
HSSFWorkbook templateWorkbook = templateCell.getSheet().getWorkbook();
String templateCellValue = templateCell.getStringCellValue();
    HSSFCellStyle newStyle = resultWorkbook.createCellStyle();
    newStyle.setFillBackgroundColor(cellStyle.getFillBackgroundColor());
    newStyle.setFillForegroundColor(cellStyle.getFillForegroundColor());
    newStyle.setFillPattern(cellStyle.getFillPatternEnum());
    newStyle.setVerticalAlignment(cellStyle.getVerticalAlignmentEnum());
      newFont = resultWorkbook.createFont();
      newFont.setFontName(cellFont.getFontName());
      newFont.setItalic(cellFont.getItalic());
      newFont.setStrikeout(cellFont.getStrikeout());
      newFont.setTypeOffset(cellFont.getTypeOffset());
      newFont.setBold(cellFont.getBold());
      newFont.setCharSet(cellFont.getCharSet());
      newFont.setColor(cellFont.getColor());
      newFont.setUnderline(cellFont.getUnderline());
      newFont.setFontHeight(cellFont.getFontHeight());
      newFont.setFontHeightInPoints(cellFont.getFontHeightInPoints());
      fontCache.addCachedFont(cellFont, newFont);

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

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("-");
  HSSFRow xlsRow = sheet.createRow(rowNum++);
  HSSFCellStyle headerStyle = wb.createCellStyle();
  headerStyle.setFillPattern(HSSFCellStyle.FINE_DOTS);
  headerStyle.setFillBackgroundColor(HSSFColor.BLUE_GREY.index);
  HSSFFont bold = wb.createFont();
  bold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
  bold.setColor(HSSFColor.WHITE.index);
  headerStyle.setFont(bold);
    HSSFCell cell = xlsRow.createCell(colNum++);
    cell.setCellValue(new HSSFRichTextString(columnHeader));
    cell.setCellStyle(headerStyle);
  HSSFRow xlsRow = sheet.createRow(rowNum++);
  colNum = 0;
    HSSFCell cell = xlsRow.createCell(colNum++);
while (colCount <= colNum)
  sheet.autoSizeColumn((short) colCount++);

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

HSSFWorkbook wb = new HSSFWorkbook();
FileOutputStream fileOut = new FileOutputStream(f);
HSSFSheet sheet = wb.createSheet();
HSSFRow headingsRow  = sheet.createRow((short)0); 
HSSFFont headingFont = wb.createFont();
headingFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
HSSFCellStyle headingStyle = wb.createCellStyle();
headingStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
headingStyle.setFont(headingFont);
HSSFCell headingA = headingsRow.createCell((short)0);
headingA.setCellValue("Heading");
headingA.setCellStyle(headingStyle);
  HSSFRow row  = sheet.createRow((short)i); 
  HSSFCell cellRunway = row.createCell((short)0);
  cellRunway.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
  cellRunway.setCellValue("Whateva");             
  cellRunway.setCellStyle(standardStyle);
sheet.setColumnWidth((short)1, (short)4000);

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

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

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

public static void main(String[] args) throws IOException {
    try (HSSFWorkbook wb = new HSSFWorkbook()) {
      HSSFSheet sheet = wb.createSheet("new sheet");

      // Create a row and put some cells in it. Rows are 0 based.
      HSSFRow row = sheet.createRow(1);

      // Create a new font and alter it.
      HSSFFont font = wb.createFont();
      font.setFontHeightInPoints((short) 24);
      font.setFontName("Courier New");
      font.setItalic(true);
      font.setStrikeout(true);

      // Fonts are set into a style so create a new one to use.
      HSSFCellStyle style = wb.createCellStyle();
      style.setFont(font);

      // Create a cell and put a value in it.
      HSSFCell cell = row.createCell(1);
      cell.setCellValue("This is a test of fonts");
      cell.setCellStyle(style);

      // Write the output to a file
      try (FileOutputStream fileOut = new FileOutputStream("workbook.xls")) {
        wb.write(fileOut);
      }
    }
  }
}

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

public static void main(String[] args) throws IOException  {
  try (HSSFWorkbook wb = new HSSFWorkbook()) {
    HSSFCreationHelper helper = wb.getCreationHelper();
    HSSFCellStyle hlink_style = wb.createCellStyle();
    HSSFFont hlink_font = wb.createFont();
    hlink_font.setUnderline(Font.U_SINGLE);
    hlink_font.setColor(HSSFColorPredefined.BLUE.getIndex());
    hlink_style.setFont(hlink_font);
    cell = sheet.createRow(0).createCell(0);
    cell.setCellValue("URL Link");
    HSSFHyperlink link = helper.createHyperlink(HyperlinkType.URL);
    link.setAddress("http://poi.apache.org/");
    cell.setHyperlink(link);
    cell.setCellStyle(hlink_style);
    cell = sheet.createRow(1).createCell(0);
    cell.setCellValue("File Link");
    link = helper.createHyperlink(HyperlinkType.FILE);
    cell = sheet.createRow(2).createCell(0);
    cell.setCellValue("Email Link");
    link = helper.createHyperlink(HyperlinkType.EMAIL);

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

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

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

wb.setSheetName(0, this.getCustomer().getClass().getSimpleName());
HSSFSheet sheet = wb.getSheetAt(0);
sheet.setColumnWidth(0, 1500);
sheet.setColumnWidth(1, 4500);
sheet.setColumnWidth(2, 6500);
HSSFCellStyle styleHeader = (HSSFCellStyle) wb.createCellStyle();
styleHeader.setAlignment(HSSFCellStyle.ALIGN_CENTER);
HSSFFont fontHeader = (HSSFFont) wb.createFont();
fontHeader.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
fontHeader.setColor(HSSFColor.WHITE.index);
styleHeader.setFillForegroundColor(HSSFColor.DARK_BLUE.index);          
styleHeader.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);         
HSSFCell indice = rowUser0.createCell((short) 0);
indice.setCellValue("N°");
indice.setCellStyle(styleHeader);
  HSSFCell hnro   = rowUser0.createCell((short) nro);
  hnro.setCellValue(column.getDescripcion());
fontCellWhite.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
  for (int i=0; i<row.getPhysicalNumberOfCells(); i++) {

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

HtmlStripper strip = new HtmlStripper();
HSSFCellStyle styleName = wb.createCellStyle();
styleName.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
styleName.setAlignment(HSSFCellStyle.ALIGN_CENTER);
styleName.setBorderBottom(HSSFCellStyle.BORDER_THIN);
HSSFFont font = wb.createFont();
font.setFontHeight((short) (font_size / 0.05));
font.setFontName("Tahoma");
font.setColor(HSSFColor.BLACK.index);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
HSSFFont fontDefault = wb.createFont();
fontDefault.setColor((short) HSSFFont.COLOR_NORMAL);
fontDefault.setFontHeight((short) (font_size / 0.05));
fontDefault.setFontName("Tahoma");
fontDefault.setItalic(true);
fontDescr.setFontHeight((short) (font_size / 0.05)); //14
fontDescr.setFontName("Tahoma");
fontDescr.setColor(HSSFColor.BLACK.index);
fontDescr.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        cellNum = 0;

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

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("New sheet");
HSSFFont font = wb.createFont();
font.setFontName("Arial Unicode MS");
HSSFCellStyle style = wb.createCellStyle();
style.setFont(font);
HSSFRow row = sheet.createRow((short) 0);
HSSFCell cell = row.createCell((short) 0);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellStyle(style);
cell.setCellValue("\u53f8");

代码示例来源: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

HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("FirstSheet");
HSSFRow rowhead = sheet.createRow(0); 
HSSFCellStyle style = wb.createCellStyle();
HSSFFont font = wb.createFont();
font.setFontName(HSSFFont.FONT_ARIAL);
font.setFontHeightInPoints((short)10);
font.setBold(true);
style.setFont(font);
rowhead.createCell(0).setCellValue("ID");
rowhead.createCell(1).setCellValue("First");
rowhead.createCell(2).setCellValue("Second");
rowhead.createCell(3).setCellValue("Third");
for(int j = 0; j<=3; j++)
rowhead.getCell(j).setCellStyle(style);

相关文章