question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: Allow identifying formats by name

See original GitHub issue

Today, when dealing with complex an multiple formats, I use the following piece of code to be able to retrieve them at the time to write data :

def register_formats(wb, d):
    return {k: wb.add_format(v) if v is not None else v for k, v in d.items()}

#my_formats d parameter simplified for readability sake
my_formats = register_formats(workbook, {
        'error':  {'bg_color': '#cc0000'},
        'warning': {'bg_color': '#ffff00'},
        'ok': None})

# Much farther in the program ...

ws = wb.add_worksheet()
ws.write(0,0,"text", my_formats['error'])

but then one has to pass this my_format dictionary around.

I suggest to extend the workbook interface with an optional ref parameter, and then in the write functions be able to give the reference of the format rather than the format itself. It would result in something like :

wb.add_format({'bg_color': '#cc0000'}, ref="error")

#####

ws.write(0,0,"text", format_ref="error")

I can propose an implementation if that helps.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:18 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
jmcnamaracommented, Jun 2, 2016

I’m going to leave the discussion of #111 to that thread.

For this feature a straight forward interface (and implemention) would be to add a user definable name field to the format object that would allow you to do this:

my_format = workbook.add_format({'name': 'error',
                                 'bold': True,  
                                 'font_color': 'red'})

# ...
error_format = workbook.get_format_by_name('error')

worksheet.write('A2', 'Hello', error_format)

Would that meet the needs of the 1+ers?

There are a couple of internal gottas that I would have to workaround but it would be doable.

The second part about adding a ref parameter to all the write_*() functions, I’m not keen on. It would just complicate the interface, docs and testing.

P.S. get_format() would probably be a better method name and as an aside get_worksheet_by_name() should probably been called get_worksheet() (the _by_name() part is implied and a little long).

0reactions
jmcnamaracommented, Aug 17, 2018

I’m going through some older feature requests into XlsxWriter and closing out ones that I am unlikely to work on in the near future. This is one of them unfortunately.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Manage Feature Requests [Template included]
This guide will teach you everything about feature requests – how to process them, manage them, respond to them, prioritize them – so...
Read more >
Feature Requests: What are they and how to manage them
Feature requests are a form of product feedback you may frequently encounter as a SaaS product manager. They typically come in the form...
Read more >
Feature Request Template: How to Collect User Feedback ...
Looking for the best feature request templates? Here's how to collect feedback with examples from the best SaaS companies.
Read more >
Feature request tracking: Guide, tools & best practices - Beamer
Feature requests are feedback forms that customers can fill out to ask for new features or suggest improvements to existing ones.
Read more >
What Is a Feature Request? Definition and Examples - Airfocus
A feature request is a comment, message, or ask from a user to implement a specific feature into your product. Feature requests can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found