Note that there are some explanatory texts on larger screens.

plurals
  1. POmissing attribute error when trying to set cell color in xlwt using python
    primarykey
    data
    text
    <p>I'm trying to change the color of my excel spreadsheet to color code data using python's xlwt package. Here's my current code:</p> <pre><code>from xlrd import open_workbook from tempfile import Temporary File from xlwt import sys import csv .... ....#Some other code style = xlwt.XFStyle() #this is the line throwing the error pattern = xlwt.Pattern() pattern.pattern = xlwt.Pattern.SOLID_PATTERN pattern.pattern_fore_colour = xlwt.Style.colour_map['red'] pattern.pattern_fore_colour = xlwt.Style.colour_map['red'] newSheet.write(row, col, values[row - 1][col], pattern) .... ....#Some other code </code></pre> <p>Other code sections are there because it is a longer script than shown but those sections of code aren't related to this problem</p> <p>I get the following stack trace when it runs:</p> <pre><code>Traceback (most recent call last): File "excel-procesor.py", line 85, in &lt;module&gt; newSheet.write(row, col, values[row - 1][col], pattern) File "/usr/local/lib/python2.7/dist-packages/xlwt/Worksheet.py", line 1030, in write self.row(r).write(c, label, style) File "/usr/local/lib/python2.7/dist-packages/xlwt/Row.py", line 234, in write self.__adjust_height(style) File "/usr/local/lib/python2.7/dist-packages/xlwt/Row.py", line 64, in __adjust_height twip = style.font.height AttributeError: 'Pattern' object has no attribute 'font' </code></pre> <p>I'm using <a href="https://stackoverflow.com/questions/10532367/how-to-change-background-color-of-excel-cell-with-python-xlwt-library">How to change background color of excel cell with python xlwt library?</a> and <a href="https://stackoverflow.com/questions/7746837/python-xlwt-set-custom-background-colour-of-a-cell">python xlwt set custom background colour of a cell</a> as guides.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload