Форум сайта python.su
1
Кто-нибудь пытался реализовать экспорт данных в ods табличку с помощью ezodf? Мне бы хоть какую-нибудь информацию про то, как мне задать ширину столбца и высоту строки. Пытался сделать через стили:
doc1.inject_style("""<style:style style:name="hehehe" style:family="table-column"><style:table-column-properties fo:break-before="auto" style:column-width="45.47mm"/></style:style>""" sheet.column_info(0).style_name="hehehe"
Отредактировано Metallikus (Апрель 22, 2015 17:53:33)
Офлайн
1
Попытался сделать так:
parser = lxml.etree.XMLParser(recover=True) doc1.styles.automatic_styles.xmlnode = lxml.etree.fromstring("""<office:automatic-styles> <style:style style:name="co1" style:family="table-column"> <style:table-column-properties fo:break-before="auto" style:column-width="82mm"/> </style:style> <style:style style:name="co2" style:family="table-column"> <style:table-column-properties fo:break-before="auto" style:column-width="22.58mm"/> </style:style> <style:style style:name="ro1" style:family="table-row"> <style:table-row-properties style:row-height="16.32mm" fo:break-before="auto" style:use-optimal-row-height="false"/> </style:style> <style:style style:name="ro2" style:family="table-row"> <style:table-row-properties style:row-height="4.52mm" fo:break-before="auto" style:use-optimal-row-height="true"/> </style:style> <style:style style:name="ta1" style:family="table" style:master-page-name="Default"> <style:table-properties table:display="true" style:writing-mode="lr-tb"/> </style:style> </office:automatic-styles>""", parser=parser) sheet.style_name = "ta1" sheet.column_info(0).style_name="co1" sheet.row_info(row).style_name="ro1"
<office:automatic-styles/>
Офлайн
1
Извиняюсь за оверпостинг. Я победил!!!
Вот как добавил стили:
co1 = ezodf.xmlns.fake_element("""<style:style style:name="co1" style:family="table-column"> <style:table-column-properties fo:break-before="auto" style:column-width="82mm"/> </style:style>""") #столбец ro1 = ezodf.xmlns.fake_element("""<style:style style:name="ro1" style:family="table-row"> <style:table-row-properties style:row-height="16.32mm" fo:break-before="auto" style:use-optimal-row-height="false"/> </style:style>""") #строка ta1 = ezodf.xmlns.fake_element("""<style:style style:name="ta1" style:family="table" style:master-page-name="Default"> <style:table-properties table:display="true" style:writing-mode="lr-tb"/> </style:style>""") #табличка, хз нужен ли он ce1 = ezodf.xmlns.fake_element("""<style:style style:name="ce1" style:family="table-cell" style:parent-style-name="Default"> #ячейка <style:table-cell-properties fo:wrap-option="wrap" fo:border="0.06pt solid #000000" style:vertical-align="middle"/> </style:style>""") doc1.content.automatic_styles.xmlnode.append(co1.xmlnode) doc1.content.automatic_styles.xmlnode.append(ro1.xmlnode) doc1.content.automatic_styles.xmlnode.append(ta1.xmlnode) doc1.content.automatic_styles.xmlnode.append(ce1.xmlnode)
Офлайн