Setting the footer text to a string that starts with a number and contains a non-numeric character prevents proper setting of the footer text size.

Issue #859 resolved
Kendall Searing
created an issue

The below code creates a footer with a left section font size of 409.

#!/usr/bin/env python
# -*- coding: utf-8 -*- 

import openpyxl
import os

root = os.path.dirname(os.path.abspath(__file__))
file = root + "/footer test.xlsx"

book = openpyxl.Workbook()
sheet = book.active
sheet.sheet_view.view = "pageLayout"

sheet.oddFooter.left.text = "2017s"
sheet.oddFooter.left.size = 8

book.save(file)

Comments (5)

  1. Jacob Scherber

    Looking at the XML generated, I might have found the issue. On the oddFooter tag, it uses &8 to specify the font size, with the 2017 listed afterwards. The font though should use the format

    &nn   Selects the specified 2-digit font point size
    

    as listed in the Header_footer class, so it's being read as font of &82. It's saving correctly in python as can be verified by re-printing the values. It must be an issue when it's being saved out. Changing it to format as a 2 digit may fix it.

    As an aside, the text in the opened excel file only shows up as an "s" so maybe it's grabbing the whole 2017 as part of the font size

  2. Jacob Scherber

    In Excel natively, this is done by place a leading space ahead of the footer text containing a leading digit (try it yourself, create an excel file with a numeric footer, save it, and re-open it, there now will be a leading space). In the meantime before a bug-fix can be pushed out, you could put a space ahead of any footers you are using that start with a number.

  3. CharlieC

    Thanks for the report and investigation. The specification doesn't go into any greater detail so it looks like adding the space is something Excel does automatically and which client code would have to manage itself, eg. sheet.oddFooter.left.text = " 2017s"

    The implementers notes do contain some more information saying that the formatting language is actually ABNF and that there is an empty token (which can be &. At some point might look at using a proper parser to handle this stuff.

  4. CharlieC

    Seems to be safe always to add a single space after the font size. Would be useful to switch to something like ABNF.py at some point if someone would help getting the code to work.

  5. Log in to comment