[pyxl] XlsxWriter feature idea - friendlier way to set default cell format

2,332 views
Skip to first unread message

John Yeung

unread,
Jun 20, 2013, 5:22:26 PM6/20/13
to python-excel
This is not even a specific proposal, let alone a request.

Right now, we can change the default font from Calibri 11 to Arial 10
by modifying the default format as follows:

from xlsxwriter.workbook import Workbook
wb = Workbook('myfile.xlsx')
wb.formats[0].font_name = 'Arial'
wb.formats[0].font_size = 10

(Or we can use the corresponding setter methods.) This is OK, I
guess, but not documented. I'm wondering if it makes sense to add
something friendlier. But even if so, I don't know what to add.

For example, it would be simple to grab the return value here

# Add the default cell format.
self.add_format({'xf_index': 0})

and give it a friendly name instead of discarding it. Or, if the
overwhelming use case for futzing with this format is to change the
font, then maybe a special setter function which accepts a name-size
tuple. Or allow another optional parameter to the workbook
constructor. Or maybe doing anything to the default format is too
esoteric, and formats[0] is just fine, tyvm.

In case it's not obvious, my own motivation for this is to let me set
up column widths (particularly autofit) based on the same character
widths I used with xlwt.

John Y.

John McNamara

unread,
Jun 21, 2013, 10:39:19 AM6/21/13
to python...@googlegroups.com


On Thursday, 20 June 2013 22:22:26 UTC+1, John Yeung wrote:
This is not even a specific proposal, let alone a request.

Right now, we can change the default font from Calibri 11 to Arial 10
by modifying the default format as follows:

Hi John,

As far as I remember Excel changes the default font in the theme.xml file. The default font in XlsxWriter is mainly for internal purposes.

The main reason that XlsxWriter doesn't support changing the default font is that it has a lot of side effects. For example, the default row and (possibly column) size changes. This in turn affects the size of any worksheet object such as images, charts and comments.

So in the end it wouldn't be possible to support arbitrary default fonts and font sizes and accurately size worksheet objects.

John
Reply all
Reply to author
Forward
0 new messages