Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created June 8, 2023 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/ce4285a03aae61d3a918649c4c1072d3 to your computer and use it in GitHub Desktop.
Save bjoerntx/ce4285a03aae61d3a918649c4c1072d3 to your computer and use it in GitHub Desktop.
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