Skip to content

Commit 50d334c

Browse files
committed
Updated Comments
1 parent 5aaf417 commit 50d334c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed
Binary file not shown.

Tables/Add-or-remove-column-in-a-table/.NET/Add-or-remove-column-in-a-table/Program.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ static void Main(string[] args)
1717
// Add a column at the last index
1818
AddColumn(table);
1919
// Remove a column at the index
20-
RemoveColumn(table, 4);
20+
RemoveColumn(table, 3);
2121
// Save the modified document to a new file
22-
document.Save(Path.GetFullPath(@"Output/Result.docx"), FormatType.Docx);
22+
document.Save(Path.GetFullPath(@"../../../Output/Result.docx"), FormatType.Docx);
2323
}
2424
}
2525
/// <summary>
@@ -28,8 +28,16 @@ static void Main(string[] args)
2828
/// <param name="table">The table to modify</param>
2929
private static void AddColumn(WTable table)
3030
{
31+
// Loop through each row in the table
3132
for (int i = 0; i < table.Rows.Count; i++)
32-
table.Rows[i].AddCell();
33+
{
34+
// Add a new cell to the current row (appends at the end)
35+
WTableCell cell = table.Rows[i].AddCell();
36+
// Set the width of the new cell to match the first cell in the row
37+
cell.Width = table.Rows[i].Cells[0].Width;
38+
// Add a paragraph to the new cell and insert the text
39+
cell.AddParagraph().AppendText("Using Add API");
40+
}
3341
}
3442
/// <summary>
3543
/// Adds a new column at the specified index in the table.
@@ -48,6 +56,8 @@ private static void InsertColumn(WTable table, int indexToAdd)
4856
WTableCell newCell = new WTableCell(table.Document);
4957
// Insert the new cell at the specified index in the current row
5058
table.Rows[i].Cells.Insert(indexToAdd, newCell);
59+
// Add a paragraph to the new cell and insert the text
60+
newCell.AddParagraph().AppendText("Using Insert API");
5161
}
5262
}
5363
}
@@ -65,7 +75,7 @@ private static void RemoveColumn(WTable table, int indexToRemove)
6575
if (indexToRemove >= 0 && indexToRemove < table.Rows[i].Cells.Count)
6676
{
6777
// Remove the cell at the specified index in the current row
68-
table.Rows[i].Cells.Remove(table.Rows[i].Cells[indexToRemove]);
78+
table.Rows[i].Cells.RemoveAt(indexToRemove);
6979
}
7080
}
7181
}

0 commit comments

Comments
 (0)