public static OpenXmlElement Paragraph(string Text, string Style, JustificationValues Alignment)
 {
     return(new Paragraph(
                new Run(
                    new Text(Text)
                    )
                )
     {
         ParagraphProperties = new ParagraphProperties(
             new Justification()
         {
             Val = Alignment
         },
             new KeepNext(),
             new KeepLines(),
             new SpacingBetweenLines()
         {
             Before = "0", After = "0"
         }
             )
         {
             ParagraphStyleId = new ParagraphStyleId()
             {
                 Val = Style
             }
         }
     });
 }
Example #2
0
        public static void AddParagraph(Body body, string idStyle, string text, JustificationValues justification = JustificationValues.Left)
        {
            Paragraph headingPar = CreateParagraphWithStyle(idStyle, justification);

            AddTextToParagraph(headingPar, text);
            body.AppendChild(headingPar);
        }
        private static bool GetJustificationValue(string style, out JustificationValues alignment)
        {
            alignment = JustificationValues.Left;
            bool assigned = false;

            switch (style.ToLower())
            {
                case right:
                    assigned = true;
                    alignment = JustificationValues.Right;
                    break;

                case left:
                    assigned = true;
                    alignment = JustificationValues.Left;
                    break;

                case center:
                    assigned = true;
                    alignment = JustificationValues.Center;
                    break;
            }

            return assigned;
        }
        private void AddParagraph(Body body, string idStyle, string text, JustificationValues justification = JustificationValues.Left)
        {
            Paragraph headingPar = wordUtils.CreateParagraphWithStyle(idStyle, justification);

            wordUtils.AddTextToParagraph(headingPar, text);
            body.AppendChild(headingPar);
        }
        private Paragraph CreateParagraph(string text, JustificationValues justification)
        {
            Paragraph paragraph = new Paragraph(
                new ParagraphProperties(
                    new ParagraphStyleId()
            {
                Val = "Bold"
            },
                    new Justification()
            {
                Val = justification
            },
                    new ParagraphMarkRunProperties()
                    ),
                new Run(
                    new RunProperties(new FontSize()
            {
                Val = "30"
            }, new Bold()
            {
                Val = OnOffValue.FromBoolean(true)
            }),
                    new Text(text)
            {
                Space = SpaceProcessingModeValues.Preserve
            }));

            return(paragraph);
        }
Example #6
0
        public static TableCell ValueCell(Run Value, JustificationValues Alignment, string Style)
        {
            TableCell tc = new TableCell(
                new Paragraph(
                    Value
                    )
            {
                ParagraphProperties = new ParagraphProperties(
                    new Justification()
                {
                    Val = Alignment
                },
                    new SpacingBetweenLines()
                {
                    Before = "0", After = "0"
                }
                    )
                {
                    ParagraphStyleId = new ParagraphStyleId()
                    {
                        Val = Style
                    }
                }
            }
                );

            return(tc);
        }
Example #7
0
 public static TableRow FieldTableRow(string Label, bool Value, JustificationValues Alignment, double LabelWidthPercent)
 {
     return(StickyTableRow(
                LabelCell(Label, Alignment).WithWidth(LabelWidthPercent),
                ValueCell(Value)
                ));
 }
        /// <summary>
        /// Создать новый подзаголовок
        /// </summary>
        /// <param name="NewRow"> Строка таблицы. </param>
        /// <returns></returns>
        private TableRow NewSubtitle(TablesRow NewRow)
        {
            UInt32 RowHeight        = 284U;
            int    LeftIndentation  = -113;
            int    RightIndentation = -113;
            JustificationValues JustificationValue = JustificationValues.Center;
            int      FontSize = 11;
            TableRow tableRow = CalibrationLib.NewTableRow(RowHeight);

            int[] CellWidthValues = GetCellWidthValues(NewRow);

            TableCell TableCell1 = tableRow.AddTableCell(CellWidthValues[0], NewRow.Values[0], LeftIndentation, RightIndentation, JustificationValue, FontSize, NewRow.GridSpan[0]);

            TableCell1.SetBorders(BorderValues.Single, BorderValues.Single, BorderValues.Single, BorderValues.Single);
            TableCell TableCell2 = tableRow.AddTableCell(CellWidthValues[1], NewRow.Values[1], LeftIndentation, RightIndentation, JustificationValue, FontSize, NewRow.GridSpan[1]);

            TableCell2.SetBorders(BorderValues.Single, BorderValues.Single, BorderValues.Single, BorderValues.Single);
            TableCell TableCell3 = tableRow.AddTableCell(CellWidthValues[2], NewRow.Values[2], LeftIndentation, RightIndentation, JustificationValue, FontSize, NewRow.GridSpan[2]);

            TableCell3.SetBorders(BorderValues.Single, BorderValues.Single, BorderValues.Single, BorderValues.Single);
            TableCell TableCell4 = tableRow.AddTableCell(CellWidthValues[3], NewRow.Values[3], LeftIndentation, RightIndentation, JustificationValue, FontSize, NewRow.GridSpan[3]);

            TableCell4.SetBorders(BorderValues.Single, BorderValues.Single, BorderValues.Single, BorderValues.Single);
            return(tableRow);
        }
Example #9
0
        public static TableCell LabelCell(string Label, JustificationValues Alignment)
        {
            TableCell tc = new TableCell(
                new Paragraph(
                    new Run(
                        new Text(Label)
                        )
                    )
            {
                ParagraphProperties = new ParagraphProperties(
                    new Justification()
                {
                    Val = Alignment
                },
                    new SpacingBetweenLines()
                {
                    Before = "0", After = "0"
                }
                    )
                {
                    ParagraphStyleId = new ParagraphStyleId()
                    {
                        Val = LSSDDocumentStyles.FieldLabel
                    }
                }
            }
                );

            return(tc);
        }
Example #10
0
        public void AddHeaderText(JustificationValues textPosition, string headerText, string fontSize = "18", bool isBold = true)
        {
            Paragraph           paragraph     = body.AppendChild(new Paragraph());
            Run                 run           = new Run();
            RunProperties       runProp       = new RunProperties();
            ParagraphProperties paraProp      = new ParagraphProperties();
            Justification       justification = new Justification()
            {
                Val = textPosition
            };

            paraProp.Append(justification);
            paragraph.Append(paraProp);
            if (isBold == true)
            {
                runProp.Bold = new Bold();
            }
            runProp.FontSize = new FontSize()
            {
                Val = fontSize
            };
            run.Append(runProp);
            run.AppendChild(new Text(headerText));
            paragraph.Append(run);
        }
Example #11
0
        private static bool GetJustificationValue(string style, out JustificationValues alignment)
        {
            alignment = JustificationValues.Left;
            bool assigned = false;

            switch (style.ToLower())
            {
            case right:
                assigned  = true;
                alignment = JustificationValues.Right;
                break;

            case left:
                assigned  = true;
                alignment = JustificationValues.Left;
                break;

            case center:
                assigned  = true;
                alignment = JustificationValues.Center;
                break;
            }

            return(assigned);
        }
        /// <summary>
        /// Создаёт ячейку таблицы.
        /// </summary>
        /// <param name="runProperties">Параметры текста.</param>
        /// <param name="aligment">Вертикальное выравнивание.</param>
        /// <param name="justification">Горизонтальное выравнивание.</param>
        /// <param name="text">Текст в ячейке.</param>
        /// <returns>Ячеёка таблицы.</returns>
        protected static TableCell CreateTableCell(
            string text,
            RunProperties runProperties,
            TableVerticalAlignmentValues aligment = TableVerticalAlignmentValues.Center,
            JustificationValues justification     = JustificationValues.Center)
        {
            var textLines = text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            var tableCell = new TableCell(
                new TableCellProperties(new TableCellVerticalAlignment {
                Val = aligment
            }));

            foreach (var line in textLines)
            {
                tableCell.AppendChild(
                    new Paragraph(
                        new ParagraphProperties(
                            new Justification {
                    Val = justification
                },
                            new SpacingBetweenLines {
                    Before = "0", After = "0"
                }),
                        new Run(
                            runProperties.CloneNode(true),
                            new Text
                {
                    Text  = line,
                    Space = SpaceProcessingModeValues.Preserve
                })));
            }

            return(tableCell);
        }
Example #13
0
        private static Paragraph CreateParagraph(string text, JustificationValues align = JustificationValues.Left, string font = "", string fontSize = "", bool isBold = false, bool isUnderlines = false)
        {
            Paragraph p = new Paragraph();

            Run r = new Run();

            RunProperties runProp = new RunProperties(); // Create run properties.
            RunFonts      runFont = new RunFonts();      // Create font

            runFont.Ascii = string.IsNullOrWhiteSpace(font) ? "Arial" : font;
            runProp.Append(runFont);

            if (!string.IsNullOrWhiteSpace(fontSize))
            {
                FontSize size = new FontSize();
                size.Val = new StringValue(fontSize);  // 48 half-point font size
                runProp.Append(size);
            }

            if (isBold)
            {
                runProp.Append(new Bold());
            }
            if (isUnderlines)
            {
                runProp.Append(new Underline());
            }

            r.PrependChild <RunProperties>(runProp);

            Text t = new Text(text);

            //Append elements appropriately.
            r.Append(t);

            p.Append(r);
            ParagraphProperties pp = p.ChildElements.First <ParagraphProperties>();

            var ppp = new ParagraphProperties {
                Justification = new Justification {
                    Val = JustificationValues.Right
                }
            };

            if (pp == null)
            {
                pp = new ParagraphProperties();
                p.InsertBefore(pp, p.First());
            }

            pp.Append(new Justification()
            {
                Val = align
            });
            pp.Append(new BiDi());
            //pp.Append(new TextDirection { Val = TextDirectionValues.TopToBottomRightToLeft });

            return(p);
        }
Example #14
0
        public OpenWordParagraph NewParagraph(JustificationValues align = JustificationValues.Left)
        {
            var par = new OpenWordParagraph();

            par.Align = align;
            m_Paragraphes.Add(par);
            return(par);
        }
Example #15
0
        protected void AddParagraph(Body body, JustificationValues justification, RunProperties runProperties, string text)
        {
            SetFontRunProperties(runProperties);
            var paragraph = body.AppendChild(new Paragraph()
            {
                ParagraphProperties = new ParagraphProperties()
                {
                    Justification = new Justification() { Val = justification }
                }
            });

            var run = paragraph.AppendChild(new Run() { RunProperties = runProperties });
            run.AppendChild(new Text(text));
        }
        // 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
                });
            }
        }
Example #17
0
 public Paragraph CreateParagraph(JustificationValues alignment)
 {
     if (alignment != JustificationValues.Left)
     {
         ParagraphProperties paraProp = new ParagraphProperties();
         paraProp.Append(new Justification()
         {
             Val = alignment
         });
         var para = CreateParagraph();
         para.Append(paraProp);
         return(para);
     }
     return(CreateParagraph());
 }
Example #18
0
        protected void AddParagraph(Body body, JustificationValues justification, List<Run> runs)
        {
            var paragraph = body.AppendChild(new Paragraph()
            {
                ParagraphProperties = new ParagraphProperties()
                {
                    Justification = new Justification() { Val = justification }
                }
            });

            foreach (var run in runs)
            {
                paragraph.AppendChild(run);
            }
        }
Example #19
0
        // needed since December 2009 CTP refactoring, where casting is not anymore an option

        public static TableRowAlignmentValues ToTableRowAlignment(this JustificationValues val)
        {
            if (val == JustificationValues.Center)
            {
                return(TableRowAlignmentValues.Center);
            }
            else if (val == JustificationValues.Right)
            {
                return(TableRowAlignmentValues.Right);
            }
            else
            {
                return(TableRowAlignmentValues.Left);
            }
        }
        /// <summary>
        /// Crea un paragrafo e lo aggiunge al documento.
        /// </summary>
        /// <param name="styleId"></param>
        /// <param name="justification"></param>
        /// <returns></returns>
        public static Paragraph CreateParagraphWithStyle(string styleId, JustificationValues justification = JustificationValues.Left)
        {
            Paragraph           paragraph = new Paragraph();
            ParagraphProperties pp        = new ParagraphProperties();

            pp.ParagraphStyleId = new ParagraphStyleId()
            {
                Val = styleId
            };
            pp.Justification = new Justification()
            {
                Val = justification
            };
            paragraph.Append(pp);
            return(paragraph);
        }
        /// <summary>
        /// Создать новую шапку таблицы.
        /// </summary>
        /// <param name="NewRow"> Строка таблицы. </param>
        /// <returns></returns>
        private TableRow NewHeader(TablesRow NewRow)
        {
            UInt32 RowHeight        = 284U;
            int    LeftIndentation  = -113;
            int    RightIndentation = -113;
            JustificationValues JustificationValue = JustificationValues.Left;
            int      FontSize = 11;
            TableRow tableRow = CalibrationLib.NewTableRow(RowHeight);

            int[] CellWidthValues = GetCellWidthValues(NewRow);

            TableCell TableCell1 = tableRow.AddTableCell(CellWidthValues[0], NewRow.Values[0], LeftIndentation, RightIndentation, JustificationValue, FontSize, NewRow.GridSpan[0]);

            TableCell1.SetBorders(BorderValues.Nil, BorderValues.Nil, BorderValues.Nil, BorderValues.Nil);
            return(tableRow);
        }
 /// <summary>
 /// Добавляет к строке таблицы объединённые ячейки.
 /// </summary>
 /// <param name="tableRow">Строка таблицы.</param>
 /// <param name="text">Текст в объединённой ячейки.</param>
 /// <param name="mergedCells">Количество объединяемых ячеек.</param>
 /// <param name="runProperties">Параметры текста.</param>
 /// <param name="aligment">Вертикальное выравнивание.</param>
 /// <param name="justification">Горизонтальное выравнивание.</param>
 protected void AppendMergedCellsToRow(
     TableRow tableRow,
     string text,
     int mergedCells,
     RunProperties runProperties,
     TableVerticalAlignmentValues aligment = TableVerticalAlignmentValues.Center,
     JustificationValues justification     = JustificationValues.Right)
 {
     for (var i = 0; i <= mergedCells; i++)
     {
         tableRow.AppendChild(
             i == 0
                 ? CreateTableCellForMerging(text, true, runProperties, aligment, justification)
                 : CreateTableCellForMerging(string.Empty, false, runProperties, aligment, justification));
     }
 }
Example #23
0
        public static Paragraph CreateParagraphWithStyle(string styleId, JustificationValues justification)
        {
            Paragraph           paragraph = new Paragraph();
            ParagraphProperties pp        = new ParagraphProperties();

            paragraph.Append(pp);
            // we set the style
            pp.ParagraphStyleId = new ParagraphStyleId()
            {
                Val = styleId
            };
            // we set the alignement
            pp.Justification = new Justification()
            {
                Val = justification
            };
            return(paragraph);
        }
Example #24
0
        /// <summary>
        /// Создает и настраивает Параграф выполнить 1 раз
        /// </summary>
        /// <param name="justifications">Выравнивание</param>
        /// <param name="leftident">Отступ слева</param>
        /// <returns></returns>
        public Paragraph GeneratorParagraph(JustificationValues justifications, string leftident = "0")
        {
            Paragraph   paragraph = new Paragraph();
            Indentation indental  = new Indentation()
            {
                Left = leftident
            };
            ParagraphProperties paragraphProperties = new ParagraphProperties();
            Justification       justification       = new Justification()
            {
                Val = justifications
            };

            paragraphProperties.Append(indental);
            paragraphProperties.Append(justification);
            paragraph.Append(paragraphProperties);
            return(paragraph);
        }
        /// <summary>
        /// Создать обычную строку
        /// </summary>
        /// <param name="NewRow"> Строка таблицы. </param>
        /// <returns></returns>
        private TableRow NewSimpleRow(TablesRow NewRow)
        {
            UInt32 RowHeight        = 284U;
            int    LeftIndentation  = -113;
            int    RightIndentation = -113;
            JustificationValues JustificationValue = JustificationValues.Center;
            int      FontSize = 11;
            TableRow tableRow = CalibrationLib.NewTableRow(RowHeight);

            int[] CellWidthValues = GetCellWidthValues(NewRow);

            for (int i = 0; i < NewRow.Values.Count(); i++)
            {
                TableCell tableCell = tableRow.AddTableCell(CellWidthValues[i], NewRow.Values[i], LeftIndentation, RightIndentation, JustificationValue, FontSize, NewRow.GridSpan[i]);
                tableCell.SetBorders(BorderValues.Single, BorderValues.Single, BorderValues.Single, BorderValues.Single);
            }
            return(tableRow);
        }
Example #26
0
        protected void AddParagraph(Body body, JustificationValues justification, List <Run> runs)
        {
            var paragraph = body.AppendChild(new Paragraph()
            {
                ParagraphProperties = new ParagraphProperties()
                {
                    Justification = new Justification()
                    {
                        Val = justification
                    }
                }
            });

            foreach (var run in runs)
            {
                paragraph.AppendChild(run);
            }
        }
Example #27
0
        private void AddParagraph(string title, bool bold = false, bool italic = false, string alignment = "left", int fontsize = 24)
        {
            RunProperties rp = new RunProperties(new RunFonts()
            {
                Ascii = "Times New Roman"
            }, new FontSize()
            {
                Val = (fontsize * 2).ToString()
            });

            if (bold)
            {
                rp.Bold = new Bold();
            }
            if (italic)
            {
                rp.Italic = new Italic();
            }
            JustificationValues val = JustificationValues.Left;

            switch (alignment)
            {
            case "left":
                val = JustificationValues.Left;
                break;

            case "center":
                val = JustificationValues.Center;
                break;

            case "right":
                val = JustificationValues.Right;
                break;
            }
            WordDoc.MainDocumentPart.Document.Body.AppendChild(new Paragraph(
                                                                   new ParagraphProperties(new Justification()
            {
                Val = val
            }),
                                                                   new Run(rp, new Text(title))
                                                                   ));
        }
Example #28
0
        public static void ApplyStyleToParagraph(WordprocessingDocument document, string styleId,
                                                 string styleName, Paragraph p, JustificationValues justification = JustificationValues.Left)
        {
            // If the paragraph has no ParagraphProperties object, create one.
            if (!p.Elements <ParagraphProperties>().Any())
            {
                p.PrependChild(new ParagraphProperties
                {
                    Justification = new Justification {
                        Val = justification
                    }
                });
            }

            // Get the paragraph properties element of the paragraph.
            var pPr = p.Elements <ParagraphProperties>().First();

            // Get the Styles part for this document.
            var part =
                document.MainDocumentPart.StyleDefinitionsPart;

            /*
             * // If the Styles part does not exist, add it and then add the style.
             * if (part != null)
             * {
             *  // If the style is not in the document, add it.
             *  if (IsStyleIdInDocument(PrintController.StylesPart, styleId) != true)
             *  {
             *      // No match on styleId, so let's try style name.
             *      var fromStyleName = GetStyleIdFromStyleName(PrintController.StylesPart, styleName);
             *      if (fromStyleName != null)
             *
             *          styleId = fromStyleName;
             *  }
             * }
             */
            // Set the style of the paragraph.
            pPr.ParagraphStyleId = new ParagraphStyleId()
            {
                Val = styleId
            };
        }
Example #29
0
        protected void AddParagraph(Body body, JustificationValues justification, RunProperties runProperties, string text)
        {
            SetFontRunProperties(runProperties);
            var paragraph = body.AppendChild(new Paragraph()
            {
                ParagraphProperties = new ParagraphProperties()
                {
                    Justification = new Justification()
                    {
                        Val = justification
                    }
                }
            });

            var run = paragraph.AppendChild(new Run()
            {
                RunProperties = runProperties
            });

            run.AppendChild(new Text(text));
        }
Example #30
0
        public static void FillTextBox(this SdtContentCell content, string newText, JustificationValues alignment)
        {
            if (content != null)
            {
                // Retrieve old paragraph to get the current style of text
                Paragraph oldParagraph = content.Descendants <TableCell>().FirstOrDefault().Elements <Paragraph>().FirstOrDefault();

                // Create a new text
                var paragraph = CreateParagraph(oldParagraph, newText, alignment);

                // Replace old text with new one
                if (oldParagraph != null)
                {
                    content.Descendants <TableCell>().FirstOrDefault().ReplaceChild(paragraph, oldParagraph);
                }
                else
                {
                    content.Descendants <TableCell>().FirstOrDefault().Append(paragraph);
                }
            }
        }
        /// <summary>
        /// Создаёт ячейку таблицы, предназначенную для объединения.
        /// </summary>
        /// <param name="text">Текст в ячейке.</param>
        /// <param name="isFirstCellInMerge">Ячейка является первой по порядку среди объединяемых ячеек.</param>
        /// <param name="runProperties">Параметры текста.</param>
        /// <param name="aligment">Вертикальное выравнивание.</param>
        /// <param name="justification">Горизонтальное выравнивание.</param>
        /// <returns>Ячейка таблицы для объединения.</returns>
        private static TableCell CreateTableCellForMerging(
            string text,
            bool isFirstCellInMerge,
            RunProperties runProperties,
            TableVerticalAlignmentValues aligment,
            JustificationValues justification)
        {
            var cellProperties = new TableCellProperties(
                new HorizontalMerge
            {
                Val =
                    isFirstCellInMerge
                            ? MergedCellValues.Restart
                            : MergedCellValues.Continue
            });

            var cellForMerging = CreateTableCell(text, runProperties, aligment, justification);

            cellForMerging.AppendChild(cellProperties);

            return(cellForMerging);
        }
Example #32
0
        private Paragraph AddParagraph(Run[] runs, JustificationValues justify = JustificationValues.Left)
        {
            var paragraph = new Paragraph();

            var paragraphProperties = new ParagraphProperties()
            {
                SpacingBetweenLines = new SpacingBetweenLines()
                {
                    Before = new StringValue("10"), After = new StringValue("10")
                },
                Justification = new Justification()
                {
                    Val = justify
                }
            };

            paragraph.Append(paragraphProperties);
            foreach (var run in runs)
            {
                paragraph.Append(run);
            }
            return(paragraph);
        }
Example #33
0
 private OpenXmlElement AlignParagraph(JustificationValues align)
 {
     return(new Justification {
         Val = new EnumValue <JustificationValues>(align)
     });
 }
		private OpenXmlElement AlignParagraph(JustificationValues align)
		{
			return new Justification { Val = new EnumValue<JustificationValues>(align) };
		}
 private void AppendTableCell(TableRow tr, JustificationValues align)
 {
     Run run = GetTableCellRun(tr, 0, 0, align, 0, false);
 }
    private Run GetTableCellRun(TableRow tr, int width, int gridSpan, JustificationValues justification, int fontSize, bool globalTC)
    {
        TableCell tcRun = new TableCell();
        TableCellProperties properties = new TableCellProperties();
        if(width > 0)
            properties.Append(new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = StringValue.FromString(width.ToString()) });

        if (gridSpan > 0)
            properties.Append(new GridSpan() { Val = gridSpan });

        tcRun.Append(properties);
        
        paragraph = new Paragraph();
        ParagraphProperties paraProperties = new ParagraphProperties();
        paraProperties.Append(new Justification() { Val = justification });
        paraProperties.Append(new SpacingBetweenLines() { After = "10", Line = "240", LineRule = LineSpacingRuleValues.Auto });

        paragraph.Append(paraProperties);
        Run run = new Run();

        if (fontSize != 0)
        {
            RunProperties runProperties = new RunProperties();
            FontSize size = new FontSize();
            size.Val = StringValue.FromString(fontSize.ToString());
            runProperties.Append(size);
            run.Append(runProperties);
        }

        paragraph.Append(run);
        tcRun.Append(paragraph);
        tr.Append(tcRun);

        //if (globalTC)
        //    tcLetter = tcRun;
        firstLine = false;
        return run;
    }