def insert(self): if DEBUG: print('Adding number...') table = self.cell_object.cell.add_table(rows=1, cols=1) if DEBUG: table.style = 'Table Grid' # add background color background_color = self.section.layout.get('style', {}).get( 'backgroundColor', '')[1:] # Add the main number inner_cell = table.cell(0, 0) style_cell(inner_cell, color_hex=background_color) main_number = CellObject(inner_cell) sign = self.section.layout.get('sign', '') sign = '' if sign is None else sign insert_text(main_number, str(self.section.contents) + sign, self.style['main']) main_number.add_paragraph(add_run=True) insert_text(main_number, str(self.section.extra['title']), self.style['title'])
def insert(self): if DEBUG: print('Adding number...') table = self.cell_object.cell.add_table(rows=1, cols=1) if DEBUG: table.style = 'Table Grid' # Add the main number inner_cell = table.cell(0, 0) style_cell(inner_cell) main_number = CellObject(inner_cell) insert_text(main_number, str(self.section.contents), self.style['main']) main_number.add_paragraph(add_run=True) insert_text(main_number, str(self.section.extra['title']), self.style['title'])
def insert(self): if DEBUG: print('Adding error element...') style = { 'bold': False, 'color': '#ff0013', 'fontSize': 10, 'underline': False, 'strikethrough': False, 'italic': False } # Add some padding table = self.cell_object.cell.add_table(rows=1, cols=1) if DEBUG: table.style = 'Table Grid' inner_cell = table.cell(0, 0) style_cell(inner_cell, {"top": 50, "bottom": 50}) error_message = f'ERROR GENERATING SECTION ({self.section.contents})' utils.insert_text(inner_cell, error_message, style)
def insert(self): if DEBUG: print("Adding trend...") table = self.cell_object.cell.add_table(rows=2, cols=4) # add background color background_color = self.section.layout.get('style', {}).get('backgroundColor', '')[1:] # Add the main number current_sum = self.section.contents['currSum'] inner_cell = table.cell(0, 1) style_cell(inner_cell, color_hex=background_color) main_number = CellObject(inner_cell) insert_text(main_number, str(current_sum), self.style['main']) # Add the trend number previous_sum = self.section.contents['prevSum'] # Fix for the percentages divider = previous_sum if previous_sum == 0: divider = 1 change = ((current_sum - previous_sum) * 100) / divider if change < 0: direction = '▼' # Down arrow elif change == 0: direction = '= ' else: direction = '▲' # Up arrow if change > 999.0: change = '> 999' elif change < -999.0: change = '< -999' else: change = "{0:.2f}".format(change) value_percent = f'{direction}{change}%' inner_cell = table.cell(0, 2) style_cell(inner_cell, color_hex=background_color) trend_number = CellObject(inner_cell) insert_text(trend_number, value_percent, self.style['trend']) # Add the title third_cell = table.cell(1, 1) style_cell(third_cell, color_hex=background_color) table.cell(1, 2).merge(third_cell) title = CellObject(third_cell) insert_text(title, str(self.section.extra['title']), self.style['title'])
def insert(self): if DEBUG: print("Adding trend...") table = self.cell_object.cell.add_table(rows=2, cols=4) # Add the main number current_sum = self.section.contents['currSum'] inner_cell = table.cell(0, 1) style_cell(inner_cell) main_number = CellObject(inner_cell) insert_text(main_number, str(current_sum), self.style['main']) # Add the trend number previous_sum = self.section.contents['prevSum'] # Fix for the percentages if previous_sum == 0: previous_sum = 1 change = (current_sum * 100) / previous_sum if change < 0: direction = '⏷' # Down arrow elif change == 0: direction = '= ' else: direction = '⏶' # Up arrow change = "{0:.2f}".format(change) value_percent = f'{direction}{change}%' inner_cell = table.cell(0, 2) style_cell(inner_cell) trend_number = CellObject(inner_cell) insert_text(trend_number, value_percent, self.style['trend']) # Add the title third_cell = table.cell(1, 1) style_cell(third_cell) table.cell(1, 2).merge(third_cell) title = CellObject(third_cell) insert_text(title, str(self.section.extra['title']), self.style['title'])
def insert(self): if DEBUG: print("Adding duration...") contents = self.section.contents days = '0' hours = '0' minutes = '0' if contents: result = 0 if len(contents) > 0 and isinstance( contents[0]['data'], list) and len(contents[0]['data']) > 0: result = contents[0]['data'][0] days = floor(result / (3600 * 24)) result -= days * 3600 * 24 hours = floor(result / 3600) result -= hours * 3600 minutes = floor(result / 60) days = format_number(days) hours = format_number(hours) minutes = format_number(minutes) # Split the table as so: # +---------------+ # | Title | # +---------------+ # | H |:| M |:| S | # +---+-+---+-+---+ # .cell(row, col) set_cell_margins(self.cell_object.cell, {"top": 50}) table = self.cell_object.cell.add_table(rows=2, cols=5) if DEBUG: table.style = 'Table Grid' title_cell = table.cell(0, 0) style_cell(title_cell) title_cell.merge(table.cell(0, 4)) title = DEFAULT_DURATION_TITLE if 'title' in self.section.extra: title = self.section.extra['title'] elif len(contents ) > 0 and 'name' in contents[0] and contents[0]['name'] != '': title = contents['data']['name'] insert_text(title_cell, title, self.style['title']) # Days days_cell = table.cell(1, 0) style_cell(days_cell) insert_text(days_cell, days, self.style['duration']) insert_text(days_cell, DURATION_DAYS_LABEL, self.style['label'], add_run=True) # Add first colon colon_right = table.cell(1, 1) style_cell(colon_right) insert_text(colon_right, ':', self.style['duration']) # Hours hours_cell = table.cell(1, 2) style_cell(hours_cell) insert_text(hours_cell, hours, self.style['duration']) insert_text(hours_cell, DURATION_HOURS_LABEL, self.style['label'], add_run=True) # Add second colon colon_left = table.cell(1, 3) style_cell(colon_left) insert_text(colon_left, ':', self.style['duration']) # Minutes minutes_cell = table.cell(1, 4) style_cell(minutes_cell) insert_text(minutes_cell, minutes, self.style['duration'], add_run=True) insert_text(minutes_cell, DURATION_MINUTES_LABEL, self.style['label'], add_run=True)