kspread
KSpread Scripting Plugin
The KSpread scripting plugin offers flexible access to the Kross scripting framework.
Languages like Python or Ruby could be used to script KSpread, extend the functionality with script-packages, automate tasks or control the runtime-environment.
- The ScriptingPart class implements a KPart component to integrate scripting into KSpread.
- The ScriptingModule class enables access to the KSpread functionality from within the scripting backends.
- The ScriptingFunction class provides access to the KSpread::Function functionality to deal with formula functions that are written in a scripting language like Python or Ruby.
- The ScriptingCellListener class implements a listener to changes within cells of a sheet.
- The ScriptingReader class provides abstract high-level functionality to read content from KSpread sheets.
- The ScriptingWriter class provides abstract high-level functionality to write content to KSpread sheets and to manipulate the content of cells.
- The ScriptingSheetsListView provides provides a listview-widget that displays all sheets and lets the user choose 0..n of them plus specify cell-ranges for all of them.
- See also:
- http://www.koffice.org/kspread
- http://techbase.kde.org/Development/Tutorials/KSpread_Scripting
- http://kross.dipe.org
Examples
Python example to write content of a sheet to stdout;
#!/usr/bin/env kross # The OpenDocument Spreadsheet file that we like to read. filename = "/home/kde4/invoicetemplate.ods" # Import Kross and fetch the KSpread module. import Kross kspread = Kross.module("kspread") # Try to open the file. if not kspread.openUrl(filename): raise "Failed to open the file \"%s\"." % filename # Get the sheet we like to print to stdout. sheet = kspread.sheetByName( kspread.sheetNames()[0] ) # Iterate now through all cells on the sheet. for row in range(sheet.maxRow()): # Put the content of the row into the record-list. record = [] for col in range(sheet.maxColumn(), 0, -1): value = sheet.text(col, row) if value or len(record) > 0: record.insert(0,value) # If the record has at least one cell print it. if len(record) > 0: print record
Python example to read template, set content and write new file;
#!/usr/bin/env kross # The OpenDocument Spreadsheet file that we like to read from. templatefile = "/home/kde4/invoicetemplate.ods" # The OpenDocument Spreadsheet file that we like to write to. savefile = "/home/kde4/invoice.ods" # Import Kross and fetch the KSpread module. import Kross kspread = Kross.module("kspread") # Try to open the file. if not kspread.openUrl(templatefile): raise "Failed to open the file \"%s\"." % templatefile # Get the sheet we like to manipulate. sheet = kspread.sheetByName( kspread.sheetNames()[0] ) # Set the content of some cells. sheet.setText(0,7,"Joe User") sheet.setText(0,8,"Userstreet. 1") sheet.setText(0,9,"Testcasecity") # Finally write the new OpenDocument Spreadsheet file. if not kspread.saveUrl(savefile): raise "Failed to save the file \"%s\"." % savefile
Legal
- Copyright (c) 2005 Cyrille Berger <cberger@cberger.net>
- Copyright (c) 2006 ISaac Clerencia <isaac@warp.es>
- Copyright (c) 2006-2007 Sebastian Sauer <mail@dipe.org>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library 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 Library General Public License for more details.
You should have received a copy of the GNU Library 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.
