def addTableColored(doc,
valores_buscados,
data,
columnssize_percentages=None,
margins_top=0.3,
margins_bottom=0.3,
size=10,
width_percentage=100,
alignment="center",
paragraph_style="Standard",
style=None,
name=None
):
"""
Function Override de la function de unogenerator addTable
Se len añade un parametro valores_buscados. Es una lista del tamaño de la tablela
Se compara cada item con el item de cada columna en cada row
si una celda coincide con el valor buscado se pone en verde, sino en rojo
"""
from com.sun.star.style.ParagraphAdjust import RIGHT, LEFT
#Tabla definition
table=doc.document.createInstance("com.sun.star.text.TextTable")
num_rows=len(data)
if num_rows==0:
return
num_columns=len(data[0])
table.initialize(num_rows, num_columns)
if name is not None:
table.TableName=name
#Párrafo de la table
doc.cursor.setPropertyValue("ParaStyleName", paragraph_style)
doc.document.Text.insertTextContent(doc.cursor,table,False)
#Table data, must be all strings (Not a spreadsheet)
if style is not None:
table.TableTemplateName=style #MUST BE BEFORE TO OVERRIDE SOME PROPERTIES
for row, row_data in enumerate(data):
for column, cell_data in enumerate(row_data):
cell=table.getCellByPosition( column, row)
cursor = cell.createTextCursor()
cursor.CharHeight=size
if row>0:
if data[row][column]==valores_buscados[column]:
cursor.setPropertyValue( "CharColor", 0x00DD000)
if style in ["Table0", "Table1", "Table1Total"] and row==0:
pass # Centered text for styles headers
else:
if cell_data.__class__.__name__ in ["str"]:
cursor.ParaAdjust=LEFT
else:
cursor.ParaAdjust=RIGHT
cursor.ParaRightMargin=100
cell.insertString(cursor, str(cell_data), False)
#TAble width and style
table.HoriOrient=2 #Centered
table.TopMargin=margins_top*1000
table.BottomMargin=margins_bottom*1000
table.RelativeWidth=width_percentage #PARECE QUE ES SOLO DESCRIPTIVO
#Columns width
if columnssize_percentages is not None:
separators=[]
for i, sep in enumerate(columnssize_percentages[:-1]):
separator= createUnoStruct("com.sun.star.text.TableColumnSeparator")
separator.Position=sum(columnssize_percentages[0:i+1])*100
separator.IsVisible=True
separators.append(separator)
table.TableColumnSeparators=separators
def addTableColored(doc,
valores_buscados,
data,
columnssize_percentages=None,
margins_top=0.3,
margins_bottom=0.3,
size=10,
width_percentage=100,
alignment="center",
paragraph_style="Standard",
style=None,
name=None
):
"""
Function Override de la function de unogenerator addTable
Se len añade un parametro valores_buscados. Es una lista del tamaño de la tablela
Se compara cada item con el item de cada columna en cada row
si una celda coincide con el valor buscado se pone en verde, sino en rojo
"""
from com.sun.star.style.ParagraphAdjust import RIGHT, LEFT
#Tabla definition
table=doc.document.createInstance("com.sun.star.text.TextTable")
num_rows=len(data)
if num_rows==0:
return
num_columns=len(data[0])
table.initialize(num_rows, num_columns)
if name is not None:
table.TableName=name