#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  faculSpread.py
#  
#  Copyright 2015 ulrich1a
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#  
#  



p=App.ParamGet("User parameter:BaseApp/Preferences/General")
thePath = p.GetString('FileOpenSavePath')


theDoc = App.newDocument("SheetTest2")
App.setActiveDocument("SheetTest2")

mySheet = theDoc.addObject('Spreadsheet::Sheet','Spreadsheet')


col = 'A'
mySheet.setColumnWidth(col, 125)
theDoc.recompute()

startRow = 3

for i in range(20):
  print "i: ", i
  if i == 0:
    print "setting start"
    mySheet.set(col+str(startRow+i), '1')
    #App.activeDocument().recompute()
  else:
    mySheet.set(col + str(startRow+i), '='+col+str(startRow+i-1)+'*'+str(i))
    #App.activeDocument().recompute()

#mySheet.show()    
#App.activeDocument().recompute()

mySheet.set('A1', 'This is the very long Titel, which needs more space!')
mySheet.set('A2', '=A1')

# mySheet.setDisplayUnit('A10:A11', 'mm')

theDoc.recompute()
mySheet.setAlias('A1', 'Title')
mySheet.set('D1', '=Title')

theDoc.recompute()

theDoc.saveAs(thePath + '/Sheet_6.fcstd')
mySheet.set('B4','=A4')
mySheet.set('E1', '=D1')
theDoc.recompute()
mySheet.setAlias('A2', 'huhu')
theDoc.recompute()

if mySheet.State == ['Invalid']:
  print "Invalid Spreadsheet"
else:
  print "No error found"
