Menu

[r8]: / trunk / example.py  Maximize  Restore  History

Download this file

62 lines (49 with data), 1.9 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
from excel_com import excel_com
from class_excel_format import format
from error_class import myerror
#Example of usage for excel_class
def main():
e=myerror()
x=excel_com(e)
f=format()#Formatting class
x.connect()#Connect to Excel program
x.add_workbook()#Add workbook
x.delete_sheet("Sheet3")# Delete sheet by name
x._set_cell_value(sheet="Sheet1", row=1, col=1, value='Hello!') #Write value of single cell
data=[
['Col1','Col2','Col3'],
[1,5,2],
[2,4,3],
[3,3,4],
[4,2,5]
]
#Set value of range of cells using data from list
x._set_range_value(sheet="Sheet1",row1=2, col1=1,row2=6, col2=3,data=data,type='value')
#Set borders for single cell
#Create borders format definition dictionary
borders={
'xlEdgeTop':{'LineStyle':'xlContinuous','Weight':'xlThin'},
'xlEdgeBottom':{'LineStyle':'xlContinuous','Weight':'xlThin'},
'xlEdgeLeft':{'LineStyle':'xlContinuous','Weight':'xlThin'},
'xlEdgeRight':{'LineStyle':'xlContinuous','Weight':'xlThin'}
}
x.set_cell_borders(sheet="Sheet1", row=1, col=1,format_data=borders)#Set borders for single cell
#Set borders for selection
x._select_range(sheet="Sheet1",row1=2, col1=1,row2=6, col2=3)#Select range of cells
x.set_cell_borders_selection(borders)#Set bordets for selected cells
#Set fill colour of single cell
fill_defenition={
"Pattern":"xlSolid",
"PatternColorIndex":"xlAutomatic",
"ThemeColor":"xlThemeColorDark1",
"TintAndShade":-0.249977111117893,
"PatternTintAndShade":0
}
x.set_interior( sheet="Sheet1", row=1, col=1,format=fill_defenition)
#Set fill colour of selection
x._select_range(sheet="Sheet1",row1=2, col1=1,row2=2, col2=3)#Select range of cells
x.set_interior_selection(fill_defenition)
#Set text alignment for single cell
if __name__=="__main__":
main()
exit(0)