This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Shold this Python snippet run?

Tags: None
(comma "," separated)
cleanman2
Registered Member
Posts
12
Karma
0

Shold this Python snippet run?

Tue Mar 19, 2013 1:12 am
I tried to run this snippet from: http://techbase.kde.org/Development/Tut ... _Scripting

EDIT: I was able to get it mostly working. I now get no error, it will swap B5 & C6, it will NOT swap D7 & E8. My comments below.

import KSpread
#sheet = KSpread.view().sheet() #This does not work, see the next 2 lines for what does work
sheetname = KSpread.currentSheet().sheetName()
sheet = KSpread.sheetByName(sheetname)
# swap text of B5 and C6
t1 = sheet.text("B5")
#t2 = sheet.text(6,3) # The docs say (row,col) but it must be (col, row) to work correctly
sheet.text(3,6)
sheet.setText("B5", t2)
#sheet.setText(6, 3, t1) # same as above
sheet.setText(3,6,t1)
# swap value of D7 and E8
v1 = sheet.value("D7") # this command works as expected
v2 = sheet.value(8,5)
sheet.setValue("D7", v2) # this command does not work, ie produces no results
sheet.setValue(8, 5, v1)

And I got this error.
'str' object has no attribute 'text'
"file:///usr/share/kde4/apps/sheets/scripts/extensions/myswap.py", line 5, in <module>

I have tried a few of the example scripts that are installed with the installation of sheets and they run OK. I tried to run a simple script of my own that put some text in a cell but nothing happened. Then I tried to run the script above and got that error.

I must be missing something. What needs to be done to run my own scripts in sheets?

Thanks, Jim


Bookmarks



Who is online

Registered users: bancha, Bing [Bot], Evergrowing, Google [Bot], mesutakcan, Sogou [Bot]