本文整理汇总了Java中org.apache.poi.ss.usermodel.Font.setColor方法的典型用法代码示例。如果您正苦于以下问题:Java Font.setColor方法的具体用法?Java Font.setColor怎么用?Java Font.setColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.ss.usermodel.Font
的用法示例。
在下文中一共展示了Font.setColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createIndentationCellStyle
import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
public CellStyle createIndentationCellStyle(Workbook workbook, int s) {
CellStyle dataStyle1 = this.createBorderCellStyle(workbook, true);
Font dataFont = workbook.createFont();
dataFont.setColor((short) 12);
dataFont.setFontHeightInPoints((short) 10);
dataStyle1.setFillPattern(FillPatternType.SOLID_FOREGROUND);
dataStyle1.setFillForegroundColor((short) 11);
dataStyle1.setFont(dataFont);
dataStyle1.setVerticalAlignment(VerticalAlignment.CENTER);
dataStyle1.setAlignment(HorizontalAlignment.LEFT);
dataStyle1.setIndention(Short.valueOf(String.valueOf((s))));
return dataStyle1;
}
示例2: defaultHeaderCellStyle
import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
/**
* Returns the default header style. Obtained from:
* http://svn.apache.org/repos/asf/poi
* /trunk/src/examples/src/org/apache/poi/ss/examples/TimesheetDemo.java
*
* @param wb the wb
* @return the cell style
*/
protected CellStyle defaultHeaderCellStyle(final Workbook wb) {
CellStyle style;
final Font monthFont = wb.createFont();
monthFont.setFontHeightInPoints((short) 11);
monthFont.setColor(IndexedColors.WHITE.getIndex());
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setFont(monthFont);
style.setWrapText(true);
return style;
}
示例3: makeHeader
import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
private void makeHeader ( final List<Field> columns, final HSSFSheet sheet )
{
final Font font = sheet.getWorkbook ().createFont ();
font.setFontName ( "Arial" );
font.setBoldweight ( Font.BOLDWEIGHT_BOLD );
font.setColor ( HSSFColor.WHITE.index );
final CellStyle style = sheet.getWorkbook ().createCellStyle ();
style.setFont ( font );
style.setFillForegroundColor ( HSSFColor.BLACK.index );
style.setFillPattern ( PatternFormatting.SOLID_FOREGROUND );
final HSSFRow row = sheet.createRow ( 0 );
for ( int i = 0; i < columns.size (); i++ )
{
final Field field = columns.get ( i );
final HSSFCell cell = row.createCell ( i );
cell.setCellValue ( field.getHeader () );
cell.setCellStyle ( style );
}
}
示例4: createStyles
import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
/**
* 创建表格样式
* @param wb 工作薄对象
* @return 样式列表
*/
private Map<String, CellStyle> createStyles(Workbook wb) {
Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
CellStyle style = wb.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
Font titleFont = wb.createFont();
titleFont.setFontName("Arial");
titleFont.setFontHeightInPoints((short) 16);
titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
style.setFont(titleFont);
styles.put("title", style);
style = wb.createCellStyle();
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setBorderRight(CellStyle.BORDER_THIN);
style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderLeft(CellStyle.BORDER_THIN);
style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderTop(CellStyle.BORDER_THIN);
style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderBottom(CellStyle.BORDER_THIN);
style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
Font dataFont = wb.createFont();
dataFont.setFontName("Arial");
dataFont.setFontHeightInPoints((short) 10);
style.setFont(dataFont);
styles.put("data", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(CellStyle.ALIGN_LEFT);
styles.put("data1", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(CellStyle.ALIGN_CENTER);
styles.put("data2", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(CellStyle.ALIGN_RIGHT);
styles.put("data3", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
// style.setWrapText(true);
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
Font headerFont = wb.createFont();
headerFont.setFontName("Arial");
headerFont.setFontHeightInPoints((short) 10);
headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
headerFont.setColor(IndexedColors.WHITE.getIndex());
style.setFont(headerFont);
styles.put("header", style);
return styles;
}
示例5: createHeadStyle
import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
CellStyle createHeadStyle() {
if (headerCellStyle != null) {
return headerCellStyle;
}
CellStyle style = wb.createCellStyle();
// 设置这些样式
style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
style.setAlignment(CellStyle.ALIGN_CENTER);
// 生成一个字体
Font font = wb.createFont();
font.setColor(IndexedColors.BLACK.index);
font.setFontHeightInPoints((short) 12);
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
// 把字体应用到当前的样式
style.setFont(font);
headerCellStyle = style;
return style;
}
示例6: createHeadDateStyle
import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
CellStyle createHeadDateStyle() {
if (headDateCellStyle != null) {
return headDateCellStyle;
}
CellStyle cellStyle = wb.createCellStyle();
DataFormat format = wb.createDataFormat();
cellStyle.setDataFormat(format.getFormat("m/d/yy h:mm"));
// 设置这些样式
cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.index);
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
// 生成一个字体
Font font = wb.createFont();
font.setColor(IndexedColors.BLACK.index);
font.setFontHeightInPoints((short) 12);
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
// 把字体应用到当前的样式
cellStyle.setFont(font);
headDateCellStyle = cellStyle;
return cellStyle;
}
示例7: createLinkStyle
import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
private CellStyle createLinkStyle(boolean bordered) {
final Font hlinkFont = wb.createFont();
hlinkFont.setUnderline(Font.U_SINGLE);
hlinkFont.setColor(IndexedColors.BLUE.getIndex());
final CellStyle style;
if (bordered) {
style = createBorderedStyle(wb);
} else {
style = wb.createCellStyle();
}
style.setFont(hlinkFont);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setIndention((short) 1);
style.setWrapText(true);
return style;
}
示例8: openOutputData
import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
/**
* @throws TechnicalException
* is thrown if you have a technical error (format, configuration, datas, ...) in NoraUi.
*/
void openOutputData() throws TechnicalException {
this.dataOutExtension = validExtension(dataOutPath);
try (FileInputStream fileOut = new FileInputStream(dataOutPath + scenarioName + "." + dataOutExtension);) {
initWorkbook(fileOut, dataOutExtension);
} catch (final IOException e) {
throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_DATA_IOEXCEPTION), e);
}
styleSuccess = workbook.createCellStyle();
final Font fontSuccess = workbook.createFont();
fontSuccess.setColor(HSSFColor.HSSFColorPredefined.GREEN.getIndex());
styleSuccess.setFont(fontSuccess);
styleFailed = workbook.createCellStyle();
final Font fontFailed = workbook.createFont();
fontFailed.setColor(HSSFColor.HSSFColorPredefined.RED.getIndex());
styleFailed.setFont(fontFailed);
styleWarning = workbook.createCellStyle();
final Font fontWarning = workbook.createFont();
fontWarning.setColor(HSSFColor.HSSFColorPredefined.ORANGE.getIndex());
styleWarning.setFont(fontWarning);
}
示例9: createStyles
import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
/**
* excel 样式
*
* @return
*/
public Map<String, CellStyle> createStyles(Workbook workbook) {
Map<String, CellStyle> styles = new HashMap();
CellStyle style = workbook.createCellStyle();
style.setAlignment((short) 2);
style.setVerticalAlignment((short) 1);
Font titleFont = workbook.createFont();
titleFont.setFontName("Arial");
titleFont.setFontHeightInPoints((short) 16);
titleFont.setBoldweight((short) 700);
style.setFont(titleFont);
styles.put("title", style);
style = workbook.createCellStyle();
style.setVerticalAlignment((short) 1);
style.setBorderRight((short) 1);
style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderLeft((short) 1);
style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderTop((short) 1);
style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderBottom((short) 1);
style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
Font dataFont = workbook.createFont();
dataFont.setFontName("Arial");
dataFont.setFontHeightInPoints((short) 10);
style.setFont(dataFont);
styles.put("data", style);
style = workbook.createCellStyle();
style.cloneStyleFrom((CellStyle) styles.get("data"));
style.setAlignment((short) 1);
styles.put("data1", style);
style = workbook.createCellStyle();
style.cloneStyleFrom((CellStyle) styles.get("data"));
style.setAlignment((short) 2);
styles.put("data2", style);
style = workbook.createCellStyle();
style.cloneStyleFrom((CellStyle) styles.get("data"));
style.setAlignment((short) 3);
styles.put("data3", style);
style = workbook.createCellStyle();
style.cloneStyleFrom((CellStyle) styles.get("data"));
style.setAlignment((short) 2);
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern((short) 1);
Font headerFont = workbook.createFont();
headerFont.setFontName("Arial");
headerFont.setFontHeightInPoints((short) 10);
headerFont.setBoldweight((short) 700);
headerFont.setColor(IndexedColors.WHITE.getIndex());
style.setFont(headerFont);
styles.put("header", style);
return styles;
}
示例10: copyFont
import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
/**
* 复制字体
*
* @author ZhengWei(HY)
* @createDate 2017-03-18
* @version v1.0
*
* @param i_FromFont 源字体
* @param i_ToFont 目标字体
*/
public final static void copyFont(Font i_FromFont ,Font i_ToFont)
{
i_ToFont.setBold( i_FromFont.getBold());
i_ToFont.setCharSet( i_FromFont.getCharSet());
i_ToFont.setColor( i_FromFont.getColor());
i_ToFont.setFontHeight( i_FromFont.getFontHeight());
i_ToFont.setFontHeightInPoints(i_FromFont.getFontHeightInPoints());
i_ToFont.setFontName( i_FromFont.getFontName());
i_ToFont.setItalic( i_FromFont.getItalic());
i_ToFont.setStrikeout( i_FromFont.getStrikeout());
i_ToFont.setTypeOffset( i_FromFont.getTypeOffset());
i_ToFont.setUnderline( i_FromFont.getUnderline());
}
示例11: startExport
import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
@Override public void startExport(List<? extends IExportColumn<?>> columnList) throws Exception {
if(m_started)
throw new IllegalArgumentException("The writer was already started");
m_started = true;
m_columnList = columnList;
Workbook wb = m_workbook = createWorkbook();
Font defaultFont = wb.createFont();
defaultFont.setFontHeightInPoints((short) 10);
defaultFont.setFontName("Arial");
CellStyle dcs = m_defaultCellStyle = wb.createCellStyle();
dcs.setFont(defaultFont);
// FIXME Date format must be locale dependent?
CellStyle dates = m_dateStyle = wb.createCellStyle();
dates.setDataFormat(wb.createDataFormat().getFormat("d-m-yyyy"));
dates.setFont(defaultFont);
CellStyle curs = m_currencyStyle = wb.createCellStyle();
curs.setDataFormat(wb.createDataFormat().getFormat("#,##0.00"));
curs.setFont(defaultFont);
CellStyle nums = m_numberStyle = wb.createCellStyle();
nums.setDataFormat(wb.createDataFormat().getFormat("#0"));
nums.setFont(defaultFont);
Font headerFont = wb.createFont();
headerFont.setFontHeightInPoints((short) 10);
headerFont.setColor((short) 0xc);
headerFont.setBold(true);
headerFont.setFontName("Arial");
CellStyle hds = m_headerStyle = wb.createCellStyle();
hds.setBorderBottom(BorderStyle.THIN);
hds.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
hds.setFont(headerFont);
createNewSheet(columnList);
}
示例12: crateCaptionCellStyle
import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
/**
*
* @return
*/
protected CellStyle crateCaptionCellStyle() {
Font font = workbook.createFont();
font.setColor(Font.COLOR_NORMAL);
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setWrapText(false);
font.setFontHeight((short) 250);
cellStyle.setFont(font);
cellStyle.setFillForegroundColor(IndexedColors.BLUE_GREY.index);
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
return cellStyle;
}
示例13: crateTitleCellStyle
import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
/**
* 表头单元格样式
*
* @return
*/
protected CellStyle crateTitleCellStyle() {
Font font = workbook.createFont();
font.setColor(Font.COLOR_NORMAL);
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setWrapText(false);
font.setFontHeight((short) 250);
cellStyle.setFont(font);
cellStyle.setFillForegroundColor(HSSFColor.BLUE_GREY.index);
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
short border = 1;
setCellBorder(cellStyle, border, border, border, border);
cellStyle.setAlignment(CellStyle.ALIGN_LEFT);
return cellStyle;
}
示例14: configFont
import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
private void configFont(Font font) {
font.setBold(isBold());
font.setItalic(isItalic());
font.setStrikeout(isStrikeout());
font.setUnderline(isUnderline() ? Font.U_SINGLE : Font.U_NONE);
if (getFontSize() != null) {
font.setFontHeightInPoints(fontSize.shortValue());
}
if (getFontColor() != null) {
if (font instanceof XSSFFont) {
((XSSFFont)font).setColor(new XSSFColor(toRgbByte(fontColor)));
} else {
font.setColor(fontColor.getIndex());
}
}
}
示例15: setBold
import org.apache.poi.ss.usermodel.Font; //导入方法依赖的package包/类
/**
* Set a bold font for the given cell with a given font size (in pt).
*
* @param wb
* the workbook that contains the cell
* @param cell
* the cell where the text is contained
* @param size
* the size in pt of the text
*/
public static void setBold(Workbook wb, HSSFCell cell, short size) {
Font font = wb.createFont();
font.setFontHeightInPoints((short) size);
font.setFontName("Arial");
font.setColor(IndexedColors.BLACK.getIndex());
font.setBold(true);
font.setItalic(false);
CellStyle style = wb.createCellStyle();
style.setFont(font);
cell.setCellStyle(style);
}