23958

xlwt code results in valueerror: More than 4094 XFs (styles)

Question:

I am trying to send results of a test to an Excel sheet. In all reality, it is written... poorly. For each piece of data I send to the excel sheet, I attach the style to that command, thus adding up the XF count passed 4094. For example, I have the following method that writes to the excel sheet. I want the text color of the row containing the status value "PASSED" to be green, and red for a status value of "FAILED". Also, I want all text to be bold and have a height of 240:

def writetolog(self, method, status, error, note): if status == "PASSED": col = xlwt.easyxf('font: colour green, bold 1, height 240') elif status == "FAILED": col = xlwt.easyxf('font: colour red, bold 1, height 240') timestamp = str(datetime.now().strftime("%y-%m-%d %H:%M:%S.%f"))[:-4] timesave = str(self.starttime.strftime("%y-%m-%d_%H-%M")) try: self.sheet.write(self.row, 0, status, col) self.sheet.write(self.row, 1, method, col) self.sheet.write(self.row, 2, note, col) self.sheet.write(self.row, 3, str(error), col) self.sheet.write(self.row, 4, timestamp, col) self.wkbk.save('Log/Logfile_%s.xls' % timesave) except Exception as e: print "something went wrong in the write to log method" print e finally: self.row += 1

This means that everytime I call this method (which is very frequently), it sends in a new style (only, it's just about always the same). I need a method of doing this without sending in the same format over and over again.

A similar question appeared here: <a href="https://stackoverflow.com/questions/17130516/xlwt-set-style-making-error-more-than-4094-xfs-styles" rel="nofollow">xlwt set style making error: More than 4094 XFs (styles)</a>

While it has an answer, it is for compressing the data, which is not what I am aiming to do. A comment on the answer says that you should not repeatedly call xlwt.easyxf with the same formats, so I'm trying to figure out how to do it without the constant use of it.

So, how should I write to the excel sheet with the following criteria without constantly sending a new style to excel:

- If the status value is "PASSED", the text color of the entire row is green - If the status value is "FAILED", the text color of the entire row is red - All data is bold - All data is height 240

There's due to be a way to set conditional formatting of the entire file via xlwt?

Answer1:

Wanted to add this as a comment but I do not have enough reputation. I have been battling with a similar conditional formatting problem and setting the style_compression = 2 as recommended in that other question solved it for me (no, it doesn't compress the data only the styles), however I can see that even with a relatively small spreadsheet there is now a noticeable processing delay.

Otherwise, you have to define all your styles in advance (i.e. outside of the loop) which can be a bit of a hassle if there is only one formatting parameter different here and there.

Recommend

  • Installing pygame for python3 in mac using anaconda
  • Python XLWT: Write a list into a cell
  • UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 11: invalid start
  • Python to save needed rows in Excel contents
  • How i change fill color of graphics in create js
  • Compare a column between 2 csv files and write differences using Python
  • href inside href [duplicate]
  • Samsung Galaxy Tab 10.1 and -webkit-tap-highlight-color style?
  • Absolutely positioned pseudo element inside table cell does not cover parent in IE9/10
  • Division with Aggregate Functions in SQL Not Behaving as Expected
  • How to add specific media query rule when media query combined
  • Base Internationalization and “Could not find a storyboard named […]”
  • Python multiprocessing of a sum
  • Error in GGally: Error in unit(tic_pos.c, “mm”) : 'x' and 'units' must have leng
  • How could I prohibit anonymous access to my NodeRed UI Dashboard on IBM Cloud(Bluemix)?
  • UIButton Borders Function Only Gives Back White Borders
  • Formatting a text in a table cell with PHPWord e.g. bold, font, size e.t.c
  • Select inner HTML item in CSS
  • Flex items with same property values are rendering in different sizes
  • Understanding RTF and edit it with vb.net
  • ggplot2: make the points on the line a darker color than the line color
  • How To Customize ASP.NET Chart Databound To SqlDataSource
  • gspread or such: help me get cell coordinates (not value)
  • How to modify the colors in the legend of a plot using a fill gradient?
  • VSO Build — Response status code does not indicate success: 404 (Not Found)
  • Highlight and Bold text in JTextPane
  • ilmerge with a PFX file
  • Xamarin Forms - UWP Fonts
  • How to convert from System.Drawing.Color to Excel.ColorFormat in C#? Change comment color
  • Validaiting emails with Net.Mail MailAddress
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • Change an a tag attribute in JavaScript based on screen width
  • Javascript + PHP Encryption with pidCrypt
  • align graphs with different xlab
  • Unanticipated behavior
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Android Google Maps API OnLocationChanged only called once
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass