0

I have what I feel could be a silly question but it seems I can't find the answer:

  • How to, while exporting to Excel, set a row/range to bold?

I know how to conditional format e.g.

    format1 = workbook.add_format({'bg_color': '#FFC7CE',
                                   'font_color': '#9C0006'})
...

        worksheet.conditional_format('C2:AF41', {'type': 'cell', 'criteria': '<', 'value': 0, 'format': format1})

or even to format columns:

    border_format = workbook.add_format({
                                'border': 1,
                                'align': 'center',
                                'font_size': 10
                               })
...

        worksheet.set_column(0, 0, 30, border_format)

But let's say I want for row A1:A40 to be written in bold, whitout any particular criteria? I just want to set to bold or a color or any formatting a given range whatever data it may contain.

In this case, for instance, apply 'format1' to range A1:A40 whatever the values.

Does anyone know the answer?

Darth Vagrant
  • 139
  • 3
  • 13
  • Possible duplicate of [xlswriter formatting a range](https://stackoverflow.com/questions/34026362/xlswriter-formatting-a-range) – ASGM Oct 04 '18 at 13:23

1 Answers1

1

It looks like there isn't a helper function specifically designed for this, according to github.

But Gabriel's answer to a similar question proposes a workaround, where you use two (or more) conditional formats to cover all values:

worksheet.conditional_format('A1:A40', {'type': 'cell', 
    'criteria': '>=', 'value': 0, 'format': format1})
worksheet.conditional_format('A1:A40', {'type': 'cell', 
    'criteria': '<', 'value': 0, 'format': format1})
ASGM
  • 11,051
  • 1
  • 32
  • 53
  • So there is no 'plain' format without condition as helper function of the kind: `worksheet.format('A1:A40', {'bold': True}`. I had seen that answer but honestly didn't quite get it at the time :). To apply 2 conditional formats to cover all values, I understand now, thank you! – Darth Vagrant Oct 04 '18 at 14:52