本文整理汇总了Java中org.apache.poi.xssf.usermodel.XSSFCellStyle.setFont方法的典型用法代码示例。如果您正苦于以下问题:Java XSSFCellStyle.setFont方法的具体用法?Java XSSFCellStyle.setFont怎么用?Java XSSFCellStyle.setFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.xssf.usermodel.XSSFCellStyle
的用法示例。
在下文中一共展示了XSSFCellStyle.setFont方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCellStyle
import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
/**
* Fixed all properties suitable for cell-related style.
*
* @param workbook Excel Workbook
* @param boardStyle all properties suitable on the style of a cell
* @param font a font
* @return the customized style
*/
protected static CellStyle getCellStyle(Workbook workbook, TableStyle boardStyle, Font font) {
XSSFCellStyle cellStyle = (XSSFCellStyle) workbook.createCellStyle();
if (boardStyle.getFillColor() != null) {
cellStyle.setFillForegroundColor(boardStyle.getFillColor());
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
}
cellStyle.setBorderLeft(boardStyle.getCellBorderLeft());
cellStyle.setBorderRight(boardStyle.getCellBorderRight());
cellStyle.setBorderTop(boardStyle.getCellBorderTop());
cellStyle.setBorderBottom(boardStyle.getCellBorderBottom());
cellStyle.setAlignment(boardStyle.getAlignment());
cellStyle.setBorderColor(BorderSide.LEFT, boardStyle.getBorderColor());
cellStyle.setBorderColor(BorderSide.RIGHT, boardStyle.getBorderColor());
cellStyle.setBorderColor(BorderSide.TOP, boardStyle.getBorderColor());
cellStyle.setBorderColor(BorderSide.BOTTOM, boardStyle.getBorderColor());
if (font != null) {
cellStyle.setFont(font);
}
return cellStyle;
}
示例2: createTitle
import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
protected void createTitle() {
short lineThickness = (short) (6 * BASE_HEIGHT);
// Top Line
Row row = sheet.createRow(ROW_4);
row.setHeight(lineThickness);
XSSFCellStyle style = wb.createCellStyle();
style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
setDummyTitleStyle(row,style);
// Title
row = sheet.createRow(ROW_5);
row.setHeightInPoints(100);
sheet.addMergedRegion(CellRangeAddress.valueOf("B5:G5"));
Font font = wb.createFont();
font.setFontHeightInPoints((short)28);
font.setFontName("Trebuchet MS");
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
style = wb.createCellStyle();
style.setFont(font);
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
setDummyTitleStyle(row,style);
row.getCell(COL_B).setCellValue("Open Source License Verification Report");
// Bottom Line
row = sheet.createRow(ROW_6);
row.setHeight(lineThickness);
style = wb.createCellStyle();
style.setFillForegroundColor(DARK_BLUE);
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
setDummyTitleStyle(row,style);
}
示例3: getCellStyle
import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
/**
* @param color
* @param font
* @return CellStyle
*/
protected XSSFCellStyle getCellStyle(XSSFColor color, Font font) {
XSSFCellStyle style = wb.createCellStyle();
style.setFillForegroundColor(color);
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setWrapText(true); // new line
style.setBorderBottom(CellStyle.BORDER_THIN);
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderLeft(CellStyle.BORDER_THIN);
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderRight(CellStyle.BORDER_THIN);
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderTop(CellStyle.BORDER_THIN);
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
if(font != null) style.setFont(font);
return style;
}
示例4: styleHeader
import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
/**
* See http://thinktibits.blogspot.co.uk/2012/12/Java-POI-XLS-XLSX-Change-Cell-Font-Color-Example.html
* Currently only for xlsx
* @param wb
* @param sheet
*/
private static void styleHeader(Workbook wb, Sheet sheet){
if(XSSFWorkbook.class.isInstance(wb) && XSSFSheet.class.isInstance(sheet)){
XSSFWorkbook my_workbook = (XSSFWorkbook)wb;
XSSFCellStyle my_style = my_workbook.createCellStyle();
XSSFFont my_font=my_workbook.createFont();
my_font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
my_style.setFont(my_font);
Row row = sheet.getRow(0);
if(row!=null && row.getFirstCellNum()>=0){
for(int i = row.getFirstCellNum() ; i<= row.getLastCellNum();i++){
Cell cell = row.getCell(i);
if(cell!=null){
cell.setCellStyle(my_style);
}
}
}
}
}
示例5: createSheetRow
import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
/**
* Creates a new line with values in the sheet.
*
* @param workbook
* (XSSFWorkbook, required) workbook to create the row in
* @param sheetRow
* (XSSFSheetRow, required) sheet to create the data row in
* @param sheetName
* (String, required) name of the sheet
* @param values
* (String [], optional) if null or empty no work will be done, else the values written to the next line
* @param bold
* (boolean) true: the values will be set in bold font face, else normal
*
* @since 2.0.10
*/
private void createSheetRow(XSSFWorkbook workbook, XSSFSheetRow sheetRow, String sheetName, List<String> values,
boolean bold)
{
if (null != values && values.size() > 0)
{
// check if sheet exists and create if not
if (null == sheetRow.sheet)
{
sheetRow.sheet = workbook.createSheet(sheetName);
}
// create cell style
XSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setAlignment(HorizontalAlignment.CENTER);
if (bold)
{
// Create bold font
Font fontBold = workbook.createFont();
fontBold.setBoldweight(Font.BOLDWEIGHT_BOLD);
cellStyle.setFont(fontBold);
}
// create row
XSSFRow row = sheetRow.sheet.createRow(sheetRow.rowCount++);
// set values
for (int i = 0; i < values.size(); i++)
{
row.getCell(i).setCellValue(values.get(i));
row.getCell(i).setCellStyle(cellStyle);
}
}
}
示例6: setCell
import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
/**
* @param sheet
* @param pos 位置【row,col】
* @param style
* @param v
*/
public static void setCell(final XSSFWorkbook wb,final XSSFSheet sheet,int[] pos,CellStyle style,FontStyle font,String v){
XSSFRow row = sheet.getRow(pos[0]);
XSSFCell cell = CellValueUtil.createCellIfNotPresent(row, pos[1]);
XSSFCellStyle _style = Objects
.requireNonNull(new XSSFCellStyleLib(wb).get(style),
"specified style not defined!");
XSSFFont _font = Objects
.requireNonNull(new XSSFFontStyleLib(wb).get(font),
"specified font not defined!");
_style.setFont(_font);
setCellProperties(cell, v, _style);
}
示例7: getCaptionCellStyle
import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
/**
* 返回副标题字体样式
* @param wb
* @return
*/
public static XSSFCellStyle getCaptionCellStyle(XSSFWorkbook wb){
//default cellStyle
XSSFCellStyle cellStyle=createXSSFCellStyle(wb);
//default font
XSSFFont cellfont=XSSFontUtil.createXSSFFont(wb);
cellStyle.setFont(cellfont);
return cellStyle;
}
示例8: getcontentCellStyle
import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
/**
* 返回excel内容字体样式
* @param wb
* @return
*/
public static XSSFCellStyle getcontentCellStyle(XSSFWorkbook wb){
String message="XSSFWorkbook must not be null!";
Objects.requireNonNull(wb, () -> message);
XSSFCellStyle contentStyle=createCenterXSSFCellStyle(wb);
//fill enlarged font
XSSFFont enlargedFont=XSSFontUtil.createColorXSSFFont(wb, "新宋体", (short) 16, new XSSFColor(Color.WHITE), true);
contentStyle.setFont(enlargedFont);
return contentStyle;
}
示例9: createCellStyle
import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
private static XSSFCellStyle createCellStyle(Workbook workbook) {
XSSFCellStyle xstyle = (XSSFCellStyle) workbook.createCellStyle();
XSSFFont font = (XSSFFont) workbook.createFont();
font.setFontHeightInPoints((short) 11);
xstyle.setFont(font);
return xstyle;
}
示例10: createXSSFCellStyle
import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
private XSSFCellStyle createXSSFCellStyle(Workbook wb, int[] bgColor, int[] fontColor, int fontSize) {
SXSSFWorkbook workbook = (SXSSFWorkbook) wb;
XSSFFont titleFont = (XSSFFont) workbook.createFont();
titleFont.setCharSet(HSSFFont.DEFAULT_CHARSET);
titleFont.setFontName("宋体");
XSSFColor color9 = new XSSFColor(new java.awt.Color(fontColor[0], fontColor[1], fontColor[2]));
XSSFColor color10 = new XSSFColor(new java.awt.Color(bgColor[0], bgColor[1], bgColor[2]));
if (!(fontColor[0] == 0 && fontColor[1] == 0 && fontColor[2] == 0)) {
titleFont.setColor(color9);
}
titleFont.setBold(true);
titleFont.setFontHeightInPoints((short) fontSize);
XSSFCellStyle titleStyle = (XSSFCellStyle) createBorderCellStyle(workbook, true);
titleStyle.setFont(titleFont);
titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
titleStyle.setFillForegroundColor(color10);
titleStyle.setAlignment(HorizontalAlignment.CENTER);
titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
return titleStyle;
}
示例11: getHeadStyle
import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
/**
* 设置表头的单元格样式
*
* @return
*/
public XSSFCellStyle getHeadStyle() {
// 创建单元格样式
XSSFCellStyle cellStyle = wb.createCellStyle();
// 设置单元格的背景颜色为淡蓝色
cellStyle.setFillForegroundColor(HSSFColor.PALE_BLUE.index);
// 创建单元格内容显示不下时自动换行
//cellStyle.setWrapText(true);
// 设置单元格字体样式
XSSFFont font = wb.createFont();
// 设置字体加粗
font.setFontName("宋体");
font.setFontHeight((short) 200);
cellStyle.setFont(font);
return cellStyle;
}
示例12: getBodyStyle
import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
/**
* 设置表体的单元格样式
*
* @return
*/
public XSSFCellStyle getBodyStyle() {
// 创建单元格样式
XSSFCellStyle cellStyle = wb.createCellStyle();
// 创建单元格内容显示不下时自动换行
//cellStyle.setWrapText(true);
// 设置单元格字体样式
XSSFFont font = wb.createFont();
// 设置字体加粗
font.setFontName("宋体");
font.setFontHeight((short) 200);
cellStyle.setFont(font);
return cellStyle;
}
示例13: setStyle
import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
public static XSSFCellStyle setStyle(XSSFWorkbook workbook) {
//设置字体;
XSSFFont font = workbook.createFont();
//设置字体大小;
font.setFontHeightInPoints((short) 20);
//设置字体名字;
font.setFontName("Courier New");
//font.setItalic(true);
//font.setStrikeout(true);
//设置样式;
XSSFCellStyle style = workbook.createCellStyle();
//设置底边框;
style.setBorderBottom(XSSFCellStyle.BORDER_THIN);
//设置底边框颜色;
style.setBottomBorderColor(new XSSFColor(Color.BLACK));
//设置左边框;
style.setBorderLeft(XSSFCellStyle.BORDER_THIN);
//设置左边框颜色;
style.setLeftBorderColor(new XSSFColor(Color.BLACK));
//设置右边框;
style.setBorderRight(XSSFCellStyle.BORDER_THIN);
//设置右边框颜色;
style.setRightBorderColor(new XSSFColor(Color.BLACK));
//设置顶边框;
style.setBorderTop(XSSFCellStyle.BORDER_THIN);
//设置顶边框颜色;
style.setTopBorderColor(new XSSFColor(Color.BLACK));
//在样式用应用设置的字体;
style.setFont(font);
//设置自动换行;
style.setWrapText(false);
//设置水平对齐的样式为居中对齐;
style.setAlignment(XSSFCellStyle.ALIGN_CENTER);
//设置垂直对齐的样式为居中对齐;
style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
return style;
}
示例14: startSerialize
import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
@Override
protected void startSerialize( RootNode rootNode, OutputStream outputStream ) throws Exception
{
workbook = new XSSFWorkbook();
sheet = workbook.createSheet( "Sheet1" );
XSSFFont boldFont = workbook.createFont();
boldFont.setBold( true );
XSSFCellStyle boldCellStyle = workbook.createCellStyle();
boldCellStyle.setFont( boldFont );
// build schema
for ( Node child : rootNode.getChildren() )
{
if ( child.isCollection() )
{
if ( !child.getChildren().isEmpty() )
{
Node node = child.getChildren().get( 0 );
XSSFRow row = sheet.createRow( 0 );
int cellIdx = 0;
for ( Node property : node.getChildren() )
{
if ( property.isSimple() )
{
XSSFCell cell = row.createCell( cellIdx++ );
cell.setCellValue( property.getName() );
cell.setCellStyle( boldCellStyle );
}
}
}
}
}
}
示例15: getCellStyle
import org.apache.poi.xssf.usermodel.XSSFCellStyle; //导入方法依赖的package包/类
protected XSSFCellStyle getCellStyle(int border, Font font) {
XSSFCellStyle style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setWrapText(true); // new line
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
if((border & BORDER_BOTTOM) > 0) style.setBorderBottom(CellStyle.BORDER_DOUBLE);
else style.setBorderBottom(CellStyle.BORDER_THIN);
if((border & BORDER_LEFT) > 0) style.setBorderLeft(CellStyle.BORDER_DOUBLE);
else style.setBorderLeft(CellStyle.BORDER_THIN);
if((border & BORDER_RIGHT) > 0) style.setBorderRight(CellStyle.BORDER_DOUBLE);
else style.setBorderRight(CellStyle.BORDER_THIN);
if((border & BORDER_TOP) > 0) style.setBorderTop(CellStyle.BORDER_DOUBLE);
else style.setBorderTop(CellStyle.BORDER_THIN);
if(font != null) style.setFont(font);
return style;
}