Hide multiple columns at once using ColumnDimension
Created originally on Bitbucket by sverkersbrg (Sverker Sjöberg)
I'm working on a project where I'm creating sheets containing a single DataTable and I am hiding all excessive (unused) columns. I do this by looping over each column and hiding them one by one. Unfortunately this produces one xml entry per column like
#!xml
<col min="7" max="7" hidden="1"/>
<col min="8" max="8" hidden="1"/>
<col min="9" max="9" hidden="1"/>
Is there any reason not to use a ColumnDimension to hide all columns and create an xml entry like this.
#!xml
<col width="0" max="16384" min="7" hidden="1"/>
This could be implemented by adding the method "hide" to the DimensionHolder
#!python
def hide(self, start, end):
if end is None:
end = start
new_dim = self[start]
new_dim.hidden = True
work_sequence = get_column_interval(start, end)[1:]
for column_letter in work_sequence:
if column_letter in self:
del self[column_letter]
new_dim.min, new_dim.max = map(column_index_from_string, (start, end))
It seems to work fine in my environment.
Awesome package, Sverker