Package parasol :: Module xlChFormula
[hide private]
[frames] | no frames]

Source Code for Module parasol.xlChFormula

 1  import string 
 2   
3 -def getNcolFromLetter( colLet ):
4 if len(colLet)==2: 5 Ncol = 26*(ord( string.upper(colLet[0]) ) - 64) + ord( string.upper(colLet[1]) ) - 64 6 elif len(colLet) ==1: 7 Ncol = ord( string.upper(colLet) ) - 64 8 else: 9 Ncol = 1 10 return Ncol
11
12 -def getNcolNrow( cell="$a$1"):
13 sp = string.split( cell, '$') 14 Ncol=1 15 Nrow=1 16 try: 17 Ncol = getNcolFromLetter( sp[1] ) 18 Nrow = string.atoi( sp[2] ) 19 except: 20 pass 21 return Ncol, Nrow
22
23 -def getNcolumnsNrowsFromRange( crange="$A$1:$D$8" ):
24 sp = string.split( crange, ':' ) 25 Ncolumns=0 26 Nrows=0 27 try: 28 if len(sp[1])>0: 29 Nc1, Nr1 = getNcolNrow( sp[0] ) 30 Nc2, Nr2 = getNcolNrow( sp[1] ) 31 Ncolumns = Nc2 - Nc1 + 1 32 Nrows = Nr2 - Nr1 + 1 33 except: 34 pass 35 return Ncolumns, Nrows
36
37 -class xlChFormula:
38 '''excel spreadsheet chart formulas for XY Series''' 39
40 - def setLabel(self, col=1, row=1, Sheet=''):
41 self.labelLoc = self.makeColLocation( NColumn=col, NRow=row) 42 if len(Sheet)>0: self.labelSht = Sheet
43
44 - def setXColumn(self, col=1, topRow=2, botRow=100, Sheet=''):
45 self.xcolRng = self.makeColRange( NColumn=col, fromRow=topRow, toRow=botRow) 46 if len(Sheet)>0: self.xcolSht = Sheet
47
48 - def setValueColumn(self, col=1, topRow=2, botRow=100, Sheet=''):
49 self.valRng = self.makeColRange( NColumn=col, fromRow=topRow, toRow=botRow) 50 if len(Sheet)>0: self.valSht = Sheet
51
52 - def splitIntoParts(self):
53 '''from self.formula, split into individual parts''' 54 sp = string.split( self.formula, ',') 55 self.labelSht, self.labelLoc = string.split( sp[0], '!') 56 self.labelSht = string.split( self.labelSht, '(')[1] 57 58 self.xcolSht, self.xcolRng = string.split( sp[1], '!') 59 self.valSht, self.valRng = string.split( sp[2], '!') 60 self.seriesNum = string.split( sp[3], ')')[0]
61
62 - def excelColLetter(self, NColumn=1):
63 '''return the letter representation of excel columns''' 64 if NColumn>26: 65 r = NColumn % 26 - 1 66 q = NColumn / 26 - 1 67 return string.uppercase[q] + string.uppercase[r] 68 else: 69 return string.uppercase[NColumn-1]
70
71 - def makeColLocation(self, NColumn=1, NRow=1):
72 L = self.excelColLetter( NColumn ) 73 return '$'+L+'$'+str(NRow)
74
75 - def makeColRange(self, NColumn=1, fromRow=1, toRow=10):
76 L = self.excelColLetter( NColumn ) 77 return '$'+L+'$'+str(fromRow) +':'+ '$'+L+'$'+str(toRow)
78
79 - def makeRange(self, fromColumn=1, fromRow=1, toColumn=2, toRow=10):
80 L1 = self.excelColLetter( fromColumn ) 81 L2 = self.excelColLetter( toColumn ) 82 return '$'+L1+'$'+str(fromRow) +':'+ '$'+L2+'$'+str(toRow)
83
84 - def getFormula(self):
85 return '=SERIES(' + self.labelSht + '!' + self.labelLoc + \ 86 ',' + self.xcolSht + '!' + self.xcolRng +\ 87 ',' + self.valSht + '!' + self.valRng + \ 88 ',' + self.seriesNum + ')'
89
90 - def setFormula(self, strForm='=SERIES(Sheet1!$C$1,Sheet1!$A$2:$A$102,Sheet1!$C$2:$C$102,1)'):
91 self.formula = strForm 92 self.splitIntoParts()
93
94 - def __init__(self, strForm='=SERIES(Sheet1!$C$1,Sheet1!$A$2:$A$102,Sheet1!$C$2:$C$102,1)'):
95 self.formula = strForm 96 self.splitIntoParts()
97