     @loader.loadDefinitions text
 
   loadRow: (rowIndex, name, formula) ->
-    rowEl = @el.find("tbody tr").eq(rowIndex)
-    cells = rowEl.find('td, th')
-    nameEl = cells.eq(0)
-    nameEl.text name
-    formulaEl = cells.eq(1)
-    formulaEl.text formula
+    row = new Row(@el.find("tbody tr").eq(rowIndex))
+    row.setName name
+    row.setFormula formula
 
   _loadTable: (defs) -> @loadRow(i, def.name, def.expr.text) for def, i in defs
 

    sheetRows = @el.find('tr')
    self = this
    sheetRows.each ->
      rowEl = $(this)
      cells = rowEl.find('td, th')
      nameEl = cells.eq(0)
      name  = nameEl.text().trim()
      formulaEl = cells.eq(1)
      formula  = formulaEl.text().trim()
      self.updateFormula name, formula

  _updateTable: (name, value) ->
    valueCellForName = @el.find('td:first-child').filter( -> $(this).text() == name).closest('tr').find('th:nth-child(3)')
    valueCellForName.text(value)

#module.exports = TableWorksheet
window.TableWorksheet = TableWorksheet
    self = this
    @el.on 'change', 'td', (evt, newValue) ->
      cell = $(this)
      row = new Row(cell.parent())
      self.updateFormula row.name(), row.formula()

  updateFormula: (name, formula, oldName) -> if name and formula then @loader.setFunctionAsText name, formula, oldName


  asText: -> @loader.asText()
