Created
June 8, 2023 12:30
-
-
Save bjoerntx/ce4285a03aae61d3a918649c4c1072d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class TableExtender { | |
public static void RemoveEmptyColumns(this Table table) { | |
List<TableColumn> columns = new List<TableColumn>(); | |
foreach (TableColumn col in table.Columns) { | |
bool foundText = false; | |
foreach (TableRow row in table.Rows) { | |
if (row.IsHeader == true) continue; | |
if (table.Cells[row.Row, col.Column].Text != "") { | |
foundText = true; break; | |
} | |
} | |
if (!foundText) { columns.Add(col); } | |
} | |
foreach (TableColumn column in columns) { | |
table.Cells[1, column.Column].Select(); | |
table.Columns.Remove(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment