private void InsertMultiLineText(string text, OpenXmlElement siblingElement, ParagraphProperties paraProp, RunProperties rProp) { if (!text.Contains("\r\n")) { return; } var insertElement = siblingElement; var textLines = text.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); var cnt = 0; foreach (var textLine in textLines) { var newPara = new Paragraph { ParagraphProperties = (ParagraphProperties)paraProp.Clone() }; if (cnt == 0) { BkmStart = new BookmarkStart { Name = BkmStart.Name, Id = BkmStart.Id }; newPara.AppendChild(BkmStart); } var nr = new Run(); if (rProp != null) { nr.RunProperties = (RunProperties)rProp.Clone(); } nr.AppendChild(new Text(textLine)); newPara.AppendChild(nr); if (cnt == textLines.Length - 1) { BkmEnd = new BookmarkEnd { Id = BkmStart.Id }; newPara.AppendChild(BkmEnd); } if (insertElement == null) { BkmStart.Parent.InsertAfter(newPara, BkmStart); } else { if (insertElement.Parent != null) { insertElement.InsertAfterSelf(newPara); } else { insertElement.Append(newPara); } } insertElement = newPara; cnt += 1; } }
//public static void AddText(Body body, int line, ParagraphProperties paragraphProperties = null) public static IEnumerable <OpenXmlElement> CreateText_02(int line, ParagraphProperties paragraphProperties = null) { //Paragraph paragraph = body.AppendChild(new Paragraph()); Paragraph paragraph = new Paragraph(); Run run = paragraph.AppendChild(new Run()); run.AppendChild(new DW.Text("test")); yield return(paragraph); for (int i = 0; i < line; i++) { //paragraph = body.AppendChild(new Paragraph()); paragraph = new Paragraph(); if (paragraphProperties != null) { paragraph.ParagraphProperties = (ParagraphProperties)paragraphProperties.Clone(); } run = paragraph.AppendChild(new Run()); yield return(paragraph); } }
public static ParagraphProperties UncompressPAP(ParagraphProperties parent, byte[] grpprl, int Offset) { ParagraphProperties newProperties = null; newProperties = (ParagraphProperties)parent.Clone(); SprmIterator sprmIt = new SprmIterator(grpprl, Offset); while (sprmIt.HasNext()) { SprmOperation sprm = sprmIt.Next(); // PAPXs can contain table sprms if the paragraph marks the end of a // table row if (sprm.Type == SprmOperation.TYPE_PAP) { UncompressPAPOperation(newProperties, sprm); } } return(newProperties); }
//public static void AddText(Body body, int line, ParagraphProperties paragraphProperties = null) public static IEnumerable<OpenXmlElement> CreateText_02(int line, ParagraphProperties paragraphProperties = null) { //Paragraph paragraph = body.AppendChild(new Paragraph()); Paragraph paragraph = new Paragraph(); Run run = paragraph.AppendChild(new Run()); run.AppendChild(new DW.Text("test")); yield return paragraph; for (int i = 0; i < line; i++) { //paragraph = body.AppendChild(new Paragraph()); paragraph = new Paragraph(); if (paragraphProperties != null) paragraph.ParagraphProperties = (ParagraphProperties)paragraphProperties.Clone(); run = paragraph.AppendChild(new Run()); yield return paragraph; } }
//public static void AddText(Body body, ParagraphProperties paragraphProperties = null) public static IEnumerable<OpenXmlElement> CreateText_01(ParagraphProperties paragraphProperties = null) { //Paragraph paragraph = body.AppendChild(new Paragraph()); Paragraph paragraph = new Paragraph(); Run run = paragraph.AppendChild(new Run()); run.AppendChild(new DW.Text("zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo")); run.AppendChild(new Break()); run.AppendChild(new DW.Text("zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo")); run.AppendChild(new Break()); run.AppendChild(new DW.Text("zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo")); yield return paragraph; //paragraph = body.AppendChild(new Paragraph()); paragraph = new Paragraph(); if (paragraphProperties != null) paragraph.ParagraphProperties = (ParagraphProperties)paragraphProperties.Clone(); run = paragraph.AppendChild(new Run()); yield return paragraph; //paragraph = body.AppendChild(new Paragraph()); paragraph = new Paragraph(); //if (paragraphProperties != null) // paragraph.ParagraphProperties = (ParagraphProperties)paragraphProperties.Clone(); run = paragraph.AppendChild(new Run()); run.AppendChild(new DW.Text("toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto")); run.AppendChild(new Break()); run.AppendChild(new DW.Text("toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto")); run.AppendChild(new Break()); run.AppendChild(new DW.Text("toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto")); yield return paragraph; //paragraph = body.AppendChild(new Paragraph()); paragraph = new Paragraph(); if (paragraphProperties != null) paragraph.ParagraphProperties = (ParagraphProperties)paragraphProperties.Clone(); run = paragraph.AppendChild(new Run()); yield return paragraph; //paragraph = body.AppendChild(new Paragraph()); paragraph = new Paragraph(); //if (paragraphProperties != null) // paragraph.ParagraphProperties = (ParagraphProperties)paragraphProperties.Clone(); run = paragraph.AppendChild(new Run()); run.AppendChild(new DW.Text("tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata")); run.AppendChild(new Break()); run.AppendChild(new DW.Text("tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata")); run.AppendChild(new Break()); run.AppendChild(new DW.Text("tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata")); yield return paragraph; //paragraph = body.AppendChild(new Paragraph()); for (int i = 0; i < 11; i++) { paragraph = new Paragraph(); run = paragraph.AppendChild(new Run()); yield return paragraph; } //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); }
public Table AppendTotalPriceTableInfo(List <string> tableData, Table table, bool header) { TableRow tr = new TableRow(); PreviousTablePropertyExceptions ptpex = new PreviousTablePropertyExceptions(); TableCellMarginDefault tcm = new TableCellMarginDefault(); tcm.TopMargin = new TopMargin() { Width = "0", Type = TableWidthUnitValues.Dxa }; tcm.BottomMargin = new BottomMargin() { Width = "0", Type = TableWidthUnitValues.Dxa }; ptpex.Append(tcm); tr.Append(ptpex); TableCell tc; TableCellProperties tcp = new TableCellProperties(new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center }); tcp.TableCellMargin = new TableCellMargin(new RightMargin() { Type = TableWidthUnitValues.Pct, Width = "50" }); tcp.TableCellMargin.LeftMargin = new LeftMargin() { Type = TableWidthUnitValues.Pct, Width = "50" }; tcp.TableCellMargin.TopMargin = new TopMargin() { Type = TableWidthUnitValues.Pct, Width = "1" }; tcp.TableCellBorders = new TableCellBorders( new TopBorder() { Val = new EnumValue <BorderValues>(BorderValues.None), Size = 0, Space = 0 }, new BottomBorder() { Val = new EnumValue <BorderValues>(BorderValues.None), Size = 0, Space = 0 }, new LeftBorder() { Val = new EnumValue <BorderValues>(BorderValues.None), Size = 0, Space = 0 }, new RightBorder() { Val = new EnumValue <BorderValues>(BorderValues.None), Size = 0, Space = 0 }, new InsideHorizontalBorder() { Val = new EnumValue <BorderValues>(BorderValues.None), Size = 0, Space = 0 }, new InsideVerticalBorder() { Val = new EnumValue <BorderValues>(BorderValues.None), Size = 0, Space = 0 } ); ParagraphProperties ppl = new ParagraphProperties(new Justification() { Val = JustificationValues.Left }); ParagraphProperties ppr = new ParagraphProperties(new Justification() { Val = JustificationValues.Right }); ppl.Append(new KeepLines()); ppl.Append(new KeepNext()); SpacingBetweenLines sp = new SpacingBetweenLines(); sp.After = "0"; ppl.Append(sp); ppr.Append(new KeepLines()); ppr.Append(new KeepNext()); SpacingBetweenLines spr = new SpacingBetweenLines(); spr.After = "0"; ppr.Append(spr); RunProperties rp = new RunProperties(new Bold() { Val = false }); Shading shading = new Shading(); rp.Bold.Val = false; rp.RunFonts = new RunFonts() { Ascii = "Calibri" }; rp.FontSize = new FontSize() { Val = new StringValue("26") }; shading = new Shading() { Val = ShadingPatternValues.Clear, Color = "auto" }; tcp.Shading = shading; for (int i = 0; i < tableData.Count; i++) { tc = new TableCell(); //TableStyle tableStyle = new TableStyle() { Val = "TableGrid" }; // Make the table width 100% of the page width. TableWidth tableWidth = new TableWidth() { Width = "5000", Type = TableWidthUnitValues.Dxa }; //tcp.Append(tableStyle, tableWidth); tcp.Append(tableWidth); if (i == 0 || i == 2 || i == 4) { tcp.TableCellWidth = new TableCellWidth() { Width = "4900", Type = TableWidthUnitValues.Dxa }; tc.Append((ParagraphProperties)ppr.Clone()); tc.Append((TableCellProperties)tcp.Clone()); } else { tcp.TableCellWidth = new TableCellWidth() { Width = "100", Type = TableWidthUnitValues.Dxa }; tc.Append((ParagraphProperties)ppl.Clone()); tc.Append((TableCellProperties)tcp.Clone()); } Run r = new Run(); r.PrependChild <RunProperties>((RunProperties)rp.Clone()); r.Append(new Text(tableData[i].ToString())); tc.Append(new Paragraph(r)); tr.Append(tc); } table.Append(tr); return(table); }
public Table AppendInvoiceTableInfo(List <string> tableData, Table table, bool header) { TableRow tr = new TableRow(); PreviousTablePropertyExceptions ptpex = new PreviousTablePropertyExceptions(); TableCellMarginDefault tcm = new TableCellMarginDefault(); tcm.TopMargin = new TopMargin() { Width = "0", Type = TableWidthUnitValues.Dxa }; tcm.BottomMargin = new BottomMargin() { Width = "0", Type = TableWidthUnitValues.Dxa }; ptpex.Append(tcm); tr.Append(ptpex); TableCell tc; TableCellProperties tcp = new TableCellProperties(new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center }); tcp.TableCellMargin = new TableCellMargin(new RightMargin() { Type = TableWidthUnitValues.Pct, Width = "50" }); tcp.TableCellMargin.LeftMargin = new LeftMargin() { Type = TableWidthUnitValues.Pct, Width = "50" }; tcp.TableCellMargin.TopMargin = new TopMargin() { Type = TableWidthUnitValues.Pct, Width = "1" }; ParagraphProperties ppp = new ParagraphProperties(new Justification() { Val = JustificationValues.Center }); ppp.Append(new KeepLines()); ppp.Append(new KeepNext()); SpacingBetweenLines sp = new SpacingBetweenLines(); sp.After = "0"; ppp.Append(sp); if (!header) { RunProperties rp = new RunProperties(new Bold() { Val = false }); Shading shading = new Shading(); rp.Bold.Val = false; rp.RunFonts = new RunFonts() { Ascii = "Calibri" }; rp.FontSize = new FontSize() { Val = new StringValue("22") }; //shading = new Shading() { Val = ShadingPatternValues.Clear, Color = "auto", Fill = "e3e6e7" }; shading = new Shading() { Val = ShadingPatternValues.Clear, Color = "auto" }; tcp.Shading = shading; for (int i = 0; i < tableData.Count; i++) { tc = new TableCell(); //TableStyle tableStyle = new TableStyle() { Val = "TableGrid" }; // Make the table width 100% of the page width. TableWidth tableWidth = new TableWidth() { Width = "50000", Type = TableWidthUnitValues.Auto }; tcp.Append(tableWidth); tc.Append((TableCellProperties)tcp.Clone()); tc.Append((ParagraphProperties)ppp.Clone()); Run r = new Run(); r.PrependChild <RunProperties>((RunProperties)rp.Clone()); r.Append(new Text(tableData[i].ToString())); tc.Append(new Paragraph(r)); tr.Append(tc); } } else { RunProperties rp = new RunProperties(new Bold() { Val = true }, new TabChar()); rp.Bold.Val = true; rp.RunFonts = new RunFonts() { Ascii = "Arial" }; rp.FontSize = new FontSize() { Val = new StringValue("20") }; //Color color = new Color() { Val = "365F91", ThemeColor = ThemeColorValues.Accent1, ThemeShade = "BF" }; Shading shading = new Shading() { Val = ShadingPatternValues.Clear, Color = "auto", Fill = "a7c6d7" }; //ppp.Shading = shading; tcp.TableCellMargin.TopMargin.Width = "200"; tcp.Shading = shading; for (int i = 0; i < tableData.Count; i++) { tc = new TableCell(); TableStyle tableStyle = new TableStyle() { Val = "TableGrid" }; // Make the table width 100% of the page width. TableWidth tableWidth = new TableWidth() { Width = "50000", Type = TableWidthUnitValues.Auto }; tcp.Append(tableStyle, tableWidth); tc.Append((TableCellProperties)tcp.Clone()); tc.Append((ParagraphProperties)ppp.Clone()); Run r = new Run(); r.PrependChild <RunProperties>((RunProperties)rp.Clone()); r.Append(new Text(tableData[i].ToString())); tc.Append(new Paragraph(r)); tr.Append(tc); } } table.Append(tr); return(table); }
//public static void AddText(Body body, ParagraphProperties paragraphProperties = null) public static IEnumerable <OpenXmlElement> CreateText_01(ParagraphProperties paragraphProperties = null) { //Paragraph paragraph = body.AppendChild(new Paragraph()); Paragraph paragraph = new Paragraph(); Run run = paragraph.AppendChild(new Run()); run.AppendChild(new DW.Text("zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo")); run.AppendChild(new Break()); run.AppendChild(new DW.Text("zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo")); run.AppendChild(new Break()); run.AppendChild(new DW.Text("zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo zozo")); yield return(paragraph); //paragraph = body.AppendChild(new Paragraph()); paragraph = new Paragraph(); if (paragraphProperties != null) { paragraph.ParagraphProperties = (ParagraphProperties)paragraphProperties.Clone(); } run = paragraph.AppendChild(new Run()); yield return(paragraph); //paragraph = body.AppendChild(new Paragraph()); paragraph = new Paragraph(); //if (paragraphProperties != null) // paragraph.ParagraphProperties = (ParagraphProperties)paragraphProperties.Clone(); run = paragraph.AppendChild(new Run()); run.AppendChild(new DW.Text("toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto")); run.AppendChild(new Break()); run.AppendChild(new DW.Text("toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto")); run.AppendChild(new Break()); run.AppendChild(new DW.Text("toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto toto")); yield return(paragraph); //paragraph = body.AppendChild(new Paragraph()); paragraph = new Paragraph(); if (paragraphProperties != null) { paragraph.ParagraphProperties = (ParagraphProperties)paragraphProperties.Clone(); } run = paragraph.AppendChild(new Run()); yield return(paragraph); //paragraph = body.AppendChild(new Paragraph()); paragraph = new Paragraph(); //if (paragraphProperties != null) // paragraph.ParagraphProperties = (ParagraphProperties)paragraphProperties.Clone(); run = paragraph.AppendChild(new Run()); run.AppendChild(new DW.Text("tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata")); run.AppendChild(new Break()); run.AppendChild(new DW.Text("tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata")); run.AppendChild(new Break()); run.AppendChild(new DW.Text("tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata tata")); yield return(paragraph); //paragraph = body.AppendChild(new Paragraph()); for (int i = 0; i < 11; i++) { paragraph = new Paragraph(); run = paragraph.AppendChild(new Run()); yield return(paragraph); } //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); //paragraph = body.AppendChild(new Paragraph()); //run = paragraph.AppendChild(new Run()); }