| 150 | cell.recalc(self.ns) |
| 151 | |
| 152 | def display(self): |
| 153 | maxx, maxy = self.getsize() |
| 154 | width, height = maxx+1, maxy+1 |
| 155 | colwidth = [1] * width |
| 156 | full = {} |
| 157 | # Add column heading labels in row 0 |
| 158 | for x in range(1, width): |
| 159 | full[x, 0] = text, alignment = colnum2name(x), RIGHT |
| 160 | colwidth[x] = max(colwidth[x], len(text)) |
| 161 | # Add row labels in column 0 |
| 162 | for y in range(1, height): |
| 163 | full[0, y] = text, alignment = str(y), RIGHT |
| 164 | colwidth[0] = max(colwidth[0], len(text)) |
| 165 | # Add sheet cells in columns with x>0 and y>0 |
| 166 | for (x, y), cell in self.cells.items(): |
| 167 | if x <= 0 or y <= 0: |
| 168 | continue |
| 169 | if hasattr(cell, 'recalc'): |
| 170 | cell.recalc(self.ns) |
| 171 | if hasattr(cell, 'format'): |
| 172 | text, alignment = cell.format() |
| 173 | assert isinstance(text, str) |
| 174 | assert alignment in (LEFT, CENTER, RIGHT) |
| 175 | else: |
| 176 | text = str(cell) |
| 177 | if isinstance(cell, str): |
| 178 | alignment = LEFT |
| 179 | else: |
| 180 | alignment = RIGHT |
| 181 | full[x, y] = (text, alignment) |
| 182 | colwidth[x] = max(colwidth[x], len(text)) |
| 183 | # Calculate the horizontal separator line (dashes and dots) |
| 184 | sep = "" |
| 185 | for x in range(width): |
| 186 | if sep: |
| 187 | sep += "+" |
| 188 | sep += "-"*colwidth[x] |
| 189 | # Now print The full grid |
| 190 | for y in range(height): |
| 191 | line = "" |
| 192 | for x in range(width): |
| 193 | text, alignment = full.get((x, y)) or ("", LEFT) |
| 194 | text = align2action[alignment](text, colwidth[x]) |
| 195 | if line: |
| 196 | line += '|' |
| 197 | line += text |
| 198 | print(line) |
| 199 | if y == 0: |
| 200 | print(sep) |
| 201 | |
| 202 | def xml(self): |
| 203 | out = ['<spreadsheet>'] |