[Tutor] Scripting Calligra sheets with Python

Dave Angel davea at davea.name
Tue Mar 19 01:54:59 CET 2013


On 03/18/2013 12:18 PM, Jim Byrnes wrote:
> I am trying to script Calligra Sheets (formerly KSpread) with python.  I
> have gotten some of the included example scripts to run so I know python
> scripting is running.
>
> I found the following snippet on their website:
>
> import KSpread
> sheet = KSpread.view().sheet()
> # swap text of B5 and C6
> t1 = sheet.text("B5")
> t2 = sheet.text(6,3)
> sheet.setText("B5", t2)
> sheet.setText(6, 3, t1)
> # swap value of D7 and E8
> v1 = sheet.value("D7")
> v2 = sheet.value(8,5)
> sheet.setValue("D7", v2)
> sheet.setValue(8, 5, v1)
>
> Error: 'str' object has no attribute 'text'
>   File
> "file:///usr/share/kde4/apps/sheets/scripts/extensions/myswap.py", line
> 4, in <module>
>
>
> This error message appeared in a dialog box.
>
> I've taught myself some Python but I don't understand what is happening
> here.  Shouldn't t1 be a sheet object?  What would cause it to be a str
> instead?
>

Since somebody has censored the rest of the error traceback, we can't 
even tell what line is giving the error.  Assuming you know it's
    t1 = sheet.text("85")

then it has nothing to do with the type of t1, but with the type of 
sheet.  If that's the case, then print out type(sheet) and see what it 
actually is.  Then consult the documentation for the 
KSpread.view().sheet() function and see what it's documented to return.


> Thanks,  Jim
>
>


-- 
DaveA


More information about the Tutor mailing list