Macro Spreadsheet2html

Description
Exports the content of a FreeCAD SpreadSheet as styled html, can be used to import to LibreOffice Writer or Calc. Further info in the docstring of the macro.

Usage
Select a SpreadSheet and run macro.

Install
Visible in Addon manager, but install is broken. For now only option is to manually install, but you have to take the code from "view source" from this wiki. The full code is there, but it does not render on the wiki.

Link
Forum: No dedicated thread at time of writing.

Code
Macro_Spreadsheet2html.FCMacro

'):                  kva = align_table.get(which)                    if kva:                        new_attrib.update(dict((kva,)))            elif k == 'backgroundColor':                new_attrib.update(dict(bgcolor=v[:-2]))            elif k == 'displayUnit':                comment.append('unit: {}'.format(v))            elif k == 'foregroundColor': # will always be first                font = ET.Element('font', dict(color=v[:-2]))                subel.append(font)            elif k == 'style':                for which in v.split(chr(124)):                    sty = ET.Element(style_table.get(which))                    subel.insert(0, sty)        # formula options        if isinstance(td.text, str) and td.text.startswith('='):            if options.get('PasteSpecial_values'):                td.text = str(spreadsheet.get(address)) # returns casted type            elif options.get('PasteSpecial_values_and_format'): formula = td.text td.text = str(spreadsheet.get(address)) comment.append('formula: {}'.format(formula)) elif options.get('PasteSpecial_formulas_and_format'): value = spreadsheet.get(address) comment.append('value: {}'.format(value))

if options.get('PasteSpecial_values'): subel, comment = list, list for k in tuple(new_attrib): if not 'span' in k:                   _ = new_attrib.pop(k)

# sanitize for html if td.text: td.text = htmllib.escape(td.text)

if comment: ET.SubElement(td, 'a', {'class': 'comment-indicator'}) popup = ET.Element('comment') popup.text = '

Version
v0.1 2021-08-09 : first release