本文整理了Java中org.apache.poi.ss.usermodel.CellStyle.setFont()
方法的一些代码示例,展示了CellStyle.setFont()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CellStyle.setFont()
方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.CellStyle
类名称:CellStyle
方法名:setFont
[英]set the font for this style
[中]设置此样式的字体
代码示例来源:origin: looly/hutool
/**
* 设置全局字体
*
* @param font 字体,可以通过{@link StyleUtil#createFont(Workbook, short, short, String)}创建
* @param ignoreHead 是否跳过头部样式
* @return this
* @since 4.1.0
*/
public StyleSet setFont(Font font, boolean ignoreHead) {
if(false == ignoreHead) {
this.headCellStyle.setFont(font);
}
this.cellStyle.setFont(font);
this.cellStyleForNumber.setFont(font);
this.cellStyleForDate.setFont(font);
return this;
}
}
代码示例来源:origin: looly/hutool
/**
* 设置全局字体
*
* @param font 字体,可以通过{@link StyleUtil#createFont(Workbook, short, short, String)}创建
* @param ignoreHead 是否跳过头部样式
* @return this
* @since 4.1.0
*/
public StyleSet setFont(Font font, boolean ignoreHead) {
if(false == ignoreHead) {
this.headCellStyle.setFont(font);
}
this.cellStyle.setFont(font);
this.cellStyleForNumber.setFont(font);
this.cellStyleForDate.setFont(font);
return this;
}
}
代码示例来源:origin: stackoverflow.com
CellStyle style = wb.createCellStyle();
Font font = wb.createFont();
font.setColor(HSSFColor.BLACK.index);
style.setFont(font);
// Set more colours on the style as needed
// Set formatting rules on the style as needed
代码示例来源:origin: primefaces/primefaces
cellStyle.setFont(cellFont);
代码示例来源:origin: primefaces/primefaces
facetStyle.setFont(facetFont);
代码示例来源:origin: primefaces/primefaces
cellStyle.setFont(cellFont);
代码示例来源:origin: wuyouzhuguli/FEBS-Shiro
CellStyle style = wb.createCellStyle();
Font font = wb.createFont();
style.setFont(font);
代码示例来源:origin: primefaces/primefaces
facetStyle.setFont(facetFont);
代码示例来源:origin: alibaba/easyexcel
/**
*
* @param workbook
* @param f
* @param indexedColors
* @return
*/
public static CellStyle buildCellStyle(Workbook workbook, com.alibaba.excel.metadata.Font f,
IndexedColors indexedColors) {
CellStyle cellStyle = buildDefaultCellStyle(workbook);
if (f != null) {
Font font = workbook.createFont();
font.setFontName(f.getFontName());
font.setFontHeightInPoints(f.getFontHeightInPoints());
font.setBold(f.isBold());
cellStyle.setFont(font);
}
if (indexedColors != null) {
cellStyle.setFillForegroundColor(indexedColors.getIndex());
}
return cellStyle;
}
代码示例来源:origin: stackoverflow.com
Workbook wb = new XSSFWorkbook("myWorkbook.xlsx");
Row row=sheet.getRow(0);
CellStyle style=null;
XSSFFont defaultFont= wb.createFont();
defaultFont.setFontHeightInPoints((short)10);
defaultFont.setFontName("Arial");
defaultFont.setColor(IndexedColors.BLACK.getIndex());
defaultFont.setBold(false);
defaultFont.setItalic(false);
XSSFFont font= wb.createFont();
font.setFontHeightInPoints((short)10);
font.setFontName("Arial");
font.setColor(IndexedColors.WHITE.getIndex());
font.setBold(true);
font.setItalic(false);
style=row.getRowStyle();
style.setFillBackgroundColor(IndexedColors.DARK_BLUE.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setFont(font);
代码示例来源:origin: alibaba/easyexcel
/**
*
* @param workbook
* @return
*/
public static CellStyle buildDefaultCellStyle(Workbook workbook) {
CellStyle newCellStyle = workbook.createCellStyle();
Font font = workbook.createFont();
font.setFontName("宋体");
font.setFontHeightInPoints((short)14);
font.setBold(true);
newCellStyle.setFont(font);
newCellStyle.setWrapText(true);
newCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
newCellStyle.setAlignment(HorizontalAlignment.CENTER);
newCellStyle.setLocked(true);
newCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
newCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
newCellStyle.setBorderBottom(BorderStyle.THIN);
newCellStyle.setBorderLeft(BorderStyle.THIN);
return newCellStyle;
}
代码示例来源:origin: wuyouzhuguli/FEBS-Shiro
@Override
public CellStyle headCellStyle(SXSSFWorkbook wb) {
CellStyle cellStyle = wb.createCellStyle();
Font font = wb.createFont();
cellStyle.setFillForegroundColor((short) 12);
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);// 填充模式
cellStyle.setBorderTop(CellStyle.BORDER_THIN);// 上边框为细边框
cellStyle.setBorderRight(CellStyle.BORDER_THIN);// 右边框为细边框
cellStyle.setBorderBottom(CellStyle.BORDER_THIN);// 下边框为细边框
cellStyle.setBorderLeft(CellStyle.BORDER_THIN);// 左边框为细边框
cellStyle.setAlignment(CellStyle.ALIGN_LEFT);// 对齐
cellStyle.setFillForegroundColor(HSSFColor.GREEN.index);
cellStyle.setFillBackgroundColor(HSSFColor.GREEN.index);
font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
// font.setFontHeightInPoints((short) 12);// 字体大小
font.setColor(HSSFColor.WHITE.index);
// 应用标题字体到标题样式
cellStyle.setFont(font);
return cellStyle;
}
代码示例来源:origin: stackoverflow.com
Sheet sheet = wb.createSheet("test");
CellStyle cs = wb.createCellStyle();
Font f = wb.createFont();
f.setBoldweight(Font.BOLDWEIGHT_BOLD);
cs.setFont(f);
sheet.setDefaultColumnStyle(1,cs); //set bold for column 1
代码示例来源:origin: pentaho/pentaho-kettle
hlink_font.setColor( IndexedColors.BLUE.getIndex() );
CellStyle style = cell.getCellStyle();
style.setFont( hlink_font );
cell.setCellStyle( style );
data.cacheLinkStyle( fieldNr, cell.getCellStyle() );
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) {
Path myFile = Paths.get(System.getProperty("user.home"), "Desktop", "tester.xlsx");
try {
XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(myFile.toFile()));
XSSFSheet sheet = wb.getSheetAt(0);
makeRowBold(wb, sheet.getRow(0));
wb.write(new FileOutputStream(myFile.toFile()));
} catch (IOException e) {
e.printStackTrace();
}
}
public static void makeRowBold(Workbook wb, Row row){
CellStyle style = wb.createCellStyle();//Create style
Font font = wb.createFont();//Create font
font.setBoldweight(Font.BOLDWEIGHT_BOLD);//Make font bold
style.setFont(font);//set it to bold
for(int i = 0; i < row.getLastCellNum(); i++){//For each cell in the row
row.getCell(i).setCellStyle(style);//Set the sty;e
}
}
代码示例来源:origin: stackoverflow.com
public static void makeRowBold(Workbook wb, Row row){
CellStyle style = wb.createCellStyle();//Create style
Font font = wb.createFont();//Create font
font.setBoldweight(Font.BOLDWEIGHT_BOLD);//Make font bold
style.setFont(font);//set it to bold
for(int i = 0; i < row.getLastCellNum(); i++){//For each cell in the row
row.getCell(i).setCellStyle(style);//Set the style
}
}
代码示例来源:origin: org.apache.poi/poi
/**
* Sets the format properties of the given style based on the given map.
*
* @param style cell style
* @param workbook parent workbook
* @param properties map of format properties (String -> Object)
* @see #getFormatProperties(CellStyle)
*/
private static void setFormatProperties(CellStyle style, Workbook workbook, Map<String, Object> properties) {
style.setAlignment(getHorizontalAlignment(properties, ALIGNMENT));
style.setVerticalAlignment(getVerticalAlignment(properties, VERTICAL_ALIGNMENT));
style.setBorderBottom(getBorderStyle(properties, BORDER_BOTTOM));
style.setBorderLeft(getBorderStyle(properties, BORDER_LEFT));
style.setBorderRight(getBorderStyle(properties, BORDER_RIGHT));
style.setBorderTop(getBorderStyle(properties, BORDER_TOP));
style.setBottomBorderColor(getShort(properties, BOTTOM_BORDER_COLOR));
style.setDataFormat(getShort(properties, DATA_FORMAT));
style.setFillPattern(getFillPattern(properties, FILL_PATTERN));
style.setFillForegroundColor(getShort(properties, FILL_FOREGROUND_COLOR));
style.setFillBackgroundColor(getShort(properties, FILL_BACKGROUND_COLOR));
style.setFont(workbook.getFontAt(getInt(properties, FONT)));
style.setHidden(getBoolean(properties, HIDDEN));
style.setIndention(getShort(properties, INDENTION));
style.setLeftBorderColor(getShort(properties, LEFT_BORDER_COLOR));
style.setLocked(getBoolean(properties, LOCKED));
style.setRightBorderColor(getShort(properties, RIGHT_BORDER_COLOR));
style.setRotation(getShort(properties, ROTATION));
style.setTopBorderColor(getShort(properties, TOP_BORDER_COLOR));
style.setWrapText(getBoolean(properties, WRAP_TEXT));
}
代码示例来源:origin: apache/tika
@Override
public void reset(XSSFWorkbook workbook) {
this.workbook = workbook;
style = workbook.createCellStyle();
Font hlinkFont = workbook.createFont();
hlinkFont.setUnderline(Font.U_SINGLE);
hlinkFont.setColor(IndexedColors.BLUE.getIndex());
style.setFont(hlinkFont);
links = 0;
}
代码示例来源:origin: stackoverflow.com
private static Map<String, CellStyle> styles;
private static Map<String, CellStyle> createStyles(Workbook wb){
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
DataFormat df = wb.createDataFormat();
CellStyle style;
Font headerFont = wb.createFont();
headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
headerFont.setFontHeightInPoints((short) 12);
style = createBorderedStyle(wb);
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setFont(headerFont);
styles.put("style1", style);
style = createBorderedStyle(wb);
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
style.setFont(headerFont);
style.setDataFormat(df.getFormat("d-mmm"));
styles.put("date_style", style);
...
return styles;
}
代码示例来源:origin: cn.afterturn/easypoi-base
@Override
public CellStyle getHeaderStyle(short headerColor) {
CellStyle titleStyle = workbook.createCellStyle();
Font font = workbook.createFont();
font.setFontHeightInPoints((short) 24);
titleStyle.setFont(font);
titleStyle.setFillForegroundColor(headerColor);
titleStyle.setAlignment(HorizontalAlignment.CENTER);
titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
return titleStyle;
}
内容来源于网络,如有侵权,请联系作者删除!