/// <summary> /// Gets the or create font. /// </summary> /// <param name="index">The index.</param> /// <param name="source">The source.</param> /// <param name="target">The target.</param> /// <returns></returns> private static uint GetOrCreateFont(uint index, Stylesheet source, Stylesheet target) { var child = SafeIndex <Fonts, Font>(source.Fonts, (int)index); if (child == null) { return(0); } uint id = 0; if (target.TryMatchFont(child, out id)) { return(id); } return(target.AddFont(child)); }
/// <summary> /// Updates the supplied <see cref="CellFormat"/> with a font index which relates to the fund in the supplied <see cref="ExportStyle"/> /// </summary> /// <param name="stylesheet"></param> /// <param name="cellInfo"></param> /// <returns></returns> private static void UpdateFont(ExcelStylesManager stylesManager, ExcelCellStyleInfo cellInfo, ref Stylesheet stylesheet, ref CellFormat cellFormat) { if (cellFormat == null) { throw new ArgumentNullException("cellFormat"); } // Anything to apply? if (cellInfo.FontInfo == null) { return; } // Look up existing... var fontItem = stylesManager.fonts.Find(cellInfo.FontInfo); UInt32Value id = fontItem.Value; if (id == null) { // Fonts Font font = new Font(); if (cellInfo.FontInfo.FontFamily != null) { font.FontName = new FontName() { Val = new StringValue(cellInfo.FontInfo.FontFamily.ToString()) }; } font.FontSize = new FontSize() { Val = new DoubleValue(cellInfo.FontInfo.FontSize) }; if ((cellInfo.FontInfo.FontWeight != null) && (cellInfo.FontInfo.FontWeight == FontWeights.Bold)) { font.Bold = new Bold(); } if (cellInfo.FontInfo.FontStyle != null) { if (cellInfo.FontInfo.FontStyle == FontStyles.Italic) { font.Italic = new Italic(); } } font.Color = new DocumentFormat.OpenXml.Spreadsheet.Color() { Rgb = new HexBinaryValue(StyleTranslator.Translate(cellInfo.FontInfo.FontColour)) }; if (cellInfo.FontInfo.FontUnderlined) { font.Underline = new Underline(); } id = stylesheet.AddFont(font); stylesManager.fonts.Add(cellInfo.FontInfo, id); } cellFormat.FontId = id; }