def hotCount(st): '''Counts the number of words in a string. ARGUMENTS: str st: count the number of words in this string RETURNS: int: the number of words in st''' startpos = long() nextwd = Boundary() lc = Locale() lc.Language = 'en' numwords = 1 mystartpos = 1 brk = smgr.createInstanceWithContext('com.sun.star.i18n.BreakIterator', ctx) nextwd = brk.nextWord(st, startpos, lc, WORD_COUNT) while nextwd.startPos != nextwd.endPos: numwords += 1 nw = nextwd.startPos nextwd = brk.nextWord(st, nw, lc, WORD_COUNT) return numwords
def changeLanguage(self, lang): if lang in self.custom_i18n.keys(): myi18n = self.custom_i18n[lang] else: raise RuntimeError('Unsupported language: %s' % lang) for key in list(self.i18n.keys()): del self.i18n[key] for key in myi18n: self.i18n[key] = myi18n[key] if lang in self.languageStrings: language, country = self.languageStrings[lang] loc = Locale() loc.Language = language loc.Country = country self._document.CharLocale = loc
def changeLanguage(self, lang): if lang in self.custom_i18n.keys(): myi18n = self.custom_i18n[lang] else: raise RuntimeError('Unsupported language: %s' % lang) for key in list(self.i18n.keys()): del self.i18n[key] for key in myi18n: self.i18n[key] = myi18n[key] self._currentLanguage = lang if lang in self.languageStrings: language, country = self.languageStrings[lang] loc = Locale() loc.Language = language loc.Country = country self._document.CharLocale = loc
def fill_cell_with_data(doc, data, cell): """Fills a single cell with given data. Before the data is stored in the cell of an worksheet, the type of the data is checked. All necessary conversion and type casts are done before the value of the cell is set.""" NumberFormat = doc.getNumberFormats() LocalSettings = Locale() LocalSettings.Language = 'de' if not data: cell.String = '' elif type(data) == str: cell.String = data elif type(data) == Arrow: # write datetime into cell cell.String = data.format('DD.MM.YYYY HH:mm:ss') # set number format for cell FormatString = 'TT.MM.JJJJ HH:MM:SS' NumberFormatID = NumberFormat.queryKey(FormatString, LocalSettings, True) # check whether a value was found for the requested format (-1 == no value) if NumberFormatID == -1: NumberFormatID = NumberFormat.addNew(FormatString, LocalSettings) cell.NumberFormat = NumberFormatID elif type(data) == timedelta: # write datetime into cell cell.String = str(data) # set number format for cell FormatString = 'HH:MM:SS' NumberFormatID = NumberFormat.queryKey(FormatString, LocalSettings, True) # check whether a value was found for the requested format (-1 == no value) if NumberFormatID == -1: NumberFormatID = NumberFormat.addNew(FormatString, LocalSettings) cell.NumberFormat = NumberFormatID else: print('Unsupported type: {}'.format(type(data))) # return data without conversion to trigger an exception return data