This commit is contained in:
eddiesoehnel committed 2026-09-22 07:50:20 -06:00
commit 2bcc107c13
39 files changed
+2643

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
"""Create a synthetic XLSX workflows worksheet using only the standard library."""
import argparse
from pathlib import Path
from xml.sax.saxutils import escape
from zipfile import ZipFile, ZIP_DEFLATED
HEADERS = ['Name','Machine','Project','Ops Segment','Mon','Tues','Wed','Thu','Fri','Sat','Sun','Other','Notes']
ROWS = [
['Demo report','demo-worker','Demo analytics','Marketing',0.375,None,None,None,None,None,None,'','Synthetic report'],
['Demo backup','demo-worker','Demo maintenance','Systems',None,0.5,None,None,None,None,None,'','Synthetic backup'],
['Demo review','demo-worker','Demo planning','Strategy',None,None,'Hourly',None,None,None,None,'','Synthetic review'],
]
def create_workbook(path, rows=None, headers=None):
path = Path(path)
path.parent.mkdir(parents=True, exist_ok=True)
matrix = [HEADERS if headers is None else headers] + (ROWS if rows is None else rows)
xml_rows = []
for rownum, row in enumerate(matrix, 1):
cells=[]
for col,value in enumerate(row):
if value is None: continue
ref=f'{chr(65+col)}{rownum}'
if isinstance(value,(int,float)):
cells.append(f'<c r="{ref}"><v>{value}</v></c>')
else:
cells.append(f'<c r="{ref}" t="inlineStr"><is><t>{escape(str(value))}</t></is></c>')
xml_rows.append(f'<row r="{rownum}">{"".join(cells)}</row>')
ns='http://schemas.openxmlformats.org/spreadsheetml/2006/main'
rel='http://schemas.openxmlformats.org/package/2006/relationships'
docrel='http://schemas.openxmlformats.org/officeDocument/2006/relationships'
with ZipFile(path,'w',ZIP_DEFLATED) as z:
z.writestr('[Content_Types].xml','<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/></Types>')
z.writestr('_rels/.rels',f'<Relationships xmlns="{rel}"><Relationship Id="rId1" Type="{docrel}/officeDocument" Target="xl/workbook.xml"/></Relationships>')
z.writestr('xl/workbook.xml',f'<workbook xmlns="{ns}" xmlns:r="{docrel}"><sheets><sheet name="workflows" sheetId="1" r:id="rId1"/></sheets></workbook>')
z.writestr('xl/_rels/workbook.xml.rels',f'<Relationships xmlns="{rel}"><Relationship Id="rId1" Type="{docrel}/worksheet" Target="worksheets/sheet1.xml"/></Relationships>')
z.writestr('xl/worksheets/sheet1.xml',f'<worksheet xmlns="{ns}"><sheetData>{"".join(xml_rows)}</sheetData></worksheet>')
if __name__=='__main__':
parser=argparse.ArgumentParser(description=__doc__)
parser.add_argument('--output',type=Path,default=Path(__file__).resolve().parent.parent/'local/workflows.xlsx')
args=parser.parse_args()
if args.output.exists(): parser.error('Output already exists; choose a new path.')
create_workbook(args.output)
print(f'Created synthetic workbook: {args.output}')