BuiltInTableStyles.cs
//
// This code is part of GrapeCity Documents for Word samples.
// Copyright (c) GrapeCity, Inc. All rights reserved.
//
using System;
using System.IO;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using GrapeCity.Documents.Word;

namespace GcWordWeb.Samples
{
    // Demo of all built-in table styles
    public class BuiltInTableStyles
    {
        public GcWordDocument CreateDocx()
        {
            var rows = 3;
            var cols = 4;

            var doc = new GcWordDocument();
            var sec = doc.Body.Sections.First;
            var pars = sec.GetRange().Paragraphs;

            pars.Add("Demo of All Built-in Table Styles", doc.Styles[BuiltInStyleId.Title]);

            foreach (BuiltInStyleId id in Enum.GetValues(typeof(BuiltInStyleId)))
            {
                if (id == BuiltInStyleId.User)
                    continue;
                var style = doc.Styles[id];
                if (style.Type != StyleType.Table)
                    continue;

                pars.Add($"The following table is formatted using style '{style.Name}':");
                var table = sec.GetRange().Tables.Add(cols, rows, style);
                for (int row = 0; row < rows; ++row)
                    for (int col = 0; col < cols; ++col)
                        table.Rows[row].Cells[col].GetRange().Paragraphs.First.GetRange().Runs.Add($"Cell ({row},{col})");
            }

            // Done:
            return doc;
        }
    }
}