|
| 1 | +def set_format_tipranks_sheet(self, size_dataframe, worksheet, workbook): |
| 2 | + cell_format = workbook.add_format() |
| 3 | + cell_format.set_bg_color('#FA8072') |
| 4 | + cell_format.set_font_color('#8B0000') |
| 5 | + |
| 6 | + worksheet.conditional_format(f'M2:M{size_dataframe}', {'type': 'cell', |
| 7 | + 'criteria': '<=', |
| 8 | + 'value': -0.6, |
| 9 | + 'format': cell_format}) |
| 10 | + |
| 11 | + cell_format2 = workbook.add_format() |
| 12 | + cell_format2.set_bg_color('#F79646') |
| 13 | + cell_format2.set_font_color('#FFFFFF') |
| 14 | + worksheet.conditional_format(f'M2:M{size_dataframe}', {'type': 'cell', |
| 15 | + 'criteria': 'between', |
| 16 | + 'minimum': -0.3, |
| 17 | + 'maximum': -0.6, |
| 18 | + 'format': cell_format2}) |
| 19 | + |
| 20 | + cell_format5 = workbook.add_format() |
| 21 | + cell_format5.set_bg_color('#F0E68C') |
| 22 | + cell_format5.set_font_color('#755811') |
| 23 | + worksheet.conditional_format(f'M2:M{size_dataframe}', {'type': 'cell', |
| 24 | + 'criteria': 'between', |
| 25 | + 'minimum': -0.0, |
| 26 | + 'maximum': -0.3, |
| 27 | + 'format': cell_format5}) |
| 28 | + |
| 29 | + cell_format3 = workbook.add_format() |
| 30 | + cell_format3.set_num_format('0.00%') |
| 31 | + worksheet.set_column('M:M', None, cell_format3) |
| 32 | + worksheet.set_column('U:U', None, cell_format3) |
| 33 | + |
| 34 | + currency_format = workbook.add_format({'num_format': '$#,##0.00'}) |
| 35 | + worksheet.set_column('C:I', None, currency_format) |
| 36 | + worksheet.set_column('L:L', None, currency_format) |
| 37 | + worksheet.set_column('T:T', None, currency_format) |
| 38 | + |
| 39 | + date_format = workbook.add_format({'num_format': 'yyyy-mm-dd'}) |
| 40 | + worksheet.set_column('AJ:AK', None, date_format) |
| 41 | + worksheet.set_column('AM:AM', None, date_format) |
| 42 | + |
| 43 | + number_format = workbook.add_format({'num_format': '#,##0.00'}) |
| 44 | + worksheet.set_column('J:K', None, number_format) |
| 45 | + worksheet.set_column('AI:AI', None, number_format) |
| 46 | + worksheet.set_column('N:N', None, number_format) |
| 47 | + |
| 48 | + bad_cell_format = workbook.add_format() |
| 49 | + bad_cell_format.set_bg_color(self.color_format['Bad']['bg']) |
| 50 | + bad_cell_format.set_font_color(self.color_format['Bad']['font']) |
| 51 | + |
| 52 | + good_cell_format = workbook.add_format() |
| 53 | + good_cell_format.set_bg_color(self.color_format['Good']['bg']) |
| 54 | + good_cell_format.set_font_color(self.color_format['Good']['font']) |
| 55 | + |
| 56 | + neutral_cell_format = workbook.add_format() |
| 57 | + neutral_cell_format.set_bg_color(self.color_format['Neutral']['bg']) |
| 58 | + neutral_cell_format.set_font_color(self.color_format['Neutral']['font']) |
| 59 | + |
| 60 | + warning_cell_format = workbook.add_format() |
| 61 | + warning_cell_format.set_bg_color(self.color_format['Warning']['bg']) |
| 62 | + warning_cell_format.set_font_color(self.color_format['Warning']['font']) |
| 63 | + |
| 64 | + accent2_cell_format = workbook.add_format() |
| 65 | + accent2_cell_format.set_bg_color(self.color_format['Accent2_20%']['bg']) |
| 66 | + accent2_cell_format.set_font_color(self.color_format['Accent2_20%']['font']) |
| 67 | + |
| 68 | + accent3_cell_format = workbook.add_format() |
| 69 | + accent3_cell_format.set_bg_color(self.color_format['Accent3_20%']['bg']) |
| 70 | + accent3_cell_format.set_font_color(self.color_format['Accent3_20%']['font']) |
| 71 | + |
| 72 | + green_cell_format = workbook.add_format() |
| 73 | + green_cell_format.set_font_color('#00FF00') |
| 74 | + |
| 75 | + red_cell_format = workbook.add_format() |
| 76 | + red_cell_format.set_font_color('#FF0000') |
| 77 | + |
| 78 | + black_cell_format = workbook.add_format() |
| 79 | + black_cell_format.set_font_color('#000000') |
| 80 | + |
| 81 | + five_level_cell_format_list = [ |
| 82 | + good_cell_format, accent3_cell_format, warning_cell_format, accent2_cell_format, bad_cell_format |
| 83 | + ] |
| 84 | + for i, five_level_cell_format in enumerate(five_level_cell_format_list): |
| 85 | + worksheet.conditional_format(f'O2:O{size_dataframe}', {'type': 'cell', |
| 86 | + 'criteria': '==', |
| 87 | + 'value': i + 1, |
| 88 | + 'format': five_level_cell_format}) |
| 89 | + |
| 90 | + worksheet.conditional_format(f'T2:T{size_dataframe}', {'type': 'formula', |
| 91 | + 'criteria': '=$U2>0', |
| 92 | + 'format': green_cell_format, |
| 93 | + }) |
| 94 | + worksheet.conditional_format(f'T2:T{size_dataframe}', {'type': 'formula', |
| 95 | + 'criteria': '=$U2<0', |
| 96 | + 'format': red_cell_format, |
| 97 | + }) |
| 98 | + worksheet.conditional_format(f'T2:T{size_dataframe}', {'type': 'formula', |
| 99 | + 'criteria': '=$U2="N/A"', |
| 100 | + 'format': black_cell_format, |
| 101 | + }) |
| 102 | + |
| 103 | + worksheet.conditional_format(f'U2:U{size_dataframe}', {'type': 'cell', |
| 104 | + 'criteria': '>', |
| 105 | + 'value': 0, |
| 106 | + 'format': green_cell_format}) |
| 107 | + worksheet.conditional_format(f'U2:U{size_dataframe}', {'type': 'cell', |
| 108 | + 'criteria': '<', |
| 109 | + 'value': 0, |
| 110 | + 'format': red_cell_format}) |
| 111 | + worksheet.conditional_format(f'U2:U{size_dataframe}', {'type': 'cell', |
| 112 | + 'criteria': '==', |
| 113 | + 'value': '"N/A"', |
| 114 | + 'format': black_cell_format}) |
| 115 | + |
| 116 | + green_cell_format = workbook.add_format() |
| 117 | + green_cell_format.set_font_color('#00FF00') |
| 118 | + |
| 119 | + red_cell_format = workbook.add_format() |
| 120 | + red_cell_format.set_font_color('#FF0000') |
| 121 | + |
| 122 | + black_cell_format = workbook.add_format() |
| 123 | + black_cell_format.set_font_color('#000000') |
| 124 | + |
| 125 | + gray_cell_format = workbook.add_format() |
| 126 | + gray_cell_format.set_font_color('#808080') |
| 127 | + |
| 128 | + smart_color_list = [ |
| 129 | + "#C00004", "#F08C8E", "#F3A3A5", "#EECD94", "#E9D686", "#E9DE85", "#E4DE85", "#C8E0A0", "#BAD988", "#AFCC80" |
| 130 | + ] |
| 131 | + |
| 132 | + for i, smart_color in enumerate(smart_color_list): |
| 133 | + smart_cell_format = workbook.add_format() |
| 134 | + smart_cell_format.set_font_color(smart_color) |
| 135 | + |
| 136 | + worksheet.conditional_format(f'V2:V{size_dataframe}', {'type': 'cell', |
| 137 | + 'criteria': '==', |
| 138 | + 'value': i + 1, |
| 139 | + 'format': smart_cell_format}) |
| 140 | + |
| 141 | + worksheet.conditional_format(f'W2:W{size_dataframe}', {'type': 'cell', |
| 142 | + 'criteria': '==', |
| 143 | + 'value': '"Bullish"', |
| 144 | + 'format': green_cell_format}) |
| 145 | + worksheet.conditional_format(f'W2:W{size_dataframe}', {'type': 'cell', |
| 146 | + 'criteria': '==', |
| 147 | + 'value': '"Bearish"', |
| 148 | + 'format': red_cell_format}) |
| 149 | + worksheet.conditional_format(f'W2:W{size_dataframe}', {'type': 'formula', |
| 150 | + 'criteria': 'AND($W2<> "Bullish", $W2 <>"Bearish")', |
| 151 | + 'format': gray_cell_format}) |
| 152 | + |
| 153 | + worksheet.conditional_format(f'X2:X{size_dataframe}', {'type': 'cell', |
| 154 | + 'criteria': '==', |
| 155 | + 'value': '"Increased"', |
| 156 | + 'format': green_cell_format}) |
| 157 | + worksheet.conditional_format(f'X2:X{size_dataframe}', {'type': 'cell', |
| 158 | + 'criteria': '==', |
| 159 | + 'value': '"Decreased"', |
| 160 | + 'format': red_cell_format}) |
| 161 | + worksheet.conditional_format(f'X2:X{size_dataframe}', {'type': 'formula', |
| 162 | + 'criteria': 'AND($W2<> "Increased", $W2 <>"Decreased")', |
| 163 | + 'format': gray_cell_format}) |
| 164 | + |
| 165 | + worksheet.conditional_format(f'Y2:Y{size_dataframe}', {'type': 'cell', |
| 166 | + 'criteria': '==', |
| 167 | + 'value': '"Bought Shares"', |
| 168 | + 'format': green_cell_format}) |
| 169 | + worksheet.conditional_format(f'Y2:Y{size_dataframe}', {'type': 'cell', |
| 170 | + 'criteria': '==', |
| 171 | + 'value': '"Sold Shares"', |
| 172 | + 'format': red_cell_format}) |
| 173 | + worksheet.conditional_format(f'Y2:Y{size_dataframe}', {'type': 'formula', |
| 174 | + 'criteria': 'AND($W2<> "Bought Shares", $W2 <>"Sold Shares")', |
| 175 | + 'format': gray_cell_format}) |
| 176 | + |
| 177 | + tipranks_investors_list = [ |
| 178 | + '"Very Positive"', '"Positive"', '"Neutral"', '"Negative"', '"Very Negative"' |
| 179 | + ] |
| 180 | + |
| 181 | + for i, five_level_cell_format in enumerate(five_level_cell_format_list): |
| 182 | + worksheet.conditional_format(f'Z2:Z{size_dataframe}', {'type': 'cell', |
| 183 | + 'criteria': '==', |
| 184 | + 'value': tipranks_investors_list[i], |
| 185 | + 'format': five_level_cell_format}) |
| 186 | + |
| 187 | + news_sentiment_list = [ |
| 188 | + '"Very Positive"', '"Positive"', '"Neutral"', '"Negative"', '"Very Negative"' |
| 189 | + ] |
| 190 | + |
| 191 | + for i, five_level_cell_format in enumerate(five_level_cell_format_list): |
| 192 | + worksheet.conditional_format(f'AA2:AA{size_dataframe}', {'type': 'cell', |
| 193 | + 'criteria': '==', |
| 194 | + 'value': news_sentiment_list[i], |
| 195 | + 'format': five_level_cell_format}) |
| 196 | + |
| 197 | + worksheet.conditional_format(f'AB2:AB{size_dataframe}', {'type': 'cell', |
| 198 | + 'criteria': '==', |
| 199 | + 'value': '"Positive"', |
| 200 | + 'format': green_cell_format}) |
| 201 | + worksheet.conditional_format(f'AB2:AB{size_dataframe}', {'type': 'cell', |
| 202 | + 'criteria': '==', |
| 203 | + 'value': '"Negative"', |
| 204 | + 'format': red_cell_format}) |
| 205 | + worksheet.conditional_format(f'AB2:AB{size_dataframe}', {'type': 'formula', |
| 206 | + 'criteria': 'AND($W2<> "Positive", $W2 <>"Negative")', |
| 207 | + 'format': gray_cell_format}) |
| 208 | + |
| 209 | + worksheet.conditional_format(f'AC2:AC{size_dataframe}', {'type': 'cell', |
| 210 | + 'criteria': '>', |
| 211 | + 'value': 0, |
| 212 | + 'format': green_cell_format}) |
| 213 | + worksheet.conditional_format(f'AC2:AC{size_dataframe}', {'type': 'cell', |
| 214 | + 'criteria': '<', |
| 215 | + 'value': 0, |
| 216 | + 'format': red_cell_format}) |
| 217 | + worksheet.conditional_format(f'AC2:AC{size_dataframe}', {'type': 'cell', |
| 218 | + 'criteria': '==', |
| 219 | + 'value': '"N/A"', |
| 220 | + 'format': black_cell_format}) |
| 221 | + |
| 222 | + worksheet.conditional_format(f'AD2:AD{size_dataframe}', {'type': 'cell', |
| 223 | + 'criteria': '>', |
| 224 | + 'value': 0, |
| 225 | + 'format': green_cell_format}) |
| 226 | + worksheet.conditional_format(f'AD2:AD{size_dataframe}', {'type': 'cell', |
| 227 | + 'criteria': '<', |
| 228 | + 'value': 0, |
| 229 | + 'format': red_cell_format}) |
| 230 | + worksheet.conditional_format(f'AD2:AD{size_dataframe}', {'type': 'cell', |
| 231 | + 'criteria': '==', |
| 232 | + 'value': '"N/A"', |
| 233 | + 'format': black_cell_format}) |
0 commit comments