java POI 3.17 粗体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46485529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 09:14:28  来源:igfitidea点击:

POI 3.17 bold font

javaexcelapache-poi

提问by beppecosta

I'm upgrading from POI 3.15 to 3.17

我正在从 POI 3.15 升级到 3.17

This code does not compile:

此代码无法编译:

HSSFFont fontTitle = wb.createFont();
fontTitle.setFontHeightInPoints((short) 12);
fontTitle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

I've changed to:

我已经改为:

Font fontTitle = wb.createFont();
fontTitle.setFontHeightInPoints((short) 12);
fontTitle.setBoldweight(Font.BOLDWEIGHT_BOLD);

but still in error:

但仍然错误:

/excel/SQL2XLSX17N.java:271: cannot find symbol               
symbol  : variable BOLDWEIGHT_BOLD                            
location: interface org.apache.poi.ss.usermodel.Font          
               fontTitle.setBoldweight(Font.BOLDWEIGHT_BOLD); 

How do I use a bold font?

如何使用粗体?

回答by Stephen Kennedy

Use Font.setBold(true)to embolden.

使用Font.setBold(true)壮胆。

Signature:

签名

void setBold(boolean bold)

回答by Yaroslav Fedorov

Just for history:

只为历史:

OLD: f.setBoldweight(Font.BOLDWEIGHT_NORMAL);NEW: f.setBold(false);

旧: f.setBoldweight(Font.BOLDWEIGHT_NORMAL);新: f.setBold(false);

OLD: fb.setBoldweight(Font.BOLDWEIGHT_BOLD);NEW: fb.setBold(true);

旧:fb.setBoldweight(Font.BOLDWEIGHT_BOLD);新:fb.setBold(true);

/**
 * sets the font to be bold or not
 */
public void setBold(boolean bold) {
    if (bold)
        font.setBoldWeight(BOLDWEIGHT_BOLD);
    else
        font.setBoldWeight(BOLDWEIGHT_NORMAL);
}