Changeset - 973e47ae51b7
[Not reviewed]
0 1 0
Lance Edgar (lance) - 4 years ago 2020-09-18 11:15:35
lance@edbob.org
Allow overriding column header labels when writing Excel file
1 file changed with 5 insertions and 2 deletions:
0 comments (0 inline, 0 general)
rattail/excel.py
Show inline comments
 
@@ -114,16 +114,19 @@ class ExcelWriter(object):
 
        self.book = openpyxl.Workbook()
 
        self.sheet = self.book.active
 
        if sheet_title:
 
            self.sheet.title = sheet_title
 
        self.number_formats = number_formats
 

	
 
    def write_header(self):
 
    def write_header(self, labels=None):
 
        font = Font(bold=True)
 
        for i, field in enumerate(self.fields, 1):
 
            cell = self.sheet.cell(row=1, column=i, value=field)
 
            value = field
 
            if labels and field in labels:
 
                value = labels[field]
 
            cell = self.sheet.cell(row=1, column=i, value=value)
 
            cell.font = font
 

	
 
    def write_row(self, data, row=None):
 
        """
 
        Write (append) a single data row to the current sheet.
 

	
0 comments (0 inline, 0 general)