On Sat, 4 Jan 2025 10:32:52 -0500, DFS wrote:
I've been itching for the better part of 20 years for a cola-based MS
Office detractor to do some significant LO/Basic coding so it could be
compared to my Office/VBA.
Do you have an equivalent to this <
https://github.com/eea/odfpy>?
Here’s just one part of my invoice-formatting code:
def write_invoice_header(self, invoice) :
self.doc = odf.opendocument.OpenDocumentText()
self.invoice_prefix = invoice["invoice_prefix"]
now = time.time()
for \
this_meta \
in \
(
odf.dc.Title(text = "Invoice for %s" % invoice["client_name"].split("\n", 1)[0]),
odf.dc.Creator(text = "Geek Central Business"),
odf.meta.CreationDate(text = format_odf_time(now)),
odf.dc.Date(text = format_odf_time(now)), # interpreted by OOo as modification date
) \
:
self.doc.meta.addElement(this_meta)
#end for
self.doc.fontfacedecls.addElement \
(
odf.style.FontFace
(
name = invoice_font,
fontfamilygeneric = "roman",
fontpitch = "variable"
)
)
default_text_properties = odf.style.TextProperties \
(
fontname = invoice_font,
fontfamilygeneric = "roman"
)
default_text_properties.setAttrNS(odf.namespaces.FONS, "font-family", invoice_font)
link_element \
(
construct = odf.style.DefaultStyle,
attrs = dict(family = "paragraph"),
parent = self.doc.styles,
children =
(
default_text_properties,
odf.style.ParagraphProperties
(
marginbottom = "0.21cm",
lineheight = "115%",
),
)
)
self.doc.text.addElement \
(
odf.text.P
(
stylename = link_element
(
construct = odf.style.Style,
attrs = dict(name = "top title", family = "paragraph"),
parent = self.doc.automaticstyles,
children =
(
odf.style.ParagraphProperties
(
textalign = "center",
marginbottom = "0.71cm"
),
)
),
text = "%(gst)sINVOICE" % {"gst" : ("", "TAX ")[self.gst_rate != None]}
)
)
cust_info_item_attrs = dict \
(
textindent = "-2.0cm", # counteract marginleft on first line
marginleft = "2.0cm", # indent for lines after first
)
cust_info_item_style = link_element \
(
construct = odf.style.Style,
attrs = dict(name = "cust info item", family = "paragraph"),
parent = self.doc.automaticstyles,
children =
(
odf.style.ParagraphProperties(**cust_info_item_attrs),
)
)
cust_info_item_attrs["breakbefore"] = "column"
cust_info_item_style_2 = link_element \
(
construct = odf.style.Style,
attrs = dict(name = "cust info item 2", family = "paragraph"),
parent = self.doc.automaticstyles,
children =
(
odf.style.ParagraphProperties(**cust_info_item_attrs),
)
)
cust_info_style = link_element \
(
construct = odf.style.Style,
attrs = dict(name = "cust info", family = "section"),
parent = self.doc.automaticstyles,
children =
(
link_element \
(
construct = odf.style.SectionProperties,
children =
(
odf.style.Columns(columncount = 2),
)
),
)
)
cust_info_name_style = link_element \
(
construct = odf.style.Style,
attrs = dict(name = "cust info name", family = "text"),
parent = self.doc.automaticstyles,
children =
(
odf.style.TextProperties(fontweight = "bold"),
)
)
cust_info = odf.text.Section(name = "cust info", stylename = cust_info_style)
for \
item_name, item_value, new_col \
in \
(
(
("Client", invoice["client_name"] + "\n" + invoice["client_address"], False),
("Contact", invoice["client_contact"], False),
("Date", format_pretty_date(invoice["when_generated"]), True),
(
"Pay to",
"\n".join((details.name, details.address_1, details.address_2))
+
(
"\n" + details.country_name,
"",
)[self.gst_rate != None],
False
),
("Bank a/c", details.bank_account, False),
)
+
(
(),
(
("GST No", details.ird_nr, False),
)
)[self.gst_rate != None]
) \
:
this_item = odf.text.P \
(
stylename = (cust_info_item_style, cust_info_item_style_2)[new_col]
)
add_elements \
(
this_item,
odf.text.Span(stylename = cust_info_name_style, text = item_name),
odf.text.Tab(),
)
first_line = True
for line in item_value.split("\n") :
if not first_line :
this_item.addElement(odf.text.LineBreak())
#end if
this_item.addElement \
(
odf.text.Span(text = line)
)
first_line = False
#end for
cust_info.addElement(this_item)
#end for
self.doc.text.addElement(cust_info)
link_element \
(
construct = odf.text.P,
attrs = dict
(
stylename = link_element
(
construct = odf.style.Style,
attrs = dict(name = "work header", family = "paragraph"),
parent = self.doc.automaticstyles,
children =
(
odf.style.TextProperties(fontweight = "bold"),
link_element
(
construct = odf.style.ParagraphProperties,
children =
(
make_tab_stops((dict(position = "15.1cm"),)),
)
),
)
)
),
parent = self.doc.text,
children =
(
odf.text.Span(text = "Description of Work"),
odf.text.Tab(),
odf.text.Span(text = "Charge"),
)
)
self.work_item_tabs = \
(
dict
(
type = "char",
char = ".",
position = "15.9cm"
),
) # I can't simply build one odf.style.TabStops object and reuse it
self.work_item_style = link_element \
(
construct = odf.style.Style,
attrs = dict(name = "work item", family = "paragraph"),
parent = self.doc.automaticstyles,
children =
(
link_element
(
construct = odf.style.ParagraphProperties,
children =
(
make_tab_stops(self.work_item_tabs),
)
),
)
)
#end write_invoice_header
I can post more, if you like.