Hiya,
Am .10.2014, 20:36 Uhr, schrieb <
shawn....@gmail.com>:
> I've tried this several ways, and get errors every way I try. I want to
> set
> a Style for an entire row. Documentation says to do it like so:
> row = ws.row_dimensions[1]
> row.style = Style()
That should work without a problem. At least it does here and when the
documentation is checked.
> When I do this, I get a "'NoneType' object has no attribute 'parent'"
> error
> at
> File
> "C:\Virtual\Dj17_OPXL21\lib\site-packages\openpyxl\worksheet\dimensions.py",
> line 52, in style
> self._style = self.worksheet.parent.shared_styles.add(style)
This tells us that self.worksheet is None. Are you working with an
existing file or creating a new one? RowDimensions are created only when
new rows are (implicitly) added but you should get an IndexError
> My specific code is as follows:
> self.column_header_style = Style(font=self.bold_11, alignment=self.
> centered, border=self.top_bottom_thick_border)
> ...
> row = self.worksheet.row_dimensions[4]
> row.style = self.column_header_style
What is "self" here?
> I also tried to do it directly on the RowDimension object that I use to
> add
> the row to the worksheet, like so:
> rd = RowDimension(index=4)
> rd.style = self.column_header_style
> self.worksheet.row_dimensions[4] = rd
That will fail because you need to pass in a worksheet to the RowDimension
> I get the exact same error both times. Is this a bug, or am I doing
> something wrong. Please help!
Can you paste the whole section of code related to creating this row?
Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel:
+49-211-600-3657
Mobile:
+49-178-782-6226