private static Styles WordStyles(IEnumerable <Campus.Report.Base.Style> stylesList) { var styles = new DocumentFormat.OpenXml.Wordprocessing.Styles(); int countId = 1; foreach (var s in stylesList) { var paragraphStyle = new DocumentFormat.OpenXml.Wordprocessing.Style() { Type = DocumentFormat.OpenXml.Wordprocessing.StyleValues.Paragraph, StyleId = "p" + countId, CustomStyle = true, Default = false, StyleName = new DocumentFormat.OpenXml.Wordprocessing.StyleName { Val = s.Name } }; var styleRunProperties = new DocumentFormat.OpenXml.Wordprocessing.StyleRunProperties { Color = new DocumentFormat.OpenXml.Wordprocessing.Color() { Val = ColorToRgb(s.FontColor) }, RunFonts = new DocumentFormat.OpenXml.Wordprocessing.RunFonts() { Ascii = s.FontName }, FontSize = new DocumentFormat.OpenXml.Wordprocessing.FontSize() { Val = (s.FontSize * 2).ToString() }, Bold = s.TextStyle.Contains(TextStyleType.Bold) ? new DocumentFormat.OpenXml.Wordprocessing.Bold() : null, Italic = s.TextStyle.Contains(TextStyleType.Italic) ? new DocumentFormat.OpenXml.Wordprocessing.Italic() : null, Underline = s.TextStyle.Contains(TextStyleType.Underline) ? new DocumentFormat.OpenXml.Wordprocessing.Underline() : null }; var helpStyleRunProperties = WordFontStyle(s.TextStyle); paragraphStyle.Append(styleRunProperties); paragraphStyle.Append(helpStyleRunProperties); styles.Append(paragraphStyle); countId++; } return(styles); }
private static StyleRunProperties WordFontStyle(IEnumerable <TextStyleType> textStyle) { var property = new DocumentFormat.OpenXml.Wordprocessing.StyleRunProperties(); foreach (var item in textStyle) { switch (item) { case TextStyleType.Bold: property.Bold = new DocumentFormat.OpenXml.Wordprocessing.Bold(); break; case TextStyleType.Italic: property.Italic = new DocumentFormat.OpenXml.Wordprocessing.Italic(); break; case TextStyleType.Underline: property.Underline = new DocumentFormat.OpenXml.Wordprocessing.Underline() { Val = DocumentFormat.OpenXml.Wordprocessing.UnderlineValues.Single }; break; default: break; } } return(property); }