@@ -13,19 +13,30 @@ static void Main(string[] args)
1313 // Access the first table in the document
1414 WTable table = ( WTable ) document . Sections [ 0 ] . Tables [ 0 ] ;
1515 // Add a new column at index
16- AddColumn ( table , 2 ) ;
16+ InsertColumn ( table , 1 ) ;
17+ // Add a column at the last index
18+ AddColumn ( table ) ;
1719 // Remove a column at the index
18- RemoveColumn ( table , 1 ) ;
20+ RemoveColumn ( table , 4 ) ;
1921 // Save the modified document to a new file
2022 document . Save ( Path . GetFullPath ( @"Output/Result.docx" ) , FormatType . Docx ) ;
2123 }
2224 }
2325 /// <summary>
26+ /// Adds a new column at the last index in the table
27+ /// </summary>
28+ /// <param name="table">The table to modify</param>
29+ private static void AddColumn ( WTable table )
30+ {
31+ for ( int i = 0 ; i < table . Rows . Count ; i ++ )
32+ table . Rows [ i ] . AddCell ( ) ;
33+ }
34+ /// <summary>
2435 /// Adds a new column at the specified index in the table.
2536 /// </summary>
2637 /// <param name="table">The table to modify.</param>
2738 /// <param name="indexToAdd">The index at which to insert the new column.</param>
28- private static void AddColumn ( WTable table , int indexToAdd )
39+ private static void InsertColumn ( WTable table , int indexToAdd )
2940 {
3041 // Loop through each row in the table
3142 for ( int i = 0 ; i < table . Rows . Count ; i ++ )
@@ -54,7 +65,7 @@ private static void RemoveColumn(WTable table, int indexToRemove)
5465 if ( indexToRemove >= 0 && indexToRemove < table . Rows [ i ] . Cells . Count )
5566 {
5667 // Remove the cell at the specified index in the current row
57- table . Rows [ i ] . Cells . RemoveAt ( indexToRemove ) ;
68+ table . Rows [ i ] . Cells . Remove ( table . Rows [ i ] . Cells [ indexToRemove ] ) ;
5869 }
5970 }
6071 }
0 commit comments