Example #1
0
        /// <summary>
        /// Create table cell with the below order:
        /// a:tc(TableCell)->a:txbody(TextBody)->a:p(Paragraph)->a:r(Run)->a:t(Text)
        /// </summary>
        /// <param name="text">Inserted Text in Cell</param>
        /// <returns>Return TableCell object</returns>
        private static A.TableCell CreateTextCell(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                text = string.Empty;
            }

            // Declare and instantiate the table cell
            // Create table cell with the below order:
            // a:tc(TableCell)->a:txbody(TextBody)->a:p(Paragraph)->a:r(Run)->a:t(Text)
            A.TableCell tableCell = new A.TableCell();

            //  Declare and instantiate the text body
            A.TextBody       textBody       = new A.TextBody();
            A.BodyProperties bodyProperties = new A.BodyProperties();
            A.ListStyle      listStyle      = new A.ListStyle();

            A.Paragraph     paragraph     = new A.Paragraph();
            A.Run           run           = new A.Run();
            A.RunProperties runProperties = new A.RunProperties()
            {
                Language = "en-US", Dirty = false, SmartTagClean = false
            };
            A.Text text2 = new A.Text();
            text2.Text = text;
            run.Append(runProperties);
            run.Append(text2);
            A.EndParagraphRunProperties endParagraphRunProperties = new A.EndParagraphRunProperties()
            {
                Language = "en-US", Dirty = false
            };

            paragraph.Append(run);
            paragraph.Append(endParagraphRunProperties);
            textBody.Append(bodyProperties);
            textBody.Append(listStyle);
            textBody.Append(paragraph);

            A.TableCellProperties tableCellProperties = new A.TableCellProperties();
            tableCell.Append(textBody);
            tableCell.Append(tableCellProperties);

            return(tableCell);
        }
Example #2
0
        private void MergeParagraphs(int minRowIndex, int minColIndex, A.TableCell aTblCell)
        {
            A.TextBody mergedCellTextBody = ((SCTableCell)this[minRowIndex, minColIndex]).ATableCell.TextBody;
            bool       hasMoreOnePara     = false;
            IEnumerable <A.Paragraph> aParagraphsWithARun =
                aTblCell.TextBody.Elements <A.Paragraph>().Where(p => !p.IsEmpty());

            foreach (A.Paragraph aParagraph in aParagraphsWithARun)
            {
                mergedCellTextBody.Append(aParagraph.CloneNode(true));
                hasMoreOnePara = true;
            }

            if (hasMoreOnePara)
            {
                foreach (A.Paragraph aParagraph in mergedCellTextBody.Elements <A.Paragraph>().Where(p => p.IsEmpty()))
                {
                    aParagraph.Remove();
                }
            }
        }
        private static TableCell CreateTextCell(string text)
        {
            var textCol = new string[2];

            if (!string.IsNullOrEmpty(text))
            {
                if (text.Length > 25)
                {
                    textCol[0] = text.Substring(0, 25);
                    textCol[1] = text.Substring(26);
                }
                else
                {
                    textCol[0] = text;
                }
            }
            else
            {
                textCol[0] = string.Empty;
            }


            TableCell tableCell3 = new TableCell();

            //DocumentFormat.OpenXml.Drawing.TextBody textBody1 = tableCell3.GetFirstChild<DocumentFormat.OpenXml.Drawing.TextBody>();

            DocumentFormat.OpenXml.Drawing.TextBody textBody3 = new DocumentFormat.OpenXml.Drawing.TextBody();
            //BodyProperties bodyProperties3 = new BodyProperties();

            //ListStyle listStyle3 = new ListStyle();

            //textBody3.Append(bodyProperties3);
            //textBody3.Append(listStyle3);


            var nonNull = textCol.Where(t => !string.IsNullOrEmpty(t)).ToList();

            foreach (var textVal in nonNull)
            {
                //if (!string.IsNullOrEmpty(textVal))
                //{
                Paragraph     paragraph3     = new Paragraph();
                Run           run2           = new Run();
                RunProperties runProperties2 = new RunProperties()
                {
                    Language = "en-US", Underline = TextUnderlineValues.DashHeavy
                };
                DocumentFormat.OpenXml.Drawing.Text text2 = new DocumentFormat.OpenXml.Drawing.Text();
                text2.Text = textVal;
                run2.Append(runProperties2);
                run2.Append(text2);
                paragraph3.Append(run2);
                textBody3.Append(paragraph3);
                //}
            }

            TableCellProperties tableCellProperties3 = new TableCellProperties();

            tableCell3.Append(textBody3);
            tableCell3.Append(tableCellProperties3);



            //var tc = new A.TableCell(
            //                    new A.TextBody(
            //                        new A.BodyProperties(),
            //                    new A.Paragraph(
            //                        new A.Run(
            //                            new A.Text(text)))),
            //                    new A.TableCellProperties());

            //return tc;
            return(tableCell3);
        }
Example #4
0
        private A.TableRow CreateRow(List <PPTXTableColumn> Cols, PPTXTableRow Row, Dictionary <string, string> HyperLinkIDMap)
        {
            A.TableRow tableRow1 = new A.TableRow()
            {
                Height = (Int64)(Row.Height * 100)
            };

            foreach (var Cell in Cols.Select((Col, ColIndex) => new { Col = Col, ColIndex = ColIndex }))
            {
                A.TableCell tableCell1 = new A.TableCell();

                A.TextBody       textBody1       = new A.TextBody();
                A.BodyProperties bodyProperties1 = new A.BodyProperties();
                A.ListStyle      listStyle1      = new A.ListStyle();

                textBody1.Append(bodyProperties1);
                textBody1.Append(listStyle1);

                var _texts = Row.Cells[Cell.ColIndex].Texts.Texts;
                if (_texts.Count == 0)
                {
                    _texts.Add(new PPTXTextRun());
                }

                foreach (var _textLine in _texts)
                {
                    var paragraph = new A.Paragraph();

                    var cellAlign = A.TextAlignmentTypeValues.Center;
                    switch (Cell.Col.Alignment)
                    {
                    case PPTXTableColumnAlign.Left:
                        cellAlign = A.TextAlignmentTypeValues.Left;
                        break;

                    case PPTXTableColumnAlign.Right:
                        cellAlign = A.TextAlignmentTypeValues.Right;
                        break;
                    }

                    paragraph.Append(new A.ParagraphProperties()
                    {
                        Alignment = cellAlign
                    });

                    paragraph.Append(new A.Run()
                    {
                        RunProperties = SlideWriterHelper.CreateRunProperties(_textLine, HyperLinkIDMap),
                        Text          = new A.Text(_textLine.Text)
                    });

                    textBody1.Append(paragraph);
                }

                A.TableCellProperties tableCellProperties1 = new A.TableCellProperties();

                tableCell1.Append(textBody1);
                tableCell1.Append(tableCellProperties1);

                tableRow1.Append(tableCell1);
            }


            A.ExtensionList extensionList4 = new A.ExtensionList();

            tableRow1.Append(extensionList4);

            return(tableRow1);
        }