сложить в c:\Documents and Settings\имя юзера\Application Data\OpenOffice.org\циферка\user\Scripts\python\sklon.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import urllib2, re
doc = XSCRIPTCONTEXT.getDocument()
sheet = doc.getCurrentController().ActiveSheet
def get_list( query_text ):
url = "http://export.yandex.ru/inflect.xml?name=%s" % query_text
try:
readed = urllib2.urlopen(url).read()
egg = re.findall("<inflection case=\"(\d)\">(.+?)</inflection>", readed)
except urllib2.HTTPError:
return [ (0, "xуй") ] * 5
return egg[1:]
def set_value(x, y, val):
cell = sheet.getCellByPosition(x,y)
cell.setFormula(val)
def Sklonyator( test ):
"""склоняет значение первой ячейки в строке"""
cur_row = doc.CurrentSelection.getCellAddress().Row
cur_col = doc.CurrentSelection.getCellAddress().Column
search_text = sheet.getCellByPosition(0,cur_row).getFormula()
rc = get_list( unicode( search_text ).encode("cp1251") )
for i in range( len(rc) ):
set_value( i+1, cur_row, rc[i][1].decode("utf-8") )