コード例 #1
0
        private static void setCellData(TableRow tr1, int index, string value)
        {
            var cell = tr1.Descendants <TableCell>().ElementAtOrDefault(index);

            DocumentFormat.OpenXml.Drawing.TextBody tb = cell.Elements <DocumentFormat.OpenXml.Drawing.TextBody>().First();
            Paragraph p = tb.Elements <Paragraph>().ElementAtOrDefault(0);
            Run       r = p.Elements <Run>().FirstOrDefault();

            //Run r = new Run();
            //RunProperties runProperties2 = new RunProperties() { Language = "en-US" };
            //DocumentFormat.OpenXml.Drawing.Text t = new DocumentFormat.OpenXml.Drawing.Text();
            //t.Text = value;
            //r.Append(runProperties2);
            //r.Append(t);
            //p.Append(r);
            if (r != null)
            {
                DocumentFormat.OpenXml.Drawing.Text t = r.Elements <DocumentFormat.OpenXml.Drawing.Text>().First();
                t.Text = value;
            }
            else
            {
            }
            //return t;
        }
コード例 #2
0
ファイル: TableBlock.cs プロジェクト: kevinfs/ReportGenerator
 private static void ModifyPowerPointCellTextContent(OpenXmlElement cell, string txt)
 {
     OXD.TextBody textbody = cell?.Descendants <OXD.TextBody>().FirstOrDefault();
     if (textbody == null)
     {
         return;
     }
     OXD.TextBody  final_textbody = textbody.CloneNode(true) as OXD.TextBody;
     OXD.Paragraph paragraph      = final_textbody?.Descendants <OXD.Paragraph>().FirstOrDefault();
     if (null != paragraph)
     {
         OXD.Paragraph final_paragraph = paragraph.CloneNode(true) as OXD.Paragraph;
         ModifyPowerPointParagraphTextContent(final_paragraph, txt);
         final_textbody.ReplaceChild(final_paragraph, paragraph);
     }
     cell.ReplaceChild(final_textbody, textbody);
 }
コード例 #3
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);
        }
コード例 #4
0
 private static void ModifyPowerPointCellTextContent(OXD.TableCell cell, string txt)
 {
     if (null != cell)
     {
         OXD.TextBody textbody = cell.Descendants <OXD.TextBody>().FirstOrDefault();
         if (null != textbody)
         {
             OXD.TextBody  final_textbody = textbody.CloneNode(true) as OXD.TextBody;
             OXD.Paragraph paragraph      = final_textbody.Descendants <OXD.Paragraph>().FirstOrDefault();
             if (null != paragraph)
             {
                 OXD.Paragraph final_paragraph = paragraph.CloneNode(true) as OXD.Paragraph;
                 ModifyPowerPointParagraphTextContent(final_paragraph, txt);
                 final_textbody.ReplaceChild <OXD.Paragraph>(final_paragraph, paragraph);
             }
             cell.ReplaceChild <OXD.TextBody>(final_textbody, textbody);
         }
     }
 }
コード例 #5
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();
                }
            }
        }
コード例 #6
0
        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);
        }
コード例 #7
0
ファイル: TableSlideWriter.cs プロジェクト: ayumax/MDToPPTX
        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);
        }