本文整理汇总了C#中Font.AppendChild方法的典型用法代码示例。如果您正苦于以下问题:C# Font.AppendChild方法的具体用法?C# Font.AppendChild怎么用?C# Font.AppendChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Font
的用法示例。
在下文中一共展示了Font.AppendChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNewFont
private static Font GetNewFont(FontInfo fontInfo, Boolean ignoreMod = true)
{
var font = new Font();
var bold = (fontInfo.Font.BoldModified || ignoreMod) && fontInfo.Font.Bold ? new Bold() : null;
var italic = (fontInfo.Font.ItalicModified || ignoreMod) && fontInfo.Font.Italic ? new Italic() : null;
var underline = (fontInfo.Font.UnderlineModified || ignoreMod) &&
fontInfo.Font.Underline != XLFontUnderlineValues.None
? new Underline {Val = fontInfo.Font.Underline.ToOpenXml()}
: null;
var strike = (fontInfo.Font.StrikethroughModified || ignoreMod) && fontInfo.Font.Strikethrough
? new Strike()
: null;
var verticalAlignment = fontInfo.Font.VerticalAlignmentModified || ignoreMod
? new VerticalTextAlignment {Val = fontInfo.Font.VerticalAlignment.ToOpenXml()}
: null;
var shadow = (fontInfo.Font.ShadowModified || ignoreMod) && fontInfo.Font.Shadow ? new Shadow() : null;
var fontSize = fontInfo.Font.FontSizeModified || ignoreMod
? new FontSize {Val = fontInfo.Font.FontSize}
: null;
var color = fontInfo.Font.FontColorModified || ignoreMod ? GetNewColor(fontInfo.Font.FontColor) : null;
var fontName = fontInfo.Font.FontNameModified || ignoreMod
? new FontName {Val = fontInfo.Font.FontName}
: null;
var fontFamilyNumbering = fontInfo.Font.FontFamilyNumberingModified || ignoreMod
? new FontFamilyNumbering {Val = (Int32)fontInfo.Font.FontFamilyNumbering}
: null;
if (bold != null)
font.AppendChild(bold);
if (italic != null)
font.AppendChild(italic);
if (underline != null)
font.AppendChild(underline);
if (strike != null)
font.AppendChild(strike);
if (verticalAlignment != null)
font.AppendChild(verticalAlignment);
if (shadow != null)
font.AppendChild(shadow);
if (fontSize != null)
font.AppendChild(fontSize);
if (color != null)
font.AppendChild(color);
if (fontName != null)
font.AppendChild(fontName);
if (fontFamilyNumbering != null)
font.AppendChild(fontFamilyNumbering);
return font;
}
示例2: WriteDefaultStyles
void WriteDefaultStyles()
{
var stylePart = _document.WorkbookPart.AddNewPart<WorkbookStylesPart>();
stylePart.Stylesheet = new Stylesheet();
stylePart.Stylesheet.CellFormats = new CellFormats();
var cellFormatZero = new CellFormat
{
NumberFormatId = 0,
FontId = 0,
FillId = 0,
BorderId = 0,
};
stylePart.Stylesheet.CellFormats.AppendChild(cellFormatZero);
stylePart.Stylesheet.CellStyleFormats = new CellStyleFormats();
var cellStyleFormatZero = new CellFormat
{
NumberFormatId = 0,
FontId = 0,
FillId = 0,
BorderId = 0,
};
stylePart.Stylesheet.CellStyleFormats.AppendChild(cellStyleFormatZero);
stylePart.Stylesheet.Fonts = new Fonts();
var fonts = stylePart.Stylesheet.Fonts;
var font = new Font();
font.AppendChild(new FontSize { Val = 11 });
font.AppendChild(new Color { Theme = 1 });
font.AppendChild(new FontName { Val = "Calibri" });
font.AppendChild(new FontScheme { Val = FontSchemeValues.Minor });
fonts.AppendChild(font);
stylePart.Stylesheet.Fills = new Fills();
stylePart.Stylesheet.Fills.AppendChild(new Fill(new PatternFill
{
PatternType = PatternValues.None,
}));
stylePart.Stylesheet.Borders = new Borders();
var border = new Border
{
LeftBorder = new LeftBorder(),
RightBorder = new RightBorder(),
TopBorder = new TopBorder(),
BottomBorder = new BottomBorder(),
DiagonalBorder = new DiagonalBorder()
};
stylePart.Stylesheet.Borders.AppendChild(border);
}