VegaRise.NET

Tables

Create a table with new Table(rows, cols), index cells viatable[row, col], and add it with doc.AddTable(table). Tables can also be built from a DataTable, a CSV file/stream, or anIEnumerable<T>.

Create a Table Manually

Use case: Add a simple two-row table to the document.

C#
1using Vega;
2using Vega.DOM;
3using DOM.Elements.TableElements;
4
5var doc = new VDocs();
6
7var table = new Table(2, 2);
8table[0, 0].AddText("Name");
9table[0, 1].AddText("Value");
10table[1, 0].AddText("Product");
11table[1, 1].AddText("VDocs");
12
13doc.AddTable(table);

Table from a DataTable

Use case: Render an existing ADO.NET DataTable into a Word table.

C#
1using System.Data;
2
3var dt = new DataTable();
4dt.Columns.Add("Name");
5dt.Columns.Add("Quantity", typeof(int));
6dt.Rows.Add("Widget", 10);
7dt.Rows.Add("Gadget", 5);
8
9var table = Table.FromDataTable(dt, includeHeaders: true);
10doc.AddTable(table);

Table from an Enumerable

Use case: Populate a table from a strongly-typed collection.

C#
1public record Product(string Name, decimal Price);
2
3var products = new[]
4{
5 new Product("Widget", 9.99m),
6 new Product("Gadget", 19.99m),
7};
8
9var table = Table.FromEnumerable(products, includeHeaders: true);
10doc.AddTable(table);

Table from CSV

Use case: Load a CSV file directly as a table.

C#
1var table = Table.FromCsv("data.csv", hasHeaderRow: true);
2doc.AddTable(table);

Merge Cells (Row)

Use case: Merge two cells in the first row into a single header.

C#
1var table = new Table(2, 3);
2table[0, 0].AddText("Merged header");
3table[0, 0].Split(1, 3); // spans 1 row x 3 columns

Frequently asked questions

How do I merge cells?

Use TableCell.Split(rowSpan, colSpan), or Table.MergeCells(...)/TableRow.MergeCells(...) where implemented.

How can I style the entire table?

Assign a TableStyle to table.Style. You can set borders, shading, alignment, and per-column widths (via TableGridColsWidth).

Can I load a table from a database?

Yes — read your data into a DataTable (or an IEnumerable<T>), then use Table.FromDataTable(...) or Table.FromEnumerable(...).

VegaRise.NET

Sign In

Welcome back. Please sign in to your account.

Forgot password?
or

Don't have an account? Create an account

By signing in, you agree to our Terms of Service and Privacy Policy.