Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
ss1.Sheet Class Reference

List of all members.

Public Member Functions

def __init__
def cellvalue
def multicellvalue
def getcell
def setcell
def clearcell
def clearcells
def clearrows
def clearcolumns
def selectcells
def movecells
def insertrows
def deleterows
def insertcolumns
def deletecolumns
def getsize
def reset
def recalc
def display
def xml
def save
def load

Public Attributes

 cells
 ns

Detailed Description

Definition at line 35 of file ss1.py.


Constructor & Destructor Documentation

def ss1.Sheet.__init__ (   self)

Definition at line 37 of file ss1.py.

00037 
00038     def __init__(self):
00039         self.cells = {} # {(x, y): cell, ...}
00040         self.ns = dict(
00041             cell = self.cellvalue,
00042             cells = self.multicellvalue,
00043             sum = sum,
00044         )

Here is the caller graph for this function:


Member Function Documentation

def ss1.Sheet.cellvalue (   self,
  x,
  y 
)

Definition at line 45 of file ss1.py.

00045 
00046     def cellvalue(self, x, y):
00047         cell = self.getcell(x, y)
00048         if hasattr(cell, 'recalc'):
00049             return cell.recalc(self.ns)
00050         else:
00051             return cell

Here is the call graph for this function:

Here is the caller graph for this function:

def ss1.Sheet.clearcell (   self,
  x,
  y 
)

Definition at line 71 of file ss1.py.

00071 
00072     def clearcell(self, x, y):
00073         try:
00074             del self.cells[x, y]
00075         except KeyError:
00076             pass

def ss1.Sheet.clearcells (   self,
  x1,
  y1,
  x2,
  y2 
)

Definition at line 77 of file ss1.py.

00077 
00078     def clearcells(self, x1, y1, x2, y2):
00079         for xy in self.selectcells(x1, y1, x2, y2):
00080             del self.cells[xy]

Here is the call graph for this function:

Here is the caller graph for this function:

def ss1.Sheet.clearcolumns (   self,
  x1,
  x2 
)

Definition at line 84 of file ss1.py.

00084 
00085     def clearcolumns(self, x1, x2):
00086         self.clearcells(x1, 0, x2, sys.maxint)

Here is the call graph for this function:

def ss1.Sheet.clearrows (   self,
  y1,
  y2 
)

Definition at line 81 of file ss1.py.

00081 
00082     def clearrows(self, y1, y2):
00083         self.clearcells(0, y1, sys.maxint, y2)

Here is the call graph for this function:

Here is the caller graph for this function:

def ss1.Sheet.deletecolumns (   self,
  x1,
  x2 
)

Definition at line 128 of file ss1.py.

00128 
00129     def deletecolumns(self, x1, x2):
00130         if x1 > x2:
00131             x1, x2 = x2, x1
00132         self.clearcells(x1, x2)
00133         self.movecells(x2+1, 0, sys.maxint, sys.maxint, x1-x2-1, 0)

Here is the call graph for this function:

def ss1.Sheet.deleterows (   self,
  y1,
  y2 
)

Definition at line 118 of file ss1.py.

00118 
00119     def deleterows(self, y1, y2):
00120         if y1 > y2:
00121             y1, y2 = y2, y1
00122         self.clearrows(y1, y2)
00123         self.movecells(0, y2+1, sys.maxint, sys.maxint, 0, y1-y2-1)

Here is the call graph for this function:

def ss1.Sheet.display (   self)

Definition at line 152 of file ss1.py.

00152 
00153     def display(self):
00154         maxx, maxy = self.getsize()
00155         width, height = maxx+1, maxy+1
00156         colwidth = [1] * width
00157         full = {}
00158         # Add column heading labels in row 0
00159         for x in range(1, width):
00160             full[x, 0] = text, alignment = colnum2name(x), RIGHT
00161             colwidth[x] = max(colwidth[x], len(text))
00162         # Add row labels in column 0
00163         for y in range(1, height):
00164             full[0, y] = text, alignment = str(y), RIGHT
00165             colwidth[0] = max(colwidth[0], len(text))
00166         # Add sheet cells in columns with x>0 and y>0
00167         for (x, y), cell in self.cells.items():
00168             if x <= 0 or y <= 0:
00169                 continue
00170             if hasattr(cell, 'recalc'):
00171                 cell.recalc(self.ns)
00172             if hasattr(cell, 'format'):
00173                 text, alignment = cell.format()
00174                 assert isinstance(text, str)
00175                 assert alignment in (LEFT, CENTER, RIGHT)
00176             else:
00177                 text = str(cell)
00178                 if isinstance(cell, str):
00179                     alignment = LEFT
00180                 else:
00181                     alignment = RIGHT
00182             full[x, y] = (text, alignment)
00183             colwidth[x] = max(colwidth[x], len(text))
00184         # Calculate the horizontal separator line (dashes and dots)
00185         sep = ""
00186         for x in range(width):
00187             if sep:
00188                 sep += "+"
00189             sep += "-"*colwidth[x]
00190         # Now print The full grid
00191         for y in range(height):
00192             line = ""
00193             for x in range(width):
00194                 text, alignment = full.get((x, y)) or ("", LEFT)
00195                 text = align2action[alignment](text, colwidth[x])
00196                 if line:
00197                     line += '|'
00198                 line += text
00199             print(line)
00200             if y == 0:
00201                 print(sep)

Here is the call graph for this function:

def ss1.Sheet.getcell (   self,
  x,
  y 
)

Definition at line 63 of file ss1.py.

00063 
00064     def getcell(self, x, y):
00065         return self.cells.get((x, y))

Here is the caller graph for this function:

def ss1.Sheet.getsize (   self)

Definition at line 134 of file ss1.py.

00134 
00135     def getsize(self):
00136         maxx = maxy = 0
00137         for x, y in self.cells:
00138             maxx = max(maxx, x)
00139             maxy = max(maxy, y)
00140         return maxx, maxy

Here is the caller graph for this function:

def ss1.Sheet.insertcolumns (   self,
  x,
  n 
)

Definition at line 124 of file ss1.py.

00124 
00125     def insertcolumns(self, x, n):
00126         assert n > 0
00127         self.movecells(x, 0, sys.maxint, sys.maxint, n, 0)

Here is the call graph for this function:

def ss1.Sheet.insertrows (   self,
  y,
  n 
)

Definition at line 114 of file ss1.py.

00114 
00115     def insertrows(self, y, n):
00116         assert n > 0
00117         self.movecells(0, y, sys.maxint, sys.maxint, 0, n)

Here is the call graph for this function:

def ss1.Sheet.load (   self,
  filename 
)

Definition at line 222 of file ss1.py.

00222 
00223     def load(self, filename):
00224         f = open(filename, 'rb')
00225         SheetParser(self).parsefile(f)
00226         f.close()

Here is the call graph for this function:

def ss1.Sheet.movecells (   self,
  x1,
  y1,
  x2,
  y2,
  dx,
  dy 
)

Definition at line 95 of file ss1.py.

00095 
00096     def movecells(self, x1, y1, x2, y2, dx, dy):
00097         if dx == 0 and dy == 0:
00098             return
00099         if x1 > x2:
00100             x1, x2 = x2, x1
00101         if y1 > y2:
00102             y1, y2 = y2, y1
00103         assert x1+dx > 0 and y1+dy > 0
00104         new = {}
00105         for x, y in self.cells:
00106             cell = self.cells[x, y]
00107             if hasattr(cell, 'renumber'):
00108                 cell = cell.renumber(x1, y1, x2, y2, dx, dy)
00109             if x1 <= x <= x2 and y1 <= y <= y2:
00110                 x += dx
00111                 y += dy
00112             new[x, y] = cell
00113         self.cells = new

Here is the caller graph for this function:

def ss1.Sheet.multicellvalue (   self,
  x1,
  y1,
  x2,
  y2 
)

Definition at line 52 of file ss1.py.

00052 
00053     def multicellvalue(self, x1, y1, x2, y2):
00054         if x1 > x2:
00055             x1, x2 = x2, x1
00056         if y1 > y2:
00057             y1, y2 = y2, y1
00058         seq = []
00059         for y in range(y1, y2+1):
00060             for x in range(x1, x2+1):
00061                 seq.append(self.cellvalue(x, y))
00062         return seq

Here is the call graph for this function:

def ss1.Sheet.recalc (   self)

Definition at line 146 of file ss1.py.

00146 
00147     def recalc(self):
00148         self.reset()
00149         for cell in self.cells.values():
00150             if hasattr(cell, 'recalc'):
00151                 cell.recalc(self.ns)

def ss1.Sheet.reset (   self)

Definition at line 141 of file ss1.py.

00141 
00142     def reset(self):
00143         for cell in self.cells.values():
00144             if hasattr(cell, 'reset'):
00145                 cell.reset()

Here is the caller graph for this function:

def ss1.Sheet.save (   self,
  filename 
)

Definition at line 214 of file ss1.py.

00214 
00215     def save(self, filename):
00216         text = self.xml()
00217         f = open(filename, "w")
00218         f.write(text)
00219         if text and not text.endswith('\n'):
00220             f.write('\n')
00221         f.close()

Here is the call graph for this function:

def ss1.Sheet.selectcells (   self,
  x1,
  y1,
  x2,
  y2 
)

Definition at line 87 of file ss1.py.

00087 
00088     def selectcells(self, x1, y1, x2, y2):
00089         if x1 > x2:
00090             x1, x2 = x2, x1
00091         if y1 > y2:
00092             y1, y2 = y2, y1
00093         return [(x, y) for x, y in self.cells
00094                 if x1 <= x <= x2 and y1 <= y <= y2]

Here is the caller graph for this function:

def ss1.Sheet.setcell (   self,
  x,
  y,
  cell 
)

Definition at line 66 of file ss1.py.

00066 
00067     def setcell(self, x, y, cell):
00068         assert x > 0 and y > 0
00069         assert isinstance(cell, BaseCell)
00070         self.cells[x, y] = cell

def ss1.Sheet.xml (   self)

Definition at line 202 of file ss1.py.

00202 
00203     def xml(self):
00204         out = ['<spreadsheet>']
00205         for (x, y), cell in self.cells.items():
00206             if hasattr(cell, 'xml'):
00207                 cellxml = cell.xml()
00208             else:
00209                 cellxml = '<value>%s</value>' % html.escape(cell)
00210             out.append('<cell row="%s" col="%s">\n  %s\n</cell>' %
00211                        (y, x, cellxml))
00212         out.append('</spreadsheet>')
00213         return '\n'.join(out)

Here is the caller graph for this function:


Member Data Documentation

Definition at line 38 of file ss1.py.

Definition at line 39 of file ss1.py.


The documentation for this class was generated from the following file: