Tables

Tables built from TableRow/TableCell lists: alignment grids, spans, rich text inside cells and automatic paging across slides.

Demo class DemoTable Source file Modules/DemoTable.cs Slide methods genSlide01 – genSlide11 Output files table_genSlide*.pptx

1Overview

DemoTable is the largest module in the suite. Since the latest API revision, rows are built with List<TableRow> where each TableRow holds a sequence of TableCell { text = …, options = new TableCellProps { … } }.

It covers the full feature map: alignment, per-cell styles, rowspan/colspan, nested rich text (word-level formatting) and the auto-paging engine that splits long tables onto extra slides.

2Demo methods

MethodWhat it demonstrates
genSlide01(segment)Alignment grid & cell styles — 3×3 valign×align plus per-cell fill/color.
genSlide02Row/col spans — rowspan & colspan following HTML table conventions.
genSlide03Super spans — bigger merged layouts combining rowspan/colspan.
genSlide04Cell formatting & margins — fonts, colors, table border, colW.
genSlide05Rich text into cells — text objects converted to styled TableCells.
genSlide06Word-level cells — a TableCell.text may itself be a TableRow.
genSlide07Auto-paging — autoPage splits long tables onto extra slides.
genSlide08Auto-paging with complex text arrays (supported since 3.7.2/3.8.0).
genSlide09Precision auto-paging — tightly calculated rows/labels for dev & test.
genSlide10Single-row paging — tests paging with one row up to Segment 3.
genSlide11Hyperlink cells — TableCellProps hyperlink reference plus autoPage.

3Code samples

Alignment grid & cell styles 3×3 valign×align grid; per-cell fill/color and border props. DemoTable.cs · genSlide01
			var arrTabRows1 = new List<TableRow> {
				new TableRow {
					new TableCell { text= "Top Lft", options = new TableCellProps  { valign= VAlign.top, align= HAlign.left, fontFace= "Arial" } },
					new TableCell { text= "Top Ctr", options = new TableCellProps  { valign= VAlign.top, align= HAlign.center, fontFace= "Courier" } },
					new TableCell { text= "Top Rgt", options = new TableCellProps  { valign= VAlign.top, align= HAlign.right, fontFace= "Verdana" } },
					},
				new TableRow {
					new TableCell { text= "Mdl Lft", options = new TableCellProps{ valign= VAlign.middle, align= HAlign.left } },
					new TableCell { text= "Mdl Ctr", options = new TableCellProps{ valign= VAlign.middle, align= HAlign.center } },
					new TableCell { text= "Mdl Rgt", options = new TableCellProps{ valign= VAlign.middle, align= HAlign.right } },
				},
				new TableRow {
					new TableCell{ text= "Btm Lft", options = new TableCellProps{ valign= VAlign.bottom, align= HAlign.left } },
					new TableCell{ text= "Btm Ctr", options = new TableCellProps{ valign= VAlign.bottom, align= HAlign.center } },
					new TableCell{ text= "Btm Rgt", options = new TableCellProps{ valign= VAlign.bottom, align= HAlign.right } },
				}
			};
			slide.addTable(arrTabRows1, new TableProps {
				x = 0.5,
				y = 1.1,
				w = 5.0,
				rowH = 0.75,
				fill = ("F7F7F7"),
				fontSize = 14,
				color = "363636",
				border = new BorderProps ("BBCCDD", null, 1),
			});
		}
		// Pass default cell style as tabOpts, then just style/override individual cells as needed

		{
			// DEMO= cell styles
			var objOpts2 = new TextPropsOptions { x = 6.0, y = 0.7, w = 4, h = 0.3, margin = 0, fontSize = 18, fontFace = "Arial", color = "0088CC" };
			slide.addText("Cell Styles:", objOpts2);

			var arrTabRows2 = new List<TableRow> 
			{
					new TableRow {
					new TableCell { text= "white", options=new TableCellProps { fill= ("6699CC"), color= "FFFFFF" } },
					new TableCell { text= "yellow", options=new TableCellProps { fill= ("99AACC"), color= "FFFFAA" } },
					new TableCell { text= "hyperlink", options= new TableCellProps{ fill= ("AACCFF"), hyperlink = 2 } },
					},
Rowspan & colspan HTML conventions: spanned cells are omitted from the row arrays. DemoTable.cs · genSlide02
			var arrTabRows1 = new List<TableRow> {
				new TableRow {
					new TableCell { text= "A1\nA2", options= new TableCellProps { rowspan= 2, fill= "99FFCC" } },
					new TableCell { text= "B1" },
					new TableCell { text= "C1 -> D1", options= new TableCellProps { colspan= 2, fill= "99FFCC" } },
					new TableCell { text= "E1" },
					new TableCell { text= "F1\nF2\nF3", options= new TableCellProps{ rowspan= 3, fill= "99FFCC" } },
				},
				new TableRow { "B2", "C2", "D2", "E2"     },
				new TableRow { "A3", "B3", "C3", "D3", "E3"},
			};
			// NOTE= Follow HTML conventions for colspan/rowspan cells - cells spanned are left out of arrays - see above
			// The table above has 6 columns, but each of the 3 rows has 4-5 elements as colspan/rowspan replacing the missing ones
			// (e.g.= there are 5 elements in the first row, and 6 in the second)
			slide.addTable(arrTabRows1, tabOpts1);
Rich text into cells Convert existing text objects to TableCells with font/color/align/breakLine. DemoTable.cs · genSlide05
		{
			var opts2 = new TableProps {
				x = 2.5,
				y = 5,
				h = 2,
				align = HAlign.center,
				valign = VAlign.middle,
				colW = new List<double> { 1.5, 1.5, 6.5 },
				border = new BorderProps (null, null, 1),
				fill = "F1F1F1"
			};
			var arrTabRows = new List<TableRow>{
				new TableRow {
					new TableCell   { text= "Cell 1A", options= new TableCellProps{ fontFace= "Arial" } },
					new TableCell   { text= "Cell 1B", options=  new TableCellProps{ fontFace= "Courier" } },
					new TableCell   { text= arrTextObjects.ConvertAll(x=> new TableCell {
						text =  x.text!,
						options = new TableCellProps {
							fontSize= x.options?.fontSize,
							color= x.options?.color,
							align= x.options?.align,
							breakLine= x.options?.breakLine
						}
					}) ,
						options=  new TableCellProps{ fill= "232323" } },
					},
			};
Word-level cells A TableCell.text may itself be a TableRow — multiple paragraphs in one cell. DemoTable.cs · genSlide06
		// EX 2=
		slide.addTable(new List<TableRow>{
			new TableRow {
					new TableCell {
						text=new TableRow
						{
							new TableCell { text= "I am a text object with bullets ", options = new TableCellProps { color= "CC0000", bullet= new CustomTextBullet { characterCode= "2605" } } },
							new TableCell { text= "and i am the next text object", options = new TableCellProps { color= "00CD00", bullet= new CustomTextBullet { characterCode= "25BA" } } },
							new TableCell { text= "Final text object w/ bullet:true", options = new TableCellProps { color= "0000AB", bullet= true } },
						},
					},
					new TableCell {
						text=new TableRow
						{
							new TableCell { text= "Cell", options= new TableCellProps { fontSize= 36, align= HAlign.left, color= "8648cd" } },
							new TableCell { text= "#2", options= new TableCellProps { fontSize= 60, align= HAlign.right, color= "CD0101" } },
						},
					},
					new TableCell {
						text=new TableRow
						{
								new TableCell { text= "Cell", options = new TableCellProps { fontSize= 36, fontFace= "Courier", color= "dd0000", breakLine= true } },
								new TableCell { text= "#", options = new TableCellProps { fontSize= 60, color= "8648cd" } },
								new TableCell { text= "3", options = new TableCellProps { fontSize= 60, fontFace= "Times", color= "33ccef" } },
						},
					},
				},
			},
			new TableProps
			{
				x = 0.6,
				y = 4.75,
				h = 2,
				fontSize = 24,
				colW = new List<double> { 8, 2, 2 },
				valign = VAlign.middle,
				border = new BorderProps(null, null, 1),
				fill = "F1F1F1"
			});
	}
Auto-paging (basic) autoPage:true splits rows across slides. DemoTable.cs · genSlide07
			slide.addTable(arrRows, new TableProps {
				x = 0.5, y = 0.5, colW = new List<double> { 0.75, 1.75, 10 },
				margin = 0.05,
				border = new BorderProps ("CFCFCF"), autoPage = true });
		}
Auto-paging (fine-tuned) autoPageSlideStartY, autoPageCharWeight and verbose knobs. DemoTable.cs · genSlide07
			slide.addTable(arrRows, new TableProps {
				x = 3.0,
				y = 4.0,
				colW = new List<double> { 0.75, 1.75, 7 },
				margin = 0.05,
				border = new BorderProps ("CFCFCF"),
				autoPage = true,
				autoPageSlideStartY = 1.5,
				autoPageCharWeight = 0.15,
				verbose = false,
			});
Master + auto-paging Footer placeholder filled on each auto-paged slide via slide.autoPagedSlides. DemoTable.cs · genSlide07
			slide = pptx.addSlide(new AddSlideProps { sectionTitle = "Tables: Auto-Paging", masterName = "MASTER_AUTO_PAGE_TABLE_PLACEHOLDER" });
			slide.addText(new List<TextProps>{
				new TextProps{ text= "Table Examples: ", options= DEMO_TITLE_TEXT },
				new TextProps{ text= "Master Page with Auto-Paging", options= DEMO_TITLE_OPTS },
			},
			new TextPropsOptions { x = 0.5, y = 0.13, w = "90%" });
			slide.addText("Auto-Paging table", new TextPropsOptions { placeholder = "footer" });
			slide.addTable(arrRows, new TableProps { x = 1.0, y = 0.6, colW = new List<double> { 0.75, 1.75, 7 }, margin = 0.05, border = new BorderProps ("CFCFCF"), autoPage = true });
			// HOWTO= In cases where you want to add custom text, placeholders, etc. to slidemasters, a reference to these slide(s) is needed
			// HOWTO= Use the `newAutoPagedSlides` to access references (see {Issue #625}(https://github.com/gitbrent/PptxGenJS/issues/625))

			if (slide.autoPagedSlides != null)
			{
				foreach (var xslide in slide.autoPagedSlides)
				{
					xslide.addText("Auto-Paging table continued...", new TextPropsOptions { placeholder = "footer" });
				}
				// slide.AutoPagedSlides.forEach((slide, _) => slide.addText("Auto-Paging table continued...", new TextPropsOptions { placeholder = "footer" }));
			}
Hyperlink cell TableCellProps.hyperlink reference with autoPage. DemoTable.cs · genSlide11
		var options = new TableCellProps { fill = "AACCFF", hyperlink = 1 };
        var baseTabRows = new TableRow[]
           {
            new TableRow
            {
                new TableCell { text = "white color", options = new TableCellProps { fill = "6699CC" , align = HAlign.left, color = "FFFFFF" } },
                new TableCell { text= "yellow color",  options =  new TableCellProps { fill = "99AACC" , color= "FFFFAA" } },
                new TableCell { text= "hyperlink here", options = options},
            }
           };
        var arrTabRows = new List<TableRow>();
        for (var i = 0; i < 2; i++)
        {
           
            arrTabRows.Add(baseTabRows[0]);
        };

        slide.addTable(arrTabRows, new TableProps { x = 0.5, y = 1.0, w = 10, autoPage = true });
Rowspan & colspan TableCellProps { rowspan, colspan } merge cells; merged cells are omitted from the row array. DemoTable.cs · genSlide03
        var optsRowspan3 = new TableCellProps { rowspan = 3, fill = "99FFCC" };
        var optsColspan4 = new TableCellProps { colspan = 4, fill = "9999FF" };

        var arrTabRows = new List<TableRow> {
            new TableRow {
                "A1", "B1", "C1", "D1",
                new TableCell { text = "I1\n-\nI5", options = new TableCellProps { rowspan = 5, fill = "99FFCC" } },
                new TableCell { text = "J1 -> K1 -> L1 -> M1 -> N1", options = new TableCellProps { colspan = 5, fill = "9999FF" } },
            },
            new TableRow {
                new TableCell { text = "A2\n--\nA3", options = new TableCellProps { rowspan = 2, fill = "99FFCC" } },
                new TableCell { text = "B2 -> C2 -> D2", options = new TableCellProps { colspan = 3, fill = "9999FF" } },
                "E2", "F2",
                new TableCell { text = "G2\n-\nG4", options = new TableCellProps { rowspan = 3, fill = "99FFCC" } },
                "H2", "J2", "K2", "L2", "M2", "N2",
            },
        };
        slide.addTable(arrTabRows, new TableProps {
            x = 0.6, y = 1.3, w = "90%", h = 5.5, margin = 0, fontSize = 14,
            align = HAlign.center, valign = VAlign.middle, border = new BorderProps(null, null, 1)
        });
Cell margins TableProps.margin accepts a number or a tuple (top, right, bottom, left). DemoTable.cs · genSlide04
        slide.addTable(new List<TableRow> { new TableRow { "margin:0" } }, new TableProps {
            x = 0.5, y = 1.1, margin = 0, w = 1.2, fill = "FFFCCC",
            border = new BorderProps(null, null, 0)
        });
        slide.addTable(new List<TableRow> { new TableRow { "margin:[0, 0, 0, 0.3]" } }, new TableProps {
            x = 2.5, y = 1.1, margin = (0, 0, 0, 0.3), w = 2.0, fill = "FFFCCC",
            align = HAlign.right
        });
        slide.addTable(new List<TableRow> { new TableRow { "margin:0.05" } }, new TableProps {
            x = 5.5, y = 1.1, margin = 0.05, w = 1.0, fill = (SCHEME_COLORS.bg2)
        });
Auto-paging (complex text) autoPage:true with nested TableCell text and autoPageRepeatHeader. DemoTable.cs · genSlide08
        arrRows.Add(new TableRow {
            new TableCell { text = "ID#",        options = new TableCellProps { fill = "0088cc", color = "ffffff", valign = VAlign.middle } },
            new TableCell { text = "First Name", options = new TableCellProps { fill = "0088cc", color = "ffffff", valign = VAlign.middle } },
            new TableCell { text = "Lorum Ipsum",options = new TableCellProps { fill = "0088cc", color = "ffffff", valign = VAlign.middle } },
        });
        TABLE_NAMES_F.ForEach((name) => {
            arrRows.Add(new TableRow {
                new TableCell { text = idx,  options = new TableCellProps { align = HAlign.center } },
                new TableCell { text = name },
                new TableCell { text = new TableRow {
                    new TableCell { text = "Title", options = new TableCellProps { bold = true, color = "FF0000", breakLine = true } },
                    new TableCell { text = LOREM_IPSUM.JsSubstring(idx * 100, idx * 200) }
                } },
            });
        });
        slide.addTable(arrRows, new TableProps {
            x = 0.5, y = 0.5, w = 8, colW = new List<double> { 1, 1, 6 },
            border = new BorderProps("CFCFCF"),
            autoPage = true, autoPageRepeatHeader = true, verbose = false,
        });
Auto-paging (calculations) Tightly calculated row heights for precision auto-paging dev & test. DemoTable.cs · genSlide09
        for (var rowIdx = 0; rowIdx < 9; rowIdx++)
        {
            var col3Lines = new TableRow {
                new TableCell { text = "Complex-Title", options = new TableCellProps { bold = true, color = "FF0000", breakLine = true } }
            };
            for (var lineIdx = 0; lineIdx < 9; lineIdx++)
            {
                col3Lines.Add(new TableCell {
                    text = $"This is ROW#:{rowIdx + 1} LNE#:{lineIdx + 1}",
                    options = new TableCellProps { breakLine = true }
                });
            }
            arrRows.Add(new TableRow { new TableCell { text = "" }, new TableCell { text = "" }, new TableCell { text = col3Lines } });
        }
        slide.addTable(arrRows, new TableProps {
            x = 0.5, y = 0.75, w = 8, colW = new List<double> { 1, 1, 6 },
            border = new BorderProps("CFCFCF"),
            autoPage = true, autoPageRepeatHeader = true, verbose = false,
        });
Auto-paging (single row) autoPageLineWeight tunes the row-height calculation for single-row paging test cases. DemoTable.cs · genSlide10
        var projRows = new List<TableRow> {
            new TableRow {
                new TableCell { text = "id",            options = new TableCellProps { bold = true, fill = "1F3864", color = "ffffff" } },
                new TableCell { text = "First item",    options = new TableCellProps { bold = true, fill = "1F3864", color = "ffffff" } },
                new TableCell { text = "Impact",        options = new TableCellProps { bold = true, fill = "1F3864", color = "ffffff" } },
                new TableCell { text = "Owner",         options = new TableCellProps { bold = true, fill = "1F3864", color = "ffffff" } },
                new TableCell { text = "Created Date",  options = new TableCellProps { bold = true, fill = "1F3864", color = "ffffff" } },
                new TableCell { text = "Due Date",      options = new TableCellProps { bold = true, fill = "1F3864", color = "ffffff" } },
                new TableCell { text = "Status",        options = new TableCellProps { bold = true, fill = "1F3864", color = "ffffff" } },
                new TableCell { text = "Update",        options = new TableCellProps { bold = true, fill = "1F3864", color = "ffffff" } },
            },
            new TableRow { new TableCell { text = "1" }, new TableCell { text = "Lorem ipsum dolor sit amet..." }, new TableCell { text = "Adam" }, /* ... */ },
        };
        slide.addTable(projRows, new TableProps {
            x = 0.4, y = 5.25,
            colW = new List<double> { 0.5, 1.8, 5, 0.9, 1.0, 0.95, 0.8, 1.5 },
            border = new BorderProps("818181", null, 0.1),
            align = HAlign.left, valign = VAlign.middle,
            fontFace = "Segoe UI", fontSize = 8,
            autoPage = true, autoPageRepeatHeader = true,
            autoPageLineWeight = -0.4,
        });

4Key notes

!

Row model: rows = new List<TableRow> { new TableRow { cell, cell … }, … }. Each cell is TableCell { text, options = new TableCellProps { … } } — text may be a plain string.

!

span semantics match HTML: the cells swallowed by a colspan/rowspan are simply left out of the row arrays (see the sample notes in code).

!

Word-level formatting: set text = new TableRow { … } inside a TableCell to stack several paragraphs/styles (bullets, mixed fonts and colors) in that one cell.

!

autoPage:true recalculates row heights and continues on fresh slides when the table does not fit; tune with autoPageSlideStartY, autoPageCharWeight and verbose, and access the generated slides via slide.autoPagedSlides.