Changeset 5bcc3ba in rattail
- Timestamp:
- 10/30/2022 04:56:02 PM (3 months ago)
- Branches:
- master
- Children:
- a2e54d9
- Parents:
- 0189de2
- Location:
- rattail
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
rattail/excel.py
r0189de2 r5bcc3ba 196 196 """ 197 197 198 def __init__(self, path, fields, sheet_title=None, number_formats={}): 198 def __init__(self, path, fields, sheet_title=None, number_formats={}, 199 highlight_rows=True): 199 200 """ 200 201 Constructor; opens an Excel workbook for writing. … … 207 208 self.sheet.title = sheet_title 208 209 self.number_formats = number_formats 210 self.highlight_rows = highlight_rows 211 212 def load_workbook(self, path, clear_sheet=False): 213 self.book = openpyxl.load_workbook(filename=path) 214 self.sheet = self.book.active 215 216 if clear_sheet: 217 # remove all non-header rows from the sheet 218 # TODO: make header row count configurable 219 self.sheet.delete_rows(2, self.sheet.max_row) 209 220 210 221 def create_sheet(self, title): … … 251 262 252 263 # apply row highlighting 253 if row % 2 == 0: 254 fill_even = PatternFill(patternType='solid', 255 fgColor='d9d9d9', 256 bgColor='d9d9d9') 257 for col, field in enumerate(self.fields, 1): 258 cell = self.sheet.cell(row=row, column=col) 259 cell.fill = fill_even 264 if self.highlight_rows: 265 if row % 2 == 0: 266 fill_even = PatternFill(patternType='solid', 267 fgColor='d9d9d9', 268 bgColor='d9d9d9') 269 for col, field in enumerate(self.fields, 1): 270 cell = self.sheet.cell(row=row, column=col) 271 cell.fill = fill_even 260 272 261 273 def write_rows(self, rows, progress=None): -
rattail/reporting/excel.py
r0189de2 r5bcc3ba 52 52 Optional list of fields which should be "totalled" and represented in a 53 53 final totals row within the output. 54 55 .. attr:: write_data_header 56 57 Boolean flag (true by default) indicating that a header row 58 with field names should be written to the data sheet. Set this 59 to false if you are using a template file. 60 61 .. attr:: auto_format_data 62 63 Boolean flag (true by default) indicating that certain 64 "auto-formatting" should be applied to the data sheet. 65 66 .. attr:: include_summary_sheet 67 68 Boolean flag (true by default) indicating that a second 69 "summary" sheet should be added to the output file. 54 70 """ 55 71 output_fields = [] 56 72 number_formats = {} 57 73 totalled_fields = [] 74 write_data_header = True 75 auto_format_data = True 76 include_summary_sheet = True 58 77 59 78 def make_filename(self, session, params, data, **kwargs): … … 80 99 Write the primary data sheet for the Excel output file. 81 100 """ 82 writer.write_header() 101 if self.write_data_header: 102 writer.write_header() 83 103 fields = self.get_output_fields(params) 84 104 … … 117 137 cell.fill = fill_totals 118 138 119 writer.auto_freeze() 120 writer.auto_filter() 121 writer.auto_resize() 139 if self.auto_format_data: 140 writer.auto_freeze() 141 writer.auto_filter() 142 writer.auto_resize() 122 143 123 144 def write_summary_sheet(self, writer, session, params, data, … … 160 181 self.write_data_sheet(writer, session, params, data, progress=progress) 161 182 162 self.write_summary_sheet(writer, session, params, data, progress=progress) 183 if self.include_summary_sheet: 184 self.write_summary_sheet(writer, session, params, data, 185 progress=progress) 163 186 164 187 writer.save(progress=progress)
Note: See TracChangeset
for help on using the changeset viewer.