Novacode.DocX.AddTable C# (CSharp) Method

AddTable() public method

public AddTable ( int rowCount, int columnCount ) : Table
rowCount int
columnCount int
return Table
        public Table AddTable(int rowCount, int columnCount)
        {
            if (rowCount < 1 || columnCount < 1)
                throw new ArgumentOutOfRangeException("Row and Column count must be greater than zero.");

            Table t = new Table(this, HelperFunctions.CreateTable(rowCount, columnCount));
            t.mainPart = mainPart;
            return t;
        }

Usage Example

Example #1
0
        private static void CreateTable(DocX doc)
        {
            const int TABLE_WIDTH = 3;
            const int TABLE_HEIGHT = 4;
            var table = doc.AddTable(TABLE_HEIGHT, TABLE_WIDTH);
            table.Alignment = Alignment.center;
            for (int row = 0; row < table.RowCount; row++)
            {
                for (int col = 0; col < table.ColumnCount; col++)
                {
                    table.Rows[row].Cells[col].Paragraphs[0].Alignment = Alignment.center;
                    if (row == 0)
                    {
                        table.Rows[row].Cells[col].FillColor = System.Drawing.Color.MediumBlue;
                        switch (col)
                        {
                            case 0:
                                table.Rows[row].Cells[col].Paragraphs[0].Append("Team");
                                break;
                            case 1:
                                table.Rows[row].Cells[col].Paragraphs[0].Append("Game");
                                break;
                            case 2:
                                table.Rows[row].Cells[col].Paragraphs[0].Append("Points");
                                break;
                        }
                    }
                    else
                    {
                        table.Rows[row].Cells[col].Paragraphs[0].Append("-");
                    }
                }
            }

            doc.InsertTable(table);
        }
All Usage Examples Of Novacode.DocX::AddTable