-
-
Notifications
You must be signed in to change notification settings - Fork 639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Support for copying the Format instance #81
Comments
Hi Constantin, Yes, that should be possible. I actually had a Could you give me a small code example of what you are trying/would like to do. John |
|
I'll leave that as a feature request and add it in if it gets a few +1s. In the meantime, URLs get a default blue underline format from XlsxWriter if none is supplied. So you may be able to use that feature instead: import xlsxwriter
workbook = xlsxwriter.workbook.Workbook('url.xlsx')
worksheet = workbook.add_worksheet()
worksheet.set_column('A:A', 20)
worksheet.write(
'A1',
'http://www.python.org',
None, # Note. No format.
u'Some text')
workbook.close() |
OK, thanks for the info. But I don't think this will be the only use case when I may need to apply additional formatting to a separate cell. Also, in LibreOffice, the link is not underlined (although I don't think it's crucial for presenting the spreadsheet to our client). So I agree that this issue shouldn't be closed. |
👍 for sure I think it would be useful to have a format1.update(source) method also, to update format1 with a dict or another format or format1.combine(format2), to return a new combined format (to not change format1) Working with data and pandas, I see myself almost each time thinking about how I could combine formats for different columns and rows UPDATE1 |
Thanks for the 👍 Format copying and updating will be handled as part of #111 "Feature request: Separate data and formatting". I just need to carve out the time to tackle that. :-) |
Just for reference I guess, I implemented in a rush these 2 functions, format_copy() and format_update() from copy import copy
def format_copy(format):
'''returns a copy of the format
'''
return copy(format)
def format_update(format, d, inplace=False):
'''updates format with a dict d
format: the format
d: dict with new attributes
inplace: bool
if format should be modified or not
'''
if inplace:
fmt = format
else:
fmt = format_copy(format)
fmt.__dict__.update(d)
return fmt UPDATE if I get them to work, I will update this comment |
@jmcnamara for my needs, working with pandas mostly, but maybe #111 is way better, I don't know just wanted to say: "take your time with #111" |
Formats have to be created via the So a straight copy won't work. Copying properties from 2 format objects created with |
What do you mean: "copying properties from 2 format objects" ? maybe two objects of format type? so then I should first create a new workbook.add_format(), then copy, then return it? |
+1 to copying formats, my code is out of hand from duplicating the same things over and over again |
Copying formats would be a huge help to me. |
👍 would like to see this @jmcnamara I just recently discovered xlsxwriter...excellent work |
+1 for copying formats |
+1 |
+1 for copying formats, or overloading workbook.add_format() to take as input an existing format, and it will make the copy plus add the new format. |
+1 for copy and update format..... |
+1 from me too. |
I wrote this helper function to copy formats for me. It's ugly, error prone (I don't know what each field means), and incomplete (I only copy fields I needed copied in my code because I was too lazy to fill in the rest). Feel free to modify it. Hopefully this feature gets implemented in the future so we don't have to use this.
Usage:
|
I wrote the following which might be a bit cleaner:
I used it for setting borders, so my use case was (for example):
|
+1 for copying formats |
+1 For copy formats, and may I add a constructor to create a format from a cell |
+1 |
1 similar comment
+1 |
+1 |
2 similar comments
+1 |
+1 |
Thanks a lot for having posted this !
|
I'm unlikely to get to implement this. Closing. |
+1 for re-open cannot understand why was closed |
I wrote 2 functions:
|
Reopening this issue on adding support for a |
Is it possible to add the subject? So that when we have a "general" format for the data processed in a loop, we could e.g. assign a separate Format instance to the cells that we want to write the hyperlinks into.
The text was updated successfully, but these errors were encountered: