Changeset 162 for trunk/aeres/scripts
- Timestamp:
- 04/05/12 13:51:05 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/aeres/scripts/aeresrh.py
r161 r162 14 14 15 15 .. option:: --ifile <file> 16 16 17 17 file to read 18 18 … … 36 36 label="${PROJECT}/++/aeresrh.py"]; 37 37 } 38 38 39 39 SEE ALSO 40 40 ======== 41 41 42 :ref: 42 https://secure.simplistix.co.uk/svn/xlrd/trunk/xlrd/doc/xlrd.html 43 43 44 44 EXAMPLES … … 50 50 ==== 51 51 52 make it work 52 test with real file (encoding, francais, etc) 53 54 gestion des temps (anne de naissance , arrivée , depard) 55 56 remove hard coded number of columns for surname, firstname, ... 53 57 54 58 coding rules (pylint) … … 64 68 65 69 * creation draft 66 70 thanks to http://www.portailsig.org/content/python-lire-et-ecrire-des-fichiers-microsoft-excel-application-quantum-gis 71 and http://scienceoss.com/read-excel-files-from-python/ 67 72 """ 68 73 69 74 import sys 70 75 import os … … 108 113 return ++ 109 114 """ 110 111 if is_verbose == True: 112 print('iii : read %s' % filein_namelist_wrf)113 114 # ouverture du fichier Excel 115 116 if is_verbose == True: 117 print('iii : read %s' % ifile) 118 119 # ouverture du fichier Excel 115 120 wb = xlrd.open_workbook(ifile) 116 121 117 122 # feuilles dans le classeur 118 print wb.sheet_names() 123 if is_verbose == True: 124 print('sheets name %s' % ( wb.sheet_names())) 119 125 120 126 # lecture des données dans la première feuille 121 sh = wb.sheet_by_name(u'Feuil1') 122 for rownum in range(sh.nrows): 123 print sh.row_values(rownum) 124 125 # lecture par colonne 126 colonne1 = sh.col_values(0) 127 print colonne1 128 129 colonne2=sh.col_values(1) 130 print colonne2 131 [u'x', 235.0, 245.0, 255.0, 265.0, 275.0, 285.0, 295.0] 132 133 # extraction d'un élément particulier 134 print colonne1[1],colonne2[1] 135 136 return sh.col_values(1) 127 sh = wb.sheet_by_index(0) 128 129 # 130 if is_verbose == True: 131 for rownum in range(sh.nrows): 132 print('values of in row %d : %s' % (rownum, sh.row_values(rownum))) 133 134 if is_verbose == True: 135 for colnum in range(sh.ncols): 136 print('values of in col %d : %s' % (colnum, sh.col_values(colnum))) 137 138 colsurname = 2 139 colfirstname = 4 140 colarrival = 26 141 coldeparture = 28 142 colpubli = 32 143 144 surname = sh.col_values(colsurname) 145 # remove the first element because it is the title 146 surname[0] = '' 147 surname = filter(lambda surname: surname != '', surname) 148 149 if is_verbose == True: 150 print(' nb surname %d' % len(surname)) 151 print(' surname %s' % surname) 152 153 firstname = [] 154 firstname = sh.col_values(colfirstname) 155 # remove the first element because it is the title 156 firstname[0] = '' 157 firstname = filter(lambda firstname: firstname != '', firstname) 158 159 if is_verbose == True: 160 print(' nb firstname %d' % len(firstname)) 161 print(' firstname %s' % firstname) 162 163 arrival = [] 164 arrival = sh.col_values(colarrival) 165 # remove the first element because it is the title 166 arrival[0] = '' 167 arrival = filter(lambda arrival: arrival != '', arrival) 168 169 if is_verbose == True: 170 print(' nb arrival %d' % len(arrival)) 171 print(' arrival %s' % arrival) 172 173 departure = [] 174 departure = sh.col_values(coldeparture) 175 # remove the first element because it is the title 176 departure[0] = '' 177 departure = filter(lambda departure: departure != '', departure) 178 179 if is_verbose == True: 180 print(' nb departure %d' % len(departure)) 181 print(' departure %s' % departure) 182 183 publi = [] 184 publi = sh.col_values(colpubli) 185 # remove the first element because it is the title 186 publi[0] = '' 187 publi = filter(lambda publi: publi != '', publi) 188 189 if is_verbose == True: 190 print(' nb publi %d' % len(publi)) 191 print(' publi %s' % publi) 192 193 return surname, firstname, arrival, departure, publi 137 194 138 195 def aeresrh(): … … 150 207 print ('ifile : %s' % (ifile)) 151 208 152 surname, firstname = readrh(ifile, is_verbose)209 surname, firstname, arrival, departure,publi = readrh(ifile, is_verbose) 153 210 print (' surname %s' % (surname)) 154 211
Note: See TracChangeset
for help on using the changeset viewer.