//
// This code is part of Document Solutions for Word demos.
// Copyright (c) MESCIUS inc. All rights reserved.
//
using System;
using System.IO;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using GrapeCity.Documents.Word;
namespace DsWordWeb.Demos
{
// This example demonstrates all built-in table styles, using the new in v6.2 content creation
// helper methods. The document created by this example is the same
// as the one created by the BuiltInTableStyles example, but uses the
// helper methods for more robust and compact code.
// The lines of code replaced by the new helper method calls are preserved
// in the code of this example for reference, commented out with '//old:' comment.
public class BuiltInTableStylesHelpers
{
public GcWordDocument CreateDocx()
{
var rows = 3;
var cols = 4;
var doc = new GcWordDocument();
var pars = doc.Body.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 = doc.Body.Tables.Add(cols, rows, style);
for (int row = 0; row < rows; ++row)
for (int col = 0; col < cols; ++col)
{
//old: table.Rows[row].Cells[col].GetRange().Paragraphs.First.GetRange().Runs.Add($"Cell ({row},{col})");
table.Rows[row].Cells[col].GetRange().Paragraphs.First.AddRun($"Cell ({row},{col})");
}
}
// Done:
return doc;
}
}
}