Changeset 1980
- Timestamp:
- 02/15/07 08:53:56 (2 years ago)
- Files:
-
- excelreportplugin/0.10/excel_report_plugin.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
excelreportplugin/0.10/excel_report_plugin.py
r1978 r1980 6 6 from trac.ticket.query import QueryModule 7 7 from pyExcelerator import * 8 from datetime import datetime 9 import copy 10 import types 8 11 9 12 class XlsDoc(CompoundDoc.XlsDoc): … … 44 47 def get_report_linkclass(self): 45 48 return None #'xls' 46 47 49 48 50 def render(self, req, cols, rows): 49 51 … … 58 60 req.hdf['project.name']) 59 61 60 sheetname = sheetname.replace('/','-') 61 try: 62 ws = wb.add_sheet(sheetname.decode('utf-8')) 63 except: 64 ws = wb.add_sheet(sheetname) 62 63 ws = wb.add_sheet(self.convertSheetName(sheetname)) 64 65 65 ws.panes_frozen = True 66 66 ro = 1 67 67 ws.horz_split_pos = ro 68 69 import copy 70 68 69 71 70 font0 = Font() 72 71 font0.charset = font0.CHARSET_SYS_DEFAULT … … 82 81 align2.wrap = align2.WRAP_AT_RIGHT 83 82 84 s tyle0 = XFStyle()85 s tyle0.font = font086 s tyle0.alignment = align187 s tyle0.num_format_str = 'general'88 s tyle_colheader = copy.copy(style0)89 s tyle_colheader.num_format_str = '@'90 s tyle_colheader.font = font191 s tyle_num = copy.copy(style0)92 s tyle_str = copy.copy(style0)93 s tyle_str.num_format_str = '@'94 s tyle_wrap_str = copy.copy(style0)95 s tyle_wrap_str.alignment = align296 s tyle_wrap_str.font = font297 s tyle_date = copy.copy(style0)98 s tyle_date.num_format_str = 'yyyy/mm/dd'83 self.style0 = XFStyle() 84 self.style0.font = font0 85 self.style0.alignment = align1 86 self.style0.num_format_str = 'general' 87 self.style_colheader = copy.copy(self.style0) 88 self.style_colheader.num_format_str = '@' 89 self.style_colheader.font = font1 90 self.style_num = copy.copy(self.style0) 91 self.style_str = copy.copy(self.style0) 92 self.style_str.num_format_str = '@' 93 self.style_wrap_str = copy.copy(self.style0) 94 self.style_wrap_str.alignment = align2 95 self.style_wrap_str.font = font2 96 self.style_date = copy.copy(self.style0) 97 self.style_date.num_format_str = 'yyyy/mm/dd' 99 98 100 99 for col, cx in map(lambda x, y: [x, y], cols, range(len(cols))): 101 100 102 101 name = str(col).replace('_','') 103 ws.write(ro-1, cx, name.decode('utf-8'), s tyle_colheader)102 ws.write(ro-1, cx, name.decode('utf-8'), self.style_colheader) 104 103 105 def conv(x): 106 try: 107 a = str(x).replace('\r','').rstrip('\r\n').decode('utf-8') 108 except: 109 return x.replace('\r','').rstrip('\r\n') 110 return a 104 conv = self.convertComments 111 105 112 style = style_str 113 if name in ['time', 'date','changetime', 'created', 'modified']: 106 style = self.style_str 107 108 if name in ['time', 'date','changetime', 'created', 'modified', 109 'hora', 'fecha','cambio' ,'creado' ,'modificado']: 114 110 ws.col(cx).width = 0xb00 115 from datetime import datetime 116 conv = lambda x: datetime.fromtimestamp(float(x)) 117 style = style_date 118 elif name in ['summary', 'description']: 119 if name == 'description': 120 ws.col(cx).width = 0x7000 121 else: 122 ws.col(cx).width = 0x1a00 123 style = style_wrap_str 111 conv = self.convertTimeStamp 112 style = self.style_date 113 114 elif name in ['summary','resumen']: 115 ws.col(cx).width = 0x1a00 116 style = self.style_wrap_str 117 118 elif name in ['description','descripcion']: 119 ws.col(cx).width = 0x7000 120 style = self.style_wrap_str 121 124 122 elif name in ['color', 'ticket', 'id']: 125 123 if name in ['color']: 126 124 ws.col(cx).hidden = 1 127 conv = lambda x: int(x)128 style = s tyle_num125 conv = self.convertInteger 126 style = self.style_num 129 127 elif name in ['style']: 130 128 ws.col(cx).hidden = 1 131 129 elif name == "component": 132 130 ws.col(cx).width = 0x1a00 131 132 133 133 for value, rx in map(lambda x, y: [conv(x[cx]), ro + y], \ 134 134 rows, range(len(rows))): 135 ws.write(rx, cx, value, style) 135 if type(value) is int: 136 ws.write(rx, cx, value, self.style_num) 137 elif type(value) is datetime: 138 ws.write(rx, cx, value, self.style_date) 139 elif type(value) is types.NoneType: 140 ws.write(rx, cx, '-',self.style_str) 141 else: 142 ws.write(rx, cx, value, style) 143 144 145 146 136 147 req.write(wb.get()) 137 148 149 def convertComments(self, x): 150 try: 151 if type(x) is types.NoneType: 152 return x 153 else: 154 return str(x).replace('\r','').rstrip('\r\n').decode('utf-8') 155 except: 156 return x.replace('\r','').rstrip('\r\n') 138 157 158 159 def convertTimeStamp(self,timestamp): 160 161 try: 162 return datetime.fromtimestamp(float(timestamp)) 163 except: 164 return timestamp 165 166 def convertInteger(self,value): 167 try: 168 return int(value) 169 except: 170 return value 171 172 def convertSheetName(self, sheetname): 173 174 sheetname = sheetname.replace('/','-') 175 176 try: 177 return sheetname.decode('utf-8') 178 except: 179 return sheetname 180 181 139 182 140 183
