[pod] If you define a variable named 'tableName' inside a table, it will be used to name the table. For information, with Calc, every spreadsheet is represented as a table; the table name is the name that appears in the corresponding tab, in the bottom of the screen.
This commit is contained in:
parent
1730ce3c19
commit
ffb8bed189
|
@ -139,16 +139,23 @@ class Buffer:
|
|||
|
||||
def getLength(self): pass # To be overridden
|
||||
|
||||
def patchColumnsRepeated(self, attrs):
|
||||
'''Every table column must have an attribute
|
||||
"number-columns-repeated".'''
|
||||
key = self.env.tags['number-columns-repeated']
|
||||
attrs = attrs._attrs
|
||||
columnNumber = self.env.getTable().nbOfColumns -1
|
||||
if key in attrs:
|
||||
attrs[key] = ':columnsRepeated[%d]|%s' % (columnNumber, attrs[key])
|
||||
else:
|
||||
attrs[key] = ':columnsRepeated[%d]|1' % (columnNumber)
|
||||
def patchTableElement(self, elem, attrs):
|
||||
'''Convert the name of a table to an expression allowing the user to
|
||||
define himself this name via variable "tableName".
|
||||
|
||||
Convert attribute "number-columns-repeated" of every table column
|
||||
(or add it if it does not exist) to let the user define how he will
|
||||
repeat table columns via variable "columnsRepeated".'''
|
||||
if elem == self.env.tags['table']:
|
||||
attrs = attrs._attrs
|
||||
name = self.env.tags['table-name']
|
||||
attrs[name] = ':tableName|"%s"' % attrs[name]
|
||||
elif elem == self.env.tags['table-column']:
|
||||
attrs = attrs._attrs
|
||||
key = self.env.tags['number-columns-repeated']
|
||||
columnNumber = self.env.getTable().nbOfColumns -1
|
||||
nb = (key in attrs) and attrs[key] or '1'
|
||||
attrs[key] = ':columnsRepeated[%d]|%s' % (columnNumber, nb)
|
||||
|
||||
def dumpStartElement(self, elem, attrs={}, ignoreAttrs=(), hook=False,
|
||||
noEndTag=False, renamedAttrs=None):
|
||||
|
@ -166,8 +173,8 @@ class Buffer:
|
|||
p_hook must be a tuple (s_attrName, s_expr).
|
||||
'''
|
||||
self.write('<%s' % elem)
|
||||
if self.pod and (elem == self.env.tags['table-column']):
|
||||
self.patchColumnsRepeated(attrs)
|
||||
# Some table elements must be patched (pod only)
|
||||
if self.pod: self.patchTableElement(elem, attrs)
|
||||
for name, value in attrs.items():
|
||||
if ignoreAttrs and (name in ignoreAttrs): continue
|
||||
if renamedAttrs and (name in renamedAttrs): name=renamedAttrs[name]
|
||||
|
|
|
@ -192,6 +192,7 @@ class PodEnvironment(OdfEnvironment):
|
|||
xmlElemDef.__init__(elemFullName)
|
||||
# Create a table of names of used tags and attributes (precomputed,
|
||||
# including namespace, for performance).
|
||||
table = ns[self.NS_TABLE]
|
||||
self.tags = {
|
||||
'tracked-changes': '%s:tracked-changes' % ns[self.NS_TEXT],
|
||||
'change': '%s:change' % ns[self.NS_TEXT],
|
||||
|
@ -199,17 +200,17 @@ class PodEnvironment(OdfEnvironment):
|
|||
'change-start': '%s:change-start' % ns[self.NS_TEXT],
|
||||
'change-end': '%s:change-end' % ns[self.NS_TEXT],
|
||||
'conditional-text': '%s:conditional-text' % ns[self.NS_TEXT],
|
||||
'table-cell': '%s:table-cell' % ns[self.NS_TABLE],
|
||||
'formula': '%s:formula' % ns[self.NS_TABLE],
|
||||
'table': '%s:table' % table,
|
||||
'table-name': '%s:name' % table,
|
||||
'table-cell': '%s:table-cell' % table,
|
||||
'table-column': '%s:table-column' % table,
|
||||
'formula': '%s:formula' % table,
|
||||
'value-type': '%s:value-type' % ns[self.NS_OFFICE],
|
||||
'value': '%s:value' % ns[self.NS_OFFICE],
|
||||
'string-value': '%s:string-value' % ns[self.NS_OFFICE],
|
||||
'span': '%s:span' % ns[self.NS_TEXT],
|
||||
'number-columns-spanned': '%s:number-columns-spanned' % \
|
||||
ns[self.NS_TABLE],
|
||||
'number-columns-repeated': '%s:number-columns-repeated' % \
|
||||
ns[self.NS_TABLE],
|
||||
'table-column': '%s:table-column' % ns[self.NS_TABLE],
|
||||
'number-columns-spanned': '%s:number-columns-spanned' % table,
|
||||
'number-columns-repeated': '%s:number-columns-repeated' % table,
|
||||
}
|
||||
self.ignorableElements = (self.tags['tracked-changes'],
|
||||
self.tags['change'])
|
||||
|
|
Loading…
Reference in a new issue