public static void SetIndent(ParagraphProperties pp, int?leftChars, FirstLineOrHangingChars firstLineOrhangingChars) { var indent = new Indentation(); if (leftChars != null) { indent.LeftChars = leftChars.Value; } if (firstLineOrhangingChars != null) { switch (firstLineOrhangingChars.Floh) { case FirstLineOrHanging.FirstLine: indent.FirstLineChars = firstLineOrhangingChars.Chars; break; case FirstLineOrHanging.Hanging: indent.HangingChars = firstLineOrhangingChars.Chars; break; default: throw new InvalidEnumArgumentException(firstLineOrhangingChars.Floh.ToString()); } } OpenXmlElementHelper.SetChild(pp, indent); }
internal static void SetFontSize(RunProperties rp, int fontSize) { OpenXmlElementHelper.SetChild(rp, new FontSize { Val = fontSize.ToString() }); OpenXmlElementHelper.SetChild(rp, new FontSizeComplexScript { Val = fontSize.ToString() }); }
internal static void SetFontName(RunProperties rp, string fontName) { OpenXmlElementHelper.SetChild(rp, new RunFonts { Ascii = fontName, HighAnsi = fontName, EastAsia = fontName, ComplexScript = fontName }); }
// Colunn index is zero-based. public static void SetColumnJustification(Table table, int columnIndex, JustificationValues jv) { foreach (var tr in table.Elements <TableRow>()) { var tc = columnIndex == 0 ? tr.GetFirstChild <TableCell>() : tr.Elements <TableCell>().ToList()[columnIndex]; var p = tc.GetFirstChild <Paragraph>(); OpenXmlElementHelper.SetChildIfNotExists <ParagraphProperties>(p); OpenXmlElementHelper.SetChild(p.GetFirstChild <ParagraphProperties>(), new Justification { Val = jv }); } }
public static void SetParagraphProperties(ParagraphProperties p, int?leftChars, FirstLineOrHangingChars firstLineOrhangingChars, int?spaceBetweenLines, JustificationValues?jv) { var oxes = new List <OpenXmlElement>(); if (leftChars != null || firstLineOrhangingChars != null) { var indent = new Indentation(); if (leftChars != null) { indent.LeftChars = leftChars.Value; } if (firstLineOrhangingChars != null) { switch (firstLineOrhangingChars.Floh) { case FirstLineOrHanging.FirstLine: indent.FirstLineChars = firstLineOrhangingChars.Chars; break; case FirstLineOrHanging.Hanging: indent.HangingChars = firstLineOrhangingChars.Chars; break; default: throw new InvalidEnumArgumentException(firstLineOrhangingChars.Floh.ToString()); } } oxes.Add(indent); } if (spaceBetweenLines.HasValue) { oxes.Add(new SpacingBetweenLines { LineRule = LineSpacingRuleValues.Auto, Line = spaceBetweenLines.Value.ToString() }); } if (jv.HasValue) { oxes.Add(new Justification { Val = jv }); } OpenXmlElementHelper.SetChild(p, new ParagraphProperties(oxes)); }
internal static void SetRunProperties(Run run, bool isBold, bool isItalic, bool isUnderline, string fontName, int?fontSize) { var oxes = new List <OpenXmlElement>(); if (isBold) { oxes.Add(new Bold()); } if (isItalic) { oxes.Add(new Italic()); } if (isUnderline) { oxes.Add(new Underline { Val = UnderlineValues.Single }); } if (fontName != null) { oxes.Add(new RunFonts { Ascii = fontName, HighAnsi = fontName, EastAsia = fontName, ComplexScript = fontName }); } if (fontSize.HasValue) { oxes.Add(new FontSize { Val = fontSize.Value.ToString() }); oxes.Add(new FontSizeComplexScript { Val = fontSize.Value.ToString() }); } OpenXmlElementHelper.SetChild(run, new RunProperties(oxes)); }
public static void SetJustification(ParagraphProperties pp, JustificationValues jv) { OpenXmlElementHelper.SetChild(pp, new Justification { Val = jv }); }
public static void SetSpacinggBetweenLines(ParagraphProperties pp, int space) { OpenXmlElementHelper.SetChild(pp, new SpacingBetweenLines { LineRule = LineSpacingRuleValues.Auto, Line = space.ToString() }); }
internal static void SetUnderline(RunProperties rp) { OpenXmlElementHelper.SetChild(rp, new Underline { Val = UnderlineValues.Single }); }
internal static void SetItalic(RunProperties rp) { OpenXmlElementHelper.SetChild(rp, new Italic()); }
internal static void SetBold(RunProperties rp) { OpenXmlElementHelper.SetChild(rp, new Bold()); }