Menu

[r1]: / trunk / class_excel_format.py  Maximize  Restore  History

Download this file

127 lines (110 with data), 4.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
class format(object):
def __init__(self):
self.conditiomal_formatting_operators_list_xl=['xlGreater','xlLess','xlBetween','xlEqual','xlNotEqual','xlNotBetween','xlGreaterEqual','xlLessEqual']
self.conditiomal_formatting_conversion_dict={
'<':'xlLess',
'>':'xlGreater',
'<=':'xlLessEqual',
'>=':'xlGreaterEqual',
'=':'xlEqual',
'<>':'xlNotEqual',
'between':'xlBetween',
'not between':'xlNotBetween'
}
def get_conditiomal_formatting_operators_list_xl(self):
return self.conditiomal_formatting_operators_list_xl
def get_conditiomal_formatting_operators_list(self):
return self.conditiomal_formatting_conversion_dict.keys()
def bold(self):
return {"Bold":True}
def text_center(self):
return {"HorizontalAlignment":"xlCenter","VerticalAlignment":"xlCenter"}
def cell_borders(self):
result={
'xlEdgeTop':{'LineStyle':'xlContinuous','Weight':'xlThin'},
'xlEdgeBottom':{'LineStyle':'xlContinuous','Weight':'xlThin'},
'xlEdgeLeft':{'LineStyle':'xlContinuous','Weight':'xlThin'},
'xlEdgeRight':{'LineStyle':'xlContinuous','Weight':'xlThin'}
}
return result
def fill_type1(self):
result={
"Pattern":"xlSolid",
"PatternColorIndex":"xlAutomatic",
"ThemeColor":"xlThemeColorDark1",
"TintAndShade":-0.249977111117893,
"PatternTintAndShade":0,
}
return result
def add_number_format(self,format,number_format):
if 'properties' in format:
format['properties']['NumberFormat']=number_format
else:
format['properties']={}
format['properties']['NumberFormat']=number_format
return format
def convert_conditional_formatting_to_xl(self,format):
assert format in self.get_conditiomal_formatting_operators_list()
return self.conditiomal_formatting_conversion_dict[format]
#---------------------------------------------------
def default_list_validation(self,list,formula=False):
"""
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
"""
result={}
result['Type']='xlValidateList'
result['AlertStyle']='xlValidAlertStop'
result['Operator']='xlBetween'
if not formula:
result['Formula1']=','.join(str(item) for item in list)
else:
result['Formula1']="=%s"%(list)
result['properties']={}
result['properties']['IgnoreBlank']=True
result['properties']['InCellDropdown']=True
result['properties']['InputTitle']=''
result['properties']['ErrorTitle']=''
result['properties']['InputMessage']=''
result['properties']['ErrorMessage']=''
result['properties']['ShowInput']=True
result['properties']['ShowError']=False
return result
def default_conditional_formatting(self,operator,formula1,formula2=None):
assert operator in self.conditiomal_formatting_operators_list_xl
assert isinstance(formula1, str)
result={}
result['Type']='xlCellValue'
result['Formula1']="=%s"%(formula1)
if formula2!=None:
assert isinstance(formula2, str)
result['Formula2']="=%s"%(formula2)
result['Operator']=operator
result['Font']={'Color': -16383844,'TintAndShade':0}
result['Interior']={'PatternColorIndex':'xlAutomatic','Color':13551615,'TintAndShade':0}
return result
def header_allign_left_cell(self):
result={}
result['font']=self.bold()
result['interior']=self.fill_type1()
result['borders']=self.cell_borders()
#result['properties']=self.text_center()
return result
def header_allign_center_cell(self):
result={}
result['font']=self.bold()
result['interior']=self.fill_type1()
result['borders']=self.cell_borders()
result['properties']=self.text_center()
return result
def allign_center_cell(self):
result={}
result['borders']=self.cell_borders()
result['properties']=self.text_center()
return result