Beispiel #1
0
        private static TableCell SetupCell(HetOwner owner, double widthInCm, double start)
        {
            try
            {
                var tableCell = new TableCell();

                var tableCellProperties = new TableCellProperties();
                tableCellProperties.AppendChild(new TableCellWidth {
                    Width = CentimeterToDxa(widthInCm).ToString(), Type = TableWidthUnitValues.Dxa
                });
                tableCellProperties.AppendChild(new TableCellVerticalAlignment()
                {
                    Val = TableVerticalAlignmentValues.Center
                });
                tableCell.AppendChild(tableCellProperties);

                var paragraphProperties = new ParagraphProperties();

                var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
                paragraphMarkRunProperties.AppendChild(new Color {
                    Val = "000000"
                });
                paragraphMarkRunProperties.AppendChild(new RunFonts {
                    Ascii = "Arial"
                });
                paragraphMarkRunProperties.AppendChild(new FontSize()
                {
                    Val = "13pt"
                });
                paragraphProperties.AppendChild(paragraphMarkRunProperties);

                paragraphProperties.AppendChild(new Justification {
                    Val = JustificationValues.Left
                });
                paragraphProperties.AppendChild(new Indentation {
                    Start = CentimeterToDxa(start).ToString()
                });

                var paragraph = new Paragraph();
                paragraph.AppendChild(paragraphProperties);

                if (owner != null)
                {
                    PopulateParagraph(owner, paragraph);
                }

                tableCell.AppendChild(paragraph);

                return(tableCell);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Beispiel #2
0
        private static TableCell CreateCell(string text, string width = null, string backgroundColor = null, string style = null, JustificationValues?justifyContent = null)
        {
            var cell       = new TableCell();
            var properties = cell.AppendChild(new TableCellProperties());

            if (width != null)
            {
                properties.AppendChild(new TableCellWidth {
                    Width = width, Type = TableWidthUnitValues.Dxa
                });
            }
            if (backgroundColor != null)
            {
                properties.AppendChild(new Shading
                {
                    Color = "auto",
                    Fill  = backgroundColor,
                    Val   = ShadingPatternValues.Clear
                });
            }
            var paragraph           = cell.AppendChild(new Paragraph());
            var paragraphProperties = paragraph.AppendChild(new ParagraphProperties());

            if (justifyContent.HasValue)
            {
                paragraphProperties.AppendChild(new Justification {
                    Val = JustificationValues.Right
                });
            }

            if (style != null)
            {
                paragraph.AppendChild(new ParagraphProperties
                {
                    ParagraphStyleId = new ParagraphStyleId {
                        Val = style
                    }
                });
            }
            var run = paragraph.AppendChild(new Run());

            if (style != null)
            {
                run.AppendChild(new RunProperties
                {
                    RunStyle = new RunStyle {
                        Val = style
                    }
                });
            }

            run.AppendChild(new Text(text));
            return(cell);
        }
Beispiel #3
0
        private TableCell SetTableCell(string textVal = null, int fontsize = 22, bool isBold = false)
        {
            TableCell           tableCell            = new TableCell();
            TableCellProperties tableCellProperties1 = new TableCellProperties();

            //TableCellWidth tableCellWidth1 = new TableCellWidth() { Width = "1175", Type = TableWidthUnitValues.Dxa };
            //tableCellProperties1.Append(tableCellWidth1);
            tableCellProperties1.Append(SetTableCellBorders());
            tableCell.AppendChild(tableCellProperties1);
            tableCell.AppendChild(SetParagraph(textVal, fontsize, isBold));

            return(tableCell);
        }
        private static void FormatCell(int row, int col, FStyle[] styles)                       // Changes formatting of a specific cell
        {
            TableRow tRow = tab.Elements <TableRow>().ElementAt(row);

            TableCell tCell = tRow.Elements <TableCell>().ElementAt(col);

            Paragraph par = tCell.Elements <Paragraph>().Count() == 0 ?
                            tCell.AppendChild(new Paragraph()) :
                            tCell.Elements <Paragraph>().First();

            Run run = par.Elements <Run>().Count() == 0 ?
                      par.AppendChild(new Run()) :
                      par.Elements <Run>().First();

            foreach (FStyle st in styles)
            {
                switch (st)
                {
                case FStyle.Bold:
                    run.Elements <RunProperties>().First().Append(new Bold());
                    break;

                case FStyle.Italic:
                    run.Elements <RunProperties>().First().Append(new Italic());
                    break;

                case FStyle.Strike:
                    run.Elements <RunProperties>().First().Append(new Strike());
                    break;
                }
            }
        }
        /// <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);
        }
Beispiel #6
0
        private void SetCellValue(TableCell cell, string value)
        {
            var paragraph = cell.Elements <Paragraph>().FirstOrDefault();

            if (paragraph == null)
            {
                paragraph = new Paragraph();
                cell.AppendChild(paragraph);
            }
            var run = paragraph.Elements <Run>().FirstOrDefault();

            if (run == null)
            {
                run = new Run();
                paragraph.AppendChild(run);
            }
            var text = run.Elements <Text>().FirstOrDefault();

            if (text == null)
            {
                text = new Text();
                run.AppendChild(text);
            }
            text.Text = value;
        }
        //向下插入資料並保持原格式
        public static void TableRowInsert(Table tb, DataTable data)
        {
            foreach (DataRow dr in data.Rows)
            {
                TableRow tr = (TableRow)tb.Elements <TableRow>().Last().CloneNode(true);

                for (int i = 0; i < data.Columns.Count; i++)
                {
                    TableCell tc = tr.Elements <TableCell>().ElementAt(i);

                    Paragraph p = tc.Elements <Paragraph>().FirstOrDefault() ?? new Paragraph();
                    if (p.Parent == null)
                    {
                        tc.AppendChild <Paragraph>(p);
                    }
                    Run  r    = (Run)(p.Elements <Run>().FirstOrDefault() ?? new Run()).CloneNode(true);
                    Text text = r.Elements <Text>().FirstOrDefault() ?? new Text();
                    if (text.Parent == null)
                    {
                        r.AppendChild <Text>(text);
                    }
                    text.Text = dr[i].ToString();
                    p.RemoveAllChildren <Run>();
                    p.AppendChild <Run>(r);
                }
                tb.AppendChild <TableRow>(tr);
            }
        }
Beispiel #8
0
        protected override void AppendChildrenToElement(HtmlElement elm)
        {
            int rows = Int32.Parse((Math.Ceiling((Double)Children.Count / (Double)Width)).ToString());

            // Create grid structure and put child elements in it
            TableRow  tr;
            TableCell td;
            Component child;
            int       c = 0;

            for (int i = 0; i < rows; i++)
            {
                tr = new TableRow();
                for (int j = 0; j < Width; j++)
                {
                    td           = new TableCell();
                    td.ClassName = "ms-cui-gallery-td ms-cui-gallery-element-" + ElementDimensions.ToString();

                    // Insert empty cells to finish out row when out of children
                    if (c < Children.Count)
                    {
                        child = (Component)Children[c++];
                        child.EnsureDOMElement();
                        td.AppendChild(child.ElementInternal);
                        child.EnsureRefreshed();
                    }
                    tr.AppendChild(td);
                }
                elm.AppendChild(tr);
            }
        }
        private void ProcessVerticalSpan(ref int colIndex, TableRow row, DocxTableProperties docxProperties)
        {
            int rowSpan;

            docxProperties.RowSpanInfo.TryGetValue(colIndex, out rowSpan);

            while (rowSpan > 0)
            {
                TableCell cell = new TableCell();

                cell.TableCellProperties = new TableCellProperties();
                cell.TableCellProperties.Append(new VerticalMerge());
                // There should be a more elegant solution for drawing borders.
                cell.TableCellProperties.Append(new LeftBorder()
                {
                    Val   = BorderValues.Single,
                    Color = "auto",
                    Size  = (UInt32Value)4U,
                    Space = (UInt32Value)0U
                });
                //
                cell.AppendChild(new Paragraph());

                row.Append(cell);

                docxProperties.RowSpanInfo[colIndex] = --rowSpan;
                ++colIndex;
                docxProperties.RowSpanInfo.TryGetValue(colIndex, out rowSpan);
            }
        }
Beispiel #10
0
        TableCell GenerateCell(OpenXmlElement Content)
        {
            TableCell Cell = new TableCell();

            Cell.AppendChild(new TableCellProperties());
            Cell.Append(Content);
            return(Cell);
        }
Beispiel #11
0
 public static TableCell WithColspan(this TableCell TC, int Columns)
 {
     TC.AppendChild(new TableCellProperties(new GridSpan()
     {
         Val = Columns
     }));
     return(TC);
 }
Beispiel #12
0
 public static TableCell WithWidth(this TableCell TC, double WidthPercent)
 {
     TC.AppendChild(new TableCellWidth()
     {
         Width = $"{WidthPercent * 50}", Type = TableWidthUnitValues.Pct
     });
     return(TC);
 }
        public static void Run()
        {
            // ExStart:CreateTableWithLockedColumns
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Tables();

            // Create an object of the Document class
            Document doc = new Document();

            // Initialize Page class object
            Aspose.Note.Page page = new Aspose.Note.Page(doc);

            // Initialize TableRow class object
            TableRow row1 = new TableRow(doc);
            // Initialize TableCell class object and set text content
            TableCell cell11 = new TableCell(doc);

            cell11.AppendChild(InsertTable.GetOutlineElementWithText(doc, "Small text"));
            row1.AppendChild(cell11);

            // Initialize TableRow class object
            TableRow row2 = new TableRow(doc);
            // Initialize TableCell class object and set text content
            TableCell cell21 = new TableCell(doc);

            cell21.AppendChild(InsertTable.GetOutlineElementWithText(doc, "Long   text    with    several   words and    spaces."));
            row2.AppendChild(cell21);

            // Initialize Table class object
            Table table = new Table(doc)
            {
                IsBordersVisible = true,
                Columns          = { new TableColumn {
                                         Width = 70, LockedWidth = true
                                     } }
            };

            // Add rows
            table.AppendChild(row1);
            table.AppendChild(row2);

            Outline        outline     = new Outline(doc);
            OutlineElement outlineElem = new OutlineElement(doc);

            // Add table node
            outlineElem.AppendChild(table);
            // Add outline element node
            outline.AppendChild(outlineElem);
            // Add outline node
            page.AppendChild(outline);
            // Add page node
            doc.AppendChild(page);
            dataDir = dataDir + "CreateTableWithLockedColumns_out_.one";
            doc.Save(dataDir);
            // ExEnd:CreateTableWithLockedColumns

            Console.WriteLine("\nTable with locked columns created successfully.\nFile saved at " + dataDir);
        }
Beispiel #14
0
        private static TableCell CreateCell(string text, bool?isThead = false)
        {
            var cell      = new TableCell();
            var paragraph = new Paragraph(new Run(new Text(text)));
            ParagraphProperties paragraphProperties = new ParagraphProperties();
            TableCellProperties cellProperties      = new TableCellProperties();

            cellProperties.AppendChild(new TableCellVerticalAlignment()
            {
                Val = TableVerticalAlignmentValues.Center
            });
            cellProperties.AppendChild(new Justification()
            {
                Val = JustificationValues.Center
            });

            TableCellWidth cellWidth = new TableCellWidth()
            {
                Type = TableWidthUnitValues.Auto
            };

            if (isThead.HasValue && isThead.Value)
            {
                paragraphProperties.AppendChild(new Justification()
                {
                    Val = JustificationValues.Center
                });
            }
            else
            {
                paragraphProperties.AppendChild(new Justification()
                {
                    Val = JustificationValues.Left
                });
            }
            paragraphProperties.AppendChild(new TextAlignment()
            {
                Val = VerticalTextAlignmentValues.Center
            });
            cell.AppendChild(cellWidth);
            cell.AppendChild(cellProperties);
            cell.AppendChild(paragraphProperties);
            cell.AppendChild(paragraph);
            return(cell);
        }
Beispiel #15
0
        /// <summary>
        /// Remplacer les éléments trouvés.
        /// </summary>
        /// <param name="currentPart">OpenXmlPart courant.</param>
        /// <param name="currentXmlElement">XmlElement courant.</param>
        /// <param name="currentDataSource">Source de données courante.</param>
        /// <param name="documentId">Id document en cours.</param>
        /// <param name="isXmlData">Si la source en xml.</param>
        public static void Process(OpenXmlPart currentPart, CustomXmlElement currentXmlElement, object currentDataSource, Guid documentId, bool isXmlData)
        {
            using (ITagHandler tagHandler = CreateTagHandler(currentPart, currentXmlElement, currentDataSource, documentId, isXmlData)) {
                IEnumerable <OpenXmlElement> newElementList = tagHandler.HandleTag();
                OpenXmlElement parent = currentXmlElement.Parent;
                if (newElementList == null)
                {
                    if (currentXmlElement.Parent.GetType() != typeof(Paragraph) && currentXmlElement.Parent.GetType() != typeof(TableRow) && currentXmlElement.Parent.GetType() != typeof(Table) && currentXmlElement.Parent.GetType() != typeof(Body) && currentXmlElement.Parent.GetType() != typeof(CustomXmlRow))
                    {
                        Paragraph p = new Paragraph();
                        if (currentXmlElement.Parent.GetType() == typeof(TableCell))
                        {
                            if (currentXmlElement.Descendants <ParagraphProperties>() != null)
                            {
                                IEnumerator <ParagraphProperties> ppEnum = currentXmlElement.Descendants <ParagraphProperties>().GetEnumerator();
                                ppEnum.MoveNext();
                                if (ppEnum.Current != null)
                                {
                                    p.AppendChild <OpenXmlElement>(ppEnum.Current.CloneNode(true));
                                }
                            }
                        }

                        parent.InsertBefore(p, currentXmlElement);
                    }
                    else if (parent.GetType() == typeof(TableRow))
                    {
                        Paragraph p2 = new Paragraph();
                        TableCell tc = new TableCell();
                        if (currentXmlElement.Descendants <ParagraphProperties>() != null)
                        {
                            IEnumerator <ParagraphProperties> ppEnum = currentXmlElement.Descendants <ParagraphProperties>().GetEnumerator();
                            ppEnum.MoveNext();
                            p2.AppendChild <OpenXmlElement>(ppEnum.Current.CloneNode(true));
                        }

                        tc.AppendChild <Paragraph>(p2);
                        parent.InsertBefore(tc, currentXmlElement);
                    }
                }
                else
                {
                    OpenXmlElement lastElement = currentXmlElement;
                    foreach (OpenXmlElement currentChild in newElementList)
                    {
                        OpenXmlElement currentChildClone = (OpenXmlElement)currentChild;
                        parent.InsertAfter(currentChildClone, lastElement);
                        lastElement = currentChildClone;
                    }

                    newElementList = null;
                }

                currentXmlElement.Remove();
                currentXmlElement = null;
            }
        }
Beispiel #16
0
        internal override OpenXmlElement Render(int index, bool isFirst, bool isLast)
        {
            var result = new TableCell(_config.CellProperties());

            var elements = _config.Contents.Where(x => x != null).AsIndexed().ToList();

            if (!elements.Any())
            {
                result.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Paragraph());
            }

            foreach (var element in elements)
            {
                result.AppendChild(element.Value.Render(element.Index, element.IsFirst, element.IsLast));
            }

            return(result);
        }
Beispiel #17
0
        private Table CreateTitleTable(string title)
        {
            var table = new Table();

            // Append the TableProperties object to the empty table.
            table.AppendChild <TableProperties>(WordTableFormats.TitleTableFormat());

            // Create a row.
            var tr = new TableRow(new TableRowProperties(new TableRowHeight()
            {
                Val = Convert.ToUInt32(500)
            }));

            // Create a cell.
            var tc = new TableCell();

            var rp = new RunProperties(new RunFonts()
            {
                Ascii = "Times New Roman"
            }, new Bold(), new FontSize()
            {
                Val = "24"
            });


            // Specify the table cell content.
            tc.AppendChild(new TableCellProperties(new TableCellVerticalAlignment()
            {
                Val = TableVerticalAlignmentValues.Center
            }));
            tc.AppendChild(new Paragraph(new ParagraphProperties(new Justification()
            {
                Val = JustificationValues.Center
            }), new Run(rp, new Text(title))));

            // Append the table cell to the table row.
            tr.AppendChild(tc);

            // Append the table row to the table.
            table.AppendChild(tr);

            return(table);
        }
Beispiel #18
0
        private void CreateMergedColumn(TableCell tableCell, string text, string width, bool isBold = false)
        {
            var run = new Run();

            if (!string.IsNullOrEmpty(text))
            {
                ParseTextForOpenXml(run, text, isBold);
            }

            tableCell.AppendChild(new Paragraph(run));

            tableCell.AppendChild(new TableCellProperties
            {
                TableCellWidth = new TableCellWidth
                {
                    Width = width
                }
            });
        }
Beispiel #19
0
        /// <summary>
        /// set cell margin (null values are left unchanged)
        /// </summary>
        public static void SetMargin(this TableCell cell, double?marginLeftMM = null,
                                     double?marginTopMM    = null,
                                     double?marginRightMM  = null,
                                     double?marginBottomMM = null)
        {
            var tcPr = cell.Descendants <TableCellProperties>().FirstOrDefault();

            if (tcPr == null)
            {
                tcPr = cell.AppendChild(new TableCellProperties());
            }
            var tcMar = tcPr.Descendants <TableCellMargin>().FirstOrDefault();

            if (tcMar == null)
            {
                tcMar = tcPr.AppendChild(new TableCellMargin());
            }
            if (marginLeftMM.HasValue)
            {
                if (tcMar.LeftMargin == null)
                {
                    tcMar.LeftMargin = new LeftMargin();
                }
                tcMar.LeftMargin.Width = marginLeftMM.Value.MMToTwip().ToString();
                tcMar.LeftMargin.Type  = TableWidthUnitValues.Dxa;
            }
            if (marginTopMM.HasValue)
            {
                if (tcMar.TopMargin == null)
                {
                    tcMar.TopMargin = new TopMargin();
                }
                tcMar.TopMargin.Width = marginTopMM.Value.MMToTwip().ToString();
                tcMar.TopMargin.Type  = TableWidthUnitValues.Dxa;
            }
            if (marginRightMM.HasValue)
            {
                if (tcMar.RightMargin == null)
                {
                    tcMar.RightMargin = new RightMargin();
                }
                tcMar.RightMargin.Width = marginRightMM.Value.MMToTwip().ToString();
                tcMar.RightMargin.Type  = TableWidthUnitValues.Dxa;
            }
            if (marginBottomMM.HasValue)
            {
                if (tcMar.BottomMargin == null)
                {
                    tcMar.BottomMargin = new BottomMargin();
                }
                tcMar.BottomMargin.Width = marginBottomMM.Value.MMToTwip().ToString();
                tcMar.BottomMargin.Type  = TableWidthUnitValues.Dxa;
            }
        }
        public static void Run()
        {
            // ExStart:AddTableNodeWithTag
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Tags();

            // Create an object of the Document class
            Document doc = new Document();

            // Initialize Page class object
            Aspose.Note.Page page = new Aspose.Note.Page(doc);
            // Initialize TableRow class object
            TableRow row = new TableRow(doc);
            // Initialize TableCell class object
            TableCell cell = new TableCell(doc);

            // Insert cell content
            cell.AppendChild(InsertTable.GetOutlineElementWithText(doc, "Single cell."));
            // Add cell to row node
            row.AppendChild(cell);
            // Initialize table node
            Table table = new Table(doc)
            {
                IsBordersVisible = true,
                Columns          = { new TableColumn {
                                         Width = 70
                                     } }
            };

            // Insert row node in table
            table.AppendChild(row);
            // Add tag to this table node
            table.Tags.Add(new NoteTag
            {
                Icon = TagIcon.QuestionMark
            });

            Outline        outline     = new Outline(doc);
            OutlineElement outlineElem = new OutlineElement(doc);

            // Add table node
            outlineElem.AppendChild(table);
            // Add outline elements
            outline.AppendChild(outlineElem);
            page.AppendChild(outline);
            doc.AppendChild(page);

            dataDir = dataDir + "AddTableNodeWithTag_out.one";
            // Save OneNote document
            doc.Save(dataDir);
            // ExEnd:AddTableNodeWithTag
            Console.WriteLine("\nTable node with tag added successfully.\nFile saved at " + dataDir);
        }
        public OpenXmlElement ToElement()
        {
            var tableCell = new TableCell
            {
                TableCellProperties = contextTableCellProperties
            };

            tableCell.AppendChild(new Paragraph(Aggregation.ToArray())
            {
                ParagraphProperties = paragraphProperties
            });

            return(tableCell);
        }
Beispiel #22
0
        /// <summary>
        /// Adds the runs to SDT content cell.
        /// </summary>
        /// <param name="sdtContentCell">The SDT content cell.</param>
        /// <param name="runs">The runs.</param>
        private void AddRunsToSdtContentCell(SdtContentCell sdtContentCell, List <Run> runs)
        {
            TableCell cell = new TableCell();
            Paragraph para = new Paragraph();

            para.RemoveAllChildren();

            foreach (Run run in runs)
            {
                para.AppendChild <Run>(run);
            }

            cell.AppendChild <Paragraph>(para);
            SetSdtContentKeepingPermissionElements(sdtContentCell, cell);
        }
Beispiel #23
0
        /// <summary>
        /// Adds the runs to SDT content cell.
        /// </summary>
        /// <param name="sdtContentCell">The SDT content cell.</param>
        /// <param name="runs">The runs.</param>
        private static void AddRunsToSdtContentCell(OpenXmlCompositeElement sdtContentCell, IEnumerable <Run> runs)
        {
            var cell = new TableCell();
            var para = new Paragraph();

            para.RemoveAllChildren();

            foreach (var run in runs)
            {
                para.AppendChild(run);
            }

            cell.AppendChild(para);
            SetSdtContentKeepingPermissionElements(sdtContentCell, cell);
        }
Beispiel #24
0
        private TableRow CreateRowAsync(Action <TableCell, TableCell, TableCell> callback)
        {
            var tableRow = new TableRow();

            var firstCell = new TableCell();

            firstCell.AppendChild(new TableCellProperties
            {
                TableCellWidth = new TableCellWidth
                {
                    Width = _firstCellWidth
                }
            });

            tableRow.AppendChild(firstCell);

            var secondCell = new TableCell();

            secondCell.AppendChild(new TableCellProperties
            {
                TableCellWidth = new TableCellWidth
                {
                    Width = _secondCellWidth
                }
            });

            tableRow.AppendChild(secondCell);

            var thirdCell = new TableCell();

            thirdCell.AppendChild(new TableCellProperties
            {
                TableCellWidth = new TableCellWidth
                {
                    Width = _thirdCellWidth
                }
            });

            tableRow.AppendChild(thirdCell);

            callback(firstCell, secondCell, thirdCell);

            return(tableRow);
        }
Beispiel #25
0
        private static void InputTextIntoCell(int row, int col, string textInput)               // Inputs text into a specific cell
        {
            TableRow tRow = tab.Elements <TableRow>().ElementAt(row);

            TableCell tCell = tRow.Elements <TableCell>().ElementAt(col);

            Paragraph par = tCell.Elements <Paragraph>().Count() == 0 ?
                            tCell.AppendChild(new Paragraph()) :
                            tCell.Elements <Paragraph>().First();

            Run run = par.Elements <Run>().Count() == 0 ?
                      par.AppendChild(new Run()) :
                      par.Elements <Run>().First();

            run.AppendChild(rProp.CloneNode(true));
            Text txt = run.AppendChild(new Text());

            txt.Text = textInput;
        }
Beispiel #26
0
        public static void Run()
        {
            // ExStart:SettingCellBackGroundColor
            // Create an object of the Document class
            Document doc = new Document();

            // Initialize Page class object
            Aspose.Note.Page page = new Aspose.Note.Page(doc);

            // Initialize TableRow class object
            TableRow row1 = new TableRow(doc);
            // Initialize TableCell class object and set text content
            TableCell cell11 = new TableCell(doc);

            cell11.AppendChild(InsertTable.GetOutlineElementWithText(doc, "Small text"));
            cell11.BackgroundColor = Color.Coral;
            row1.AppendChild(cell11);
            // ExEnd:SettingCellBackGroundColor
        }
        public void AddTableRow(List <string> cellData)
        {
            var tableRow = new TableRow();

            cellData.ForEach(cellText =>
            {
                var tableCell = new TableCell();

                var paragraph = new Paragraph();
                var run       = new Run();
                DocumentBuilderHelpers.AddTextToElement(run, cellText);

                paragraph.AppendChild(run);
                tableCell.AppendChild(paragraph);
                tableRow.AppendChild(tableCell);
            });

            _table.AppendChild(tableRow);
        }
Beispiel #28
0
        /// <summary>
        /// Adds the runs to SDT content cell.
        /// </summary>
        /// <param name="sdtContentCell">The SDT content cell.</param>
        /// <param name="runs">The runs.</param>
        private void AddRunsToSdtContentCell(SdtContentCell sdtContentCell, List <Run> runs)
        {
            TableCell cell = new TableCell();
            Paragraph para = new Paragraph();

            para.RemoveAllChildren();

            if (sdtContentCell.Descendants <ParagraphProperties>().Count() > 0)
            {
                para.ParagraphProperties = (ParagraphProperties)sdtContentCell.Descendants <ParagraphProperties>().First().Clone();
            }

            foreach (Run run in runs)
            {
                para.AppendChild <Run>(run);
            }

            cell.AppendChild <Paragraph>(para);
            SetSdtContentKeepingPermissionElements(sdtContentCell, cell);
        }
        private void ChangeTextWord(WordprocessingDocument doc)
        {
            // Encuentra la primera tabla en el documento.
            Table table = doc.MainDocumentPart.Document.Body.Elements <Table>().First();

            // Encuentra la segunda y tercera fila en la tabla.
            TableRow row1 = table.Elements <TableRow>().ElementAt(1);
            TableRow row2 = table.Elements <TableRow>().ElementAt(2);

            // Encuentra las celdas a modificar.
            TableCell cellNombre    = row1.Elements <TableCell>().ElementAt(1);
            TableCell cellApellido  = row1.Elements <TableCell>().ElementAt(3);
            TableCell cellEdad      = row2.Elements <TableCell>().ElementAt(1);
            TableCell cellDireccion = row2.Elements <TableCell>().ElementAt(3);

            // Llena las celdas con los datos de la primera fila de la primera tabla del dataset.
            cellNombre.AppendChild(new Paragraph(new Run(new Text("Freddy"))));
            cellApellido.AppendChild(new Paragraph(new Run(new Text("Quintero"))));
            cellEdad.AppendChild(new Paragraph(new Run(new Text("29"))));
            cellDireccion.AppendChild(new Paragraph(new Run(new Text("Porlamar"))));
        }
Beispiel #30
0
        private void ProcessVerticalSpan(ref int colIndex, TableRow row, DocxTableProperties docxProperties)
        {
            int rowSpan;

            docxProperties.RowSpanInfo.TryGetValue(colIndex, out rowSpan);

            while (rowSpan > 0)
            {
                TableCell cell = new TableCell();

                cell.TableCellProperties = new TableCellProperties();
                cell.TableCellProperties.Append(new VerticalMerge());

                cell.AppendChild(new Paragraph());

                row.Append(cell);

                docxProperties.RowSpanInfo[colIndex] = --rowSpan;
                ++colIndex;
                docxProperties.RowSpanInfo.TryGetValue(colIndex, out rowSpan);
            }
        }
Beispiel #31
0
        /// <summary>
        /// Adds the runs to SDT content cell.
        /// </summary>
        /// <param name="sdtContentCell">The SDT content cell.</param>
        /// <param name="runs">The runs.</param>
        private void AddRunsToSdtContentCell(SdtContentCell sdtContentCell, List<Run> runs)
        {
            TableCell cell = new TableCell();
            Paragraph para = new Paragraph();
            para.RemoveAllChildren();

            foreach (Run run in runs)
            {
                para.AppendChild<Run>(run);
            }

            cell.AppendChild<Paragraph>(para);
            SetSdtContentKeepingPermissionElements(sdtContentCell, cell);
        }
Beispiel #32
0
        //This method allows me to create either a row full of text cells or a row of text cells and a last row with a drawing
        TableRow CreateRow(string[] cellText)
        {
            TableRow tr = new TableRow();

            //create cells with simple text
            foreach (string s in cellText) {
                TableCell tc = new TableCell();
                Paragraph p = new Paragraph();
                Run r = new Run();
                Text t = new Text(s);

                r.AppendChild(t);
                p.AppendChild(r);
                tc.AppendChild(p);
                tr.AppendChild(tc);
            }

            return tr;
        }
        public OpenXmlElement ToElement()
        {
            var tableCell = new TableCell
                                {
                                    TableCellProperties = contextTableCellProperties
                                };

            tableCell.AppendChild(new Paragraph(Aggregation.ToArray())
                                  	{
                                  		ParagraphProperties = paragraphProperties
                                  	});

            return tableCell;
        }
        private void ProcessTd(int colIndex, DocxNode td, TableRow row, DocxTableProperties tableProperties)
        {
            TableCell cell = new TableCell();
            bool hasRowSpan = false;

            string rowSpan = td.ExtractAttributeValue(DocxTableProperties.rowSpan);
            Int32 rowSpanValue;
            if (Int32.TryParse(rowSpan, out rowSpanValue))
            {
                tableProperties.RowSpanInfo[colIndex] = rowSpanValue - 1;
                hasRowSpan = true;
            }

            DocxTableCellStyle style = new DocxTableCellStyle();
            style.HasRowSpan = hasRowSpan;
            style.Process(cell, tableProperties, td);

            if (td.HasChildren)
            {
                Paragraph para = null;

                //If the cell is th header, apply font-weight:bold to the text
                if (tableProperties.IsCellHeader)
                {
                    SetThStyleToRun(td);
                }

                foreach (DocxNode child in td.Children)
                {
                    td.CopyExtentedStyles(child);
                    
                    if (child.IsText)
                    {
                        if (!IsEmptyText(child.InnerHtml))
                        {
                            if (para == null)
                            {
                                para = cell.AppendChild(new Paragraph());
                                OnParagraphCreated(DocxTableCellStyle.GetHtmlNodeForTableCellContent(td), para);
                            }

                            Run run = para.AppendChild(new Run(new Text()
                            {
                                Text = ClearHtml(child.InnerHtml),
                                Space = SpaceProcessingModeValues.Preserve
                            }));

                            RunCreated(child, run);
                        }
                    }
                    else
                    {
                        child.ParagraphNode = DocxTableCellStyle.GetHtmlNodeForTableCellContent(td);
                        child.Parent = cell;
                        td.CopyExtentedStyles(child);
                        ProcessChild(child, ref para);
                    }
                }
            }

            //The last element of the table cell must be a paragraph.
            var lastElement = cell.Elements().LastOrDefault();

            if (lastElement == null || !(lastElement is Paragraph))
            {
                cell.AppendChild(new Paragraph());
            }

            row.Append(cell);
        }
        private void ProcessVerticalSpan(ref int colIndex, TableRow row, DocxTableProperties docxProperties)
        {
            int rowSpan;

            docxProperties.RowSpanInfo.TryGetValue(colIndex, out rowSpan);

            while (rowSpan > 0)
            {
                TableCell cell = new TableCell();

                cell.TableCellProperties = new TableCellProperties();
                cell.TableCellProperties.Append(new VerticalMerge());

                cell.AppendChild(new Paragraph());

                row.Append(cell);

                docxProperties.RowSpanInfo[colIndex] = --rowSpan;
                ++colIndex;
                docxProperties.RowSpanInfo.TryGetValue(colIndex, out rowSpan);
            }
        }
        /// <summary>
        /// Adds the runs to SDT content cell.
        /// </summary>
        /// <param name="sdtContentCell">The SDT content cell.</param>
        /// <param name="runs">The runs.</param>
        private static void AddRunsToSdtContentCell(OpenXmlCompositeElement sdtContentCell, IEnumerable<Run> runs)
        {
            var cell = new TableCell();
            var para = new Paragraph();
            para.RemoveAllChildren();

            foreach (var run in runs)
            {
                para.AppendChild(run);
            }

            cell.AppendChild(para);
            SetSdtContentKeepingPermissionElements(sdtContentCell, cell);
        }
Beispiel #37
0
    public static void AddRow(this Table table, string[] cells, string[] styles = null, bool singleSpace = true)
    {
        TableRow tr = new TableRow();
        for (int i = 0; i < cells.Length; i++)
        {
            TableCell tc = new TableCell();
            if(cells[i].Contains("|"))
            {
                Paragraph para = tc.AppendChild(new Paragraph(new ParagraphProperties()));
                Run run = para.AppendChild(new Run(new RunProperties()));

                string[] values = cells[i].Split('|');
                for(int j = 0, jj = values.Length; j < jj; j++)
                {
                    if(j != 0)
                        run.AppendChild(new Break());

                    run.AppendChild(new Text(values[j]));
                }
            }
            else
                tc.AppendChild(new Paragraph(new ParagraphProperties(), new Run(new RunProperties(), new Text(cells[i]))));

            tr.Append(tc);

            foreach (OpenXmlElement els in tc.Elements())
            {
                if (els.GetType() == typeof(Paragraph))
                {
                    Paragraph para = (Paragraph)els;
                    if(singleSpace)
                        para.ParagraphProperties.AppendChild(new SpacingBetweenLines() { Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0" });
                    else
                        para.ParagraphProperties.AppendChild(new SpacingBetweenLines() { Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "240", After = "0" });
                }
            }
            if (styles != null && styles.Length > i && !string.IsNullOrEmpty(styles[i]))
            {
                TableCellProperties props = new TableCellProperties();
                tc.Append(props);
                if (styles[i].Contains("LeftIndent"))
                {
                    string value = styles[i].Substring(styles[i].IndexOf("LeftIndent:") + 11);
                    if (value.Contains("|"))
                        value = value.Substring(0, value.IndexOf("|"));
                    props.LeftIndent(value);
                }
                if (styles[i].Contains("RightIndent"))
                {
                    string value = styles[i].Substring(styles[i].IndexOf("RightIndent:") + 12);
                    if (value.Contains("|"))
                        value = value.Substring(0, value.IndexOf("|"));
                    props.RightIndent(value);
                }
                if (styles[i].Contains("TopIndent"))
                {
                    string value = styles[i].Substring(styles[i].IndexOf("TopIndent:") + 10);
                    if (value.Contains("|"))
                        value = value.Substring(0, value.IndexOf("|"));
                    props.TopIndent(value);
                }
                if (styles[i].Contains("Background"))
                {
                    string value = styles[i].Substring(styles[i].IndexOf("Background:") + 11);
                    if (value.Contains("|"))
                        value = value.Substring(0, value.IndexOf("|"));
                    props.BackgroundColor(value);
                }
                if (styles[i].Contains("Bold"))
                    tc.Bold();
                if (styles[i].Contains("JustifyRight"))
                    tc.Right();
                if (styles[i].Contains("JustifyCenter"))
                    tc.Center();
                if(styles[i].Contains("FontSize"))
                {
                    string value = styles[i].Substring(styles[i].IndexOf("FontSize:") + 9);
                    if (value.Contains("|"))
                        value = value.Substring(0, value.IndexOf("|"));
                    tc.FontSize(value);
                }
                if (styles[i].Contains("FontColor"))
                {
                    string value = styles[i].Substring(styles[i].IndexOf("FontColor:") + 10);
                    if (value.Contains("|"))
                        value = value.Substring(0, value.IndexOf("|"));
                    tc.FontColor(value);
                }
                if (styles[i].Contains("VerticalText"))
                {
                    string value = styles[i].Substring(styles[i].IndexOf("VerticalText:") + 13);
                    if (value.Contains("|"))
                        value = value.Substring(0, value.IndexOf("|"));
                    props.VerticalText(value);
                }
                if (styles[i].Contains("Borders"))
                {
                    string value = styles[i].Substring(styles[i].IndexOf("Borders:") + 8);
                    if (value.Contains("|"))
                        value = value.Substring(0, value.IndexOf("|"));
                    props.Borders(value);
                }
                if (styles[i].Contains("VerticalMerge"))
                {
                    string value = styles[i].Substring(styles[i].IndexOf("VerticalMerge:") + 14);
                    if (value.Contains("|"))
                        value = value.Substring(0, value.IndexOf("|"));
                    props.VertMerge(value);
                }
                if (styles[i].Contains("HorizontalMerge"))
                {
                    string value = styles[i].Substring(styles[i].IndexOf("HorizontalMerge:") + 16);
                    if (value.Contains("|"))
                        value = value.Substring(0, value.IndexOf("|"));
                    props.HorizMerge(value);
                }
            }
        }

        table.AppendChild(tr);
    }
Beispiel #38
0
        /// <summary>
        /// Adds the runs to SDT content cell.
        /// </summary>
        /// <param name="sdtContentCell">The SDT content cell.</param>
        /// <param name="runs">The runs.</param>
        private void AddRunsToSdtContentCell(SdtContentCell sdtContentCell, List<Run> runs)
        {
            TableCell cell = new TableCell();
            Paragraph para = new Paragraph();
            para.RemoveAllChildren();

            if (sdtContentCell.Descendants<ParagraphProperties>().Count() > 0)
                para.ParagraphProperties = (ParagraphProperties)sdtContentCell.Descendants<ParagraphProperties>().First().Clone();

            foreach (Run run in runs)
            {
                para.AppendChild<Run>(run);
            }

            cell.AppendChild<Paragraph>(para);
            SetSdtContentKeepingPermissionElements(sdtContentCell, cell);
        }