Closed micah-quinn closed 5 months ago
Hi, at the moment there is no simple way to manipulate the data of a chart. I just made an attempt by using odfdo internals, but table is seen empty? (should not of course), I need to investigate.
from odfdo import *
doc = Document("my_document.odt")
# list the parts if needed
d.get_parts()
# -> ['mimetype', 'ObjectReplacements/Object 1', 'Object 1/meta.xml', 'Object 1/styles.xml', 'Object 1/content.xml', ...
# this should have done the trick :
obj = XmlPart('Object 1/content.xml', doc.container)
body = obj.root.document_body
table = body.get_table(0)
# however strange bug for now:
table.serialize()
# -> some apparently valid xml content, but :
table.size
# -> (0, 0)
table.is_empty()
# -> True
Hey Jerome. Thanks for the quick response. I've spent an hour or so investigating this and I'm not sure what's going on. I think it has something to do with the cache map for Table. " _compute_table_cache" seems to count on having a repeated element (cols or rows), but charts from LibreOffice do not have either.
Let me know if you need me to test anything. I appreciate your help on this.
This is a crude work-around. More complex graphs I'm sure will be even less intuitive:
obj = XmlPart('Object 1/content.xml', self.doc.container)
body = obj.root.document_body
t0 = body.get_table(0)
table_rows = t0.children[3]
row0 = table_rows.children[0]
row1 = table_rows.children[1]
row0.set_value(1, 50)
row1.set_value(1, 50)
self.doc.container.set_part('Object 1/content.xml',obj.serialize())
The last v3.7.8 version fix the table problem (and improve somehow the XmlPart management). See recipe "change_values_of_a_chart_inside_a_document.py"
I'm attempting to modify the underlying data in a chart within an existing text document. The chart is placed inside a table for formatting. In the main content.xml for the document, I can see the following:
And within the content.xml file (./Object 1/content.xml) for the chart I see a chart node and table node that describe the chart and it's data.
However, when I attempt to get all tables using "doc.body.get_tables()", the table for the chart is not returned. How does one manipulate the data of a chart within a text document?
LibreOffice 7.3.7.2 odfdo 3.7.7