本文整理汇总了C#中ICellStyle.SetFont方法的典型用法代码示例。如果您正苦于以下问题:C# ICellStyle.SetFont方法的具体用法?C# ICellStyle.SetFont怎么用?C# ICellStyle.SetFont使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICellStyle
的用法示例。
在下文中一共展示了ICellStyle.SetFont方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyCellStyle
/// <summary>
/// Copy c1 into c2
/// </summary>
public static void CopyCellStyle(IWorkbook wb, ICellStyle c1, ICellStyle c2)
{
c2.Alignment = c1.Alignment;
c2.BorderBottom = c1.BorderBottom;
c2.BorderLeft = c1.BorderLeft;
c2.BorderRight = c1.BorderRight;
c2.BorderTop = c1.BorderTop;
c2.BottomBorderColor = c1.BottomBorderColor;
c2.DataFormat = c1.DataFormat;
c2.FillBackgroundColor = c1.FillBackgroundColor;
c2.FillForegroundColor = c1.FillForegroundColor;
c2.FillPattern = c1.FillPattern;
c2.SetFont(wb.GetFontAt(c1.FontIndex));
// HIDDEN ?
c2.Indention = c1.Indention;
c2.LeftBorderColor = c1.LeftBorderColor;
// LOCKED ?
c2.RightBorderColor = c1.RightBorderColor;
c2.Rotation = c1.Rotation;
c2.TopBorderColor = c1.TopBorderColor;
c2.VerticalAlignment = c1.VerticalAlignment;
c2.WrapText = c1.WrapText;
}
示例2: XlsModel
public XlsModel(string sheetName)
{
SheetName = sheetName;
// Create a new workbook and a sheet named "User Accounts"
_workbook = new HSSFWorkbook();
_sheet = _workbook.CreateSheet(SheetName);
var boldFont = _workbook.CreateFont();
boldFont.FontHeightInPoints = 10;
boldFont.FontName = "Arial";
boldFont.Boldweight = (short) FontBoldWeight.Bold;
_dateStyle = _workbook.CreateCellStyle();
_dateStyle.DataFormat = _workbook.CreateDataFormat().GetFormat("dd/mm/yyyy");
_nullStyle = _workbook.CreateCellStyle();
_nullStyle.FillForegroundColor = HSSFColor.Grey40Percent.Index;
_nullStyle.FillPattern = FillPattern.SolidForeground;
_headStyle = _workbook.CreateCellStyle();
_headStyle.SetFont(boldFont);
}
示例3: SetFormatProperties
/**
* 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(ICellStyle style, IWorkbook workbook, Dictionary<String, Object> properties)
{
style.Alignment=(HorizontalAlignment)(GetShort(properties, ALIGNMENT));
style.BorderBottom=(BorderStyle)(GetShort(properties, BORDER_BOTTOM));
style.BorderLeft=(BorderStyle)(GetShort(properties, BORDER_LEFT));
style.BorderRight=(BorderStyle)(GetShort(properties, BORDER_RIGHT));
style.BorderTop=(BorderStyle)(GetShort(properties, BORDER_TOP));
style.BottomBorderColor=(GetShort(properties, BOTTOM_BORDER_COLOR));
style.DataFormat=(GetShort(properties, DATA_FORMAT));
style.FillBackgroundColor=(GetShort(properties, FILL_BACKGROUND_COLOR));
style.FillForegroundColor=(GetShort(properties, FILL_FOREGROUND_COLOR));
style.FillPattern=(FillPatternType)(GetShort(properties, FILL_PATTERN));
style.SetFont(workbook.GetFontAt(GetShort(properties, FONT)));
style.IsHidden=(GetBoolean(properties, HIDDEN));
style.Indention=(GetShort(properties, INDENTION));
style.LeftBorderColor=(GetShort(properties, LEFT_BORDER_COLOR));
style.IsLocked=(GetBoolean(properties, LOCKED));
style.RightBorderColor=(GetShort(properties, RIGHT_BORDER_COLOR));
style.Rotation=(GetShort(properties, ROTATION));
style.TopBorderColor=(GetShort(properties, TOP_BORDER_COLOR));
style.VerticalAlignment=(VerticalAlignment)(GetShort(properties, VERTICAL_ALIGNMENT));
style.WrapText=(GetBoolean(properties, WRAP_TEXT));
}
示例4: InitTitleStyle
/// <summary>
/// 初始化标题样式
/// </summary>
private void InitTitleStyle()
{
// 标题字体
IFont titleFont = workbook.CreateFont();
titleFont.FontHeightInPoints = 9;
titleFont.FontName = "宋体";
titleFont.Boldweight = (short)FontBoldWeight.Bold;
// 标题样式
titleStyle = workbook.CreateCellStyle();
titleStyle.WrapText = false;
titleStyle.SetFont(titleFont);
titleStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
titleStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
}
示例5: GetDataStyle
private ICellStyle GetDataStyle()
{
if (dataStyle == null)
{
//数据样式
dataStyle = workbook.CreateCellStyle();
dataStyle.Alignment = HorizontalAlignment.LEFT;//左对齐
//数据单元格的边框
dataStyle.BorderTop = BorderStyle.THIN;
dataStyle.TopBorderColor = HSSFColor.BLACK.index;
dataStyle.BorderRight = BorderStyle.THIN;
dataStyle.RightBorderColor = HSSFColor.BLACK.index;
dataStyle.BorderBottom = BorderStyle.THIN;
dataStyle.BottomBorderColor = HSSFColor.BLACK.index;
dataStyle.BorderLeft = BorderStyle.THIN;
dataStyle.LeftBorderColor = HSSFColor.BLACK.index;
//数据的字体
var datafont = workbook.CreateFont();
datafont.FontHeightInPoints = 11;//字号
dataStyle.SetFont(datafont);
}
return dataStyle;
}
示例6: RegisterTitleStyle
public virtual void RegisterTitleStyle(IWorkbook workbook, ICellStyle cellStyle)
{
cellStyle.SetBorder();
cellStyle.SetBackgroundColor(HSSFColor.Red.Index);
cellStyle.SetFont(workbook.GetFontAt(1));
}
示例7: ApplyStyle
/// <summary>
/// Applies the style by copying the fluent style to the NPOI style object,.
/// </summary>
/// <param name="workbook">The workbook.</param>
/// <param name="destination">The destination NPOI style object to apply the FluentStyle to.</param>
public void ApplyStyle(IWorkbook workbook, ICellStyle destination)
{
// If users sets format string this overrides the DataFormat property.
if (Format != null)
{
var dataFormat = workbook.CreateDataFormat();
DataFormat = dataFormat.GetFormat(Format);
}
if (Alignment != null) destination.Alignment = Alignment.Value;
if (BorderBottom != null) destination.BorderBottom = BorderBottom.Value;
if (BorderDiagonal != null) destination.BorderDiagonal = BorderDiagonal.Value;
if (BorderDiagonalColor != null) destination.BorderDiagonalColor = BorderDiagonalColor.Value;
if (BorderDiagonalLineStyle != null) destination.BorderDiagonalLineStyle = BorderDiagonalLineStyle.Value;
if (BorderLeft != null) destination.BorderLeft = BorderLeft.Value;
if (BorderRight != null) destination.BorderRight = BorderRight.Value;
if (BorderTop != null) destination.BorderTop = BorderTop.Value;
if (BottomBorderColor != null) destination.BottomBorderColor = BottomBorderColor.Value;
if (DataFormat != null) destination.DataFormat = DataFormat.Value;
if (FillBackgroundColor != null) destination.FillBackgroundColor = FillBackgroundColor.Value;
if (FillForegroundColor != null) destination.FillForegroundColor = FillForegroundColor.Value;
if (FillPattern != null) destination.FillPattern = FillPattern.Value;
if (Indention != null) destination.Indention = Indention.Value;
if (LeftBorderColor != null) destination.LeftBorderColor = LeftBorderColor.Value;
if (RightBorderColor != null) destination.RightBorderColor = RightBorderColor.Value;
if (Rotation != null) destination.Rotation = Rotation.Value;
if (ShrinkToFit != null) destination.ShrinkToFit = ShrinkToFit.Value;
if (TopBorderColor != null) destination.TopBorderColor = TopBorderColor.Value;
if (VerticalAlignment != null) destination.VerticalAlignment = VerticalAlignment.Value;
if (WrapText != null) destination.WrapText = WrapText.Value;
if (FontIsNeeded)
{
var font = workbook.CreateFont();
if (FontWeight != null) font.Boldweight = (short)FontWeight.Value;
if (Charset != null) font.Charset = Charset.Value;
if (Color != null) font.Color = Color.Value;
if (FontHeight != null) font.FontHeight = FontHeight.Value;
if (FontHeightInPoints != null) font.FontHeightInPoints = FontHeightInPoints.Value;
if (FontName != null) font.FontName = FontName;
if (Italic != null) font.IsItalic = Italic.Value;
if (Strikeout != null) font.IsStrikeout = Strikeout.Value;
if (SuperScript != null) font.TypeOffset = SuperScript.Value;
if (Underline != null) font.Underline = Underline.Value;
destination.SetFont(font);
}
}