Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save openize-com-gists/65e3c305b9d698ad19fc42d062eb0cb8 to your computer and use it in GitHub Desktop.

Select an option

Save openize-com-gists/65e3c305b9d698ad19fc42d062eb0cb8 to your computer and use it in GitHub Desktop.
C# Create Roman Alphabetic Paragraphs in Word Documents
using System;
namespace OpenizeTableReadingExample
{
class Program
{
static void Main(string[] args)
{
var program = new Program();
program.ReadTablesInWordDocument();
}
/// <summary>
/// Loads a Word Document with structured content using
/// Openize.Words.
/// Traverses tables and displays associated styles as defined by the Word document template.
/// Traverses through each row and then traverses columns within the row.
/// Traverses through paragrpahs within each cell and displays paragraph plain text
/// </summary>
/// <param name="documentDirectory">
/// The directory where the Word Document to load is present
/// (default is root of your project).
/// </param>
/// <param name="filename">
/// The name of the Word Document file to load (default is "WordTables.docx").
/// </param>
public void ReadTablesInWordDocument(string documentDirectory = "../../../",
string filename = "WordTables.docx")
{
try
{
// Load the Word Document
var doc = new Openize.Words.Document($"{documentDirectory}/{filename}");
var body = new Openize.Words.Body(doc);
var tables = body.Tables;
var tableNumber = 0;
var rowNumber = 0;
var columnNumber = 0;
var paraNumber = 0;
foreach (var table in tables)
{
tableNumber++;
System.Console.WriteLine($"Table Number : {tableNumber}");
System.Console.WriteLine($"..Table Style : {table.Style}");
foreach (var row in table.Rows)
{
rowNumber++;
System.Console.WriteLine($"..Row Number : {rowNumber}");
foreach (var cell in row.Cells)
{
columnNumber++;
System.Console.WriteLine($"....Column Number : {columnNumber}");
foreach (var para in cell.Paragraphs)
{
paraNumber++;
System.Console.WriteLine($"......Paragraph Number : {paraNumber}");
System.Console.WriteLine($"......Paragraph Text : {para.Text}");
}
paraNumber = 0;
}
columnNumber = 0;
}
rowNumber = 0;
}
}
catch (System.Exception ex)
{
throw new Openize.Words.OpenizeException("An error occurred.", ex);
}
}
}
}

C# Create Roman Alphabetic Paragraphs in Word Documents

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment