Repository Public
1#!/usr/bin/env python32# =============================================================================3# SP BOUCHER | SOFTWARE & RESEARCH4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# PROJECT METADATA8# -----------------------------------------------------------------------------9# Project : ORIX Sheet10# File : Packages/SheetIO/Tests/SheetIOTests/Generators/gen_raw_xlsx.py11# Description : Hand-written OOXML fixtures for features openpyxl cannot12# produce.13# Module : SheetIOTests14# Repository : https://git.spboucher.ai/orix-sheet15# Created : 2026-11-2116# Last Modified : 2026-11-2117#18# =============================================================================19# AUTHOR & PROFESSIONAL AFFILIATION20# =============================================================================21#22# Author : Simon-Pierre Boucher23# Position : Professor of Finance24# Institution : Université du Québec en Outaouais (UQO)25# Department : Département des sciences administratives26# Organization : SP Boucher27#28# Website : https://spboucher.ai29# Git : https://git.spboucher.ai30#31# =============================================================================32# OFFICIAL CONTACT DIRECTORY33# =============================================================================34#35# General : info@spboucher.ai36# Professional : contact@spboucher.ai37# Direct : simon@spboucher.ai38# Research : research@spboucher.ai39# Development : dev@spboucher.ai40# Support : support@spboucher.ai41# Security/Admin : admin@spboucher.ai42# Notifications : notifications@spboucher.ai43#44# Preferred Contact: support@spboucher.ai45#46# =============================================================================47# COPYRIGHT & INTELLECTUAL PROPERTY48# =============================================================================49#50# Copyright (c) 202651# Simon-Pierre Boucher52#53# All rights reserved where applicable.54#55# This file is governed by the applicable project license,56# copyright notices, institutional agreements and relevant law.57#58# Unless expressly authorized by the applicable license or59# rights holder, copying, redistribution, sublicensing,60# publication and commercial exploitation are not permitted.61#62# Existing third-party rights and notices remain unaffected.63#64# =============================================================================65# CONFIDENTIALITY & SECURITY66# =============================================================================67#68# Classification : Public69# Distribution : Public repository; use is governed by the project license70# Security Contact : admin@spboucher.ai71#72# Access to this source does not independently grant permission73# to redistribute or disclose confidential materials.74#75# Do not embed credentials, private keys, access tokens,76# certificates or confidential personal information.77#78# =============================================================================79# LICENSE & MAINTENANCE80# =============================================================================81#82# License : None specified (no license file in this repository)83# Maintainer : Simon-Pierre Boucher84# Technical Contact: dev@spboucher.ai85#86# =============================================================================87# END OF SP BOUCHER SOURCE HEADER88# =============================================================================8990"""Hand-written OOXML fixtures for features openpyxl cannot produce.9192Usage: gen_raw_xlsx.py OUTDIR93 raw_features.xlsx shared formulas, inline strings, ISO dates, dynamic arrays (cm + metadata),94 legacy array formulas, _xlpm/_xlfn prefixes, external links, unknown functions,95 cells and rows without r attributes, theme/tint/indexed colours, gradient fill,96 rich + phonetic shared strings, _xHHHH_ escapes, threaded comments, x14 data97 validation, sparklines, a chart sheet, a pivot table (synthetic parts), custom XML,98 custom document properties, hidden defined names, print titles.99 macro.xlsm a workbook with a (fake, never executed) vbaProject.bin and VBA code names.100The pivot, chart-sheet and VBA parts are structurally plausible placeholders: SheetIO never101interprets them, the tests only check that the bytes are preserved or dropped as documented.102"""103import sys104import zipfile105from pathlib import Path106107MAIN = "http://schemas.openxmlformats.org/spreadsheetml/2006/main"108REL = "http://schemas.openxmlformats.org/officeDocument/2006/relationships"109PKG = "http://schemas.openxmlformats.org/package/2006/relationships"110HEAD = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n'111112113def rels(items):114 body = "".join('<Relationship Id="%s" Type="%s" Target="%s"%s/>' % (i, t, tg, ' TargetMode="External"' if ext else "")115 for i, t, tg, ext in items)116 return HEAD + '<Relationships xmlns="%s">%s</Relationships>' % (PKG, body)117118119THEME = HEAD + '''<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="T"><a:themeElements><a:clrScheme name="C">120<a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1><a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1>121<a:dk2><a:srgbClr val="1F497D"/></a:dk2><a:lt2><a:srgbClr val="EEECE1"/></a:lt2>122<a:accent1><a:srgbClr val="4F81BD"/></a:accent1><a:accent2><a:srgbClr val="C0504D"/></a:accent2><a:accent3><a:srgbClr val="9BBB59"/></a:accent3>123<a:accent4><a:srgbClr val="8064A2"/></a:accent4><a:accent5><a:srgbClr val="4BACC6"/></a:accent5><a:accent6><a:srgbClr val="F79646"/></a:accent6>124<a:hlink><a:srgbClr val="0000FF"/></a:hlink><a:folHlink><a:srgbClr val="800080"/></a:folHlink></a:clrScheme>125<a:fontScheme name="F"><a:majorFont><a:latin typeface="Cambria"/><a:ea typeface=""/><a:cs typeface=""/></a:majorFont><a:minorFont><a:latin typeface="Calibri"/><a:ea typeface=""/><a:cs typeface=""/></a:minorFont></a:fontScheme>126<a:fmtScheme name="O"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:fillStyleLst><a:lnStyleLst><a:ln w="9525"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln><a:ln w="9525"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln><a:ln w="9525"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:ln></a:lnStyleLst><a:effectStyleLst><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle><a:effectStyle><a:effectLst/></a:effectStyle></a:effectStyleLst><a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:solidFill><a:schemeClr val="phClr"/></a:solidFill></a:bgFillStyleLst></a:fmtScheme></a:themeElements></a:theme>'''127128STYLES = HEAD + '''<styleSheet xmlns="%s"><numFmts count="1"><numFmt numFmtId="164" formatCode="0.0" u""/></numFmts>129<fonts count="3"><font><sz val="11"/><color theme="1"/><name val="Calibri"/></font>130<font><b/><sz val="11"/><color theme="4" tint="-0.249977111117893"/><name val="Calibri"/></font>131<font><i/><u/><sz val="9"/><color indexed="12"/><name val="Courier New"/></font></fonts>132<fills count="5"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill>133<fill><patternFill patternType="solid"><fgColor theme="0" tint="-0.14999847407452621"/><bgColor indexed="64"/></patternFill></fill>134<fill><gradientFill degree="90"><stop position="0"><color rgb="FFFF0000"/></stop><stop position="1"><color rgb="FF0000FF"/></stop></gradientFill></fill>135<fill><patternFill patternType="darkGrid"><fgColor rgb="FF00FF00"/><bgColor rgb="FFFFFFFF"/></patternFill></fill></fills>136<borders count="2"><border><left/><right/><top/><bottom/><diagonal/></border>137<border diagonalUp="1"><left style="hair"><color auto="1"/></left><right/><top/><bottom style="thick"><color theme="5"/></bottom><diagonal style="thin"><color auto="1"/></diagonal></border></borders>138<cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/></cellStyleXfs>139<cellXfs count="7"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>140<xf numFmtId="14" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/>141<xf numFmtId="0" fontId="1" fillId="2" borderId="0" xfId="0" applyFont="1" applyFill="1"/>142<xf numFmtId="164" fontId="2" fillId="0" borderId="1" xfId="0" applyNumberFormat="1" applyFont="1" applyBorder="1"/>143<xf numFmtId="0" fontId="0" fillId="3" borderId="0" xfId="0" applyFill="1"/>144<xf numFmtId="0" fontId="0" fillId="4" borderId="0" xfId="0" applyFill="1"><alignment textRotation="255"/></xf>145<xf numFmtId="22" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/></cellXfs>146<cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles><dxfs count="0"/></styleSheet>''' % MAIN147148SST = HEAD + '''<sst xmlns="%s" count="4" uniqueCount="4"><si><t>shared zero</t></si>149<si><r><t xml:space="preserve">rich </t></r><r><rPr><b/></rPr><t>bold</t></r><rPh sb="0" eb="1"><t>PHONETIC</t></rPh></si>150<si><t>carriage_x000D_return and _x005F_x0041_ kept</t></si><si><t xml:space="preserve"> padded </t></si></sst>''' % MAIN151152SHEET1 = HEAD + '''<worksheet xmlns="%s" xmlns:r="%s" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main" xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main"><sheetPr codeName="RawSheet"/><dimension ref="A1:J8"/>153<sheetViews><sheetView workbookViewId="0"><pane ySplit="1" topLeftCell="A2" activePane="bottomLeft" state="frozen"/></sheetView></sheetViews>154<sheetFormatPr defaultRowHeight="15"/><cols><col min="1" max="1" width="20" customWidth="1" style="2"/><col min="3" max="4" width="12.5" customWidth="1"/></cols>155<sheetData>156<row r="1"><c r="A1" t="s"><v>0</v></c><c r="B1" t="inlineStr"><is><t>inline text</t></is></c><c r="C1" t="d"><v>2024-03-05T12:00:00</v></c>157<c r="D1" t="str"><f>"str"&"ing"</f><v>string</v></c><c r="E1" t="b"><v>1</v></c><c r="F1" t="e"><v>#REF!</v></c><c r="G1" t="s"><v>1</v></c><c r="H1" t="s"><v>2</v></c><c r="I1" t="s"><v>3</v></c><c r="J1" s="1"><v>45000</v></c></row>158<row r="2"><c r="A2"><v>3</v></c><c r="B2"><f t="shared" ref="B2:B5" si="0">A2*2+$A$2</f><v>9</v></c>159<c r="D2" cm="1"><f t="array" ref="D2:D5">_xlfn._xlws.SORT(A2:A5)</f><v>1</v></c>160<c r="F2"><f t="array" ref="F2:F3">A2:A3+1</f><v>4</v></c><c r="G2"><f>_xlfn.LET(_xlpm.x,A2,_xlpm.x*2)</f><v>6</v></c>161<c r="H2"><f>[1]Ext!$A$1+1</f><v>100</v></c><c r="I2"><f>SUM(_xlfn.ANCHORARRAY(D2))</f><v>10</v></c><c r="J2"><f>MYUDF(A2)+_xlfn.FUTUREFN(1)</f><v>7</v></c></row>162<row r="3"><c r="A3"><v>1</v></c><c r="B3"><f t="shared" si="0"/><v>5</v></c><c r="D3"><v>2</v></c><c r="F3"><v>2</v></c></row>163<row r="4"><c r="A4"><v>4</v></c><c r="B4"><f t="shared" si="0"/><v>11</v></c><c r="D4"><v>3</v></c></row>164<row r="5"><c r="A5"><v>2</v></c><c r="B5"><f t="shared" si="0"/><v>7</v></c><c r="D5"><v>4</v></c></row>165<row r="6" ht="33" customHeight="1"><c r="A6" s="2"><v>6.5</v></c><c r="B6" s="3"><v>1.25</v></c><c r="C6" s="4"><v>1</v></c><c r="D6" s="5"><v>2</v></c><c r="E6" s="6"><v>45000.5</v></c></row>166<row><c><v>70</v></c><c><v>71</v></c><c t="inlineStr"><is><r><t>run1</t></r><r><t>run2</t></r></is></c></row>167<row r="8"><c r="A8"><f>A2>A3</f><v>1</v></c><c r="B8" t="b"><f>A2<A3</f><v>0</v></c><c r="C8" t="e"><f>1/0</f><v>#DIV/0!</v></c><c r="D8"><f>A2</f></c></row>168</sheetData>169<legacyDrawing r:id="rId1"/>170<extLst><ext uri="{CCE6A557-97BC-4b89-ADB6-D9C93CAAB3DF}"><x14:dataValidations count="1"><x14:dataValidation type="list" allowBlank="1" showInputMessage="1" showErrorMessage="1"><x14:formula1><xm:f>Second!$A$1:$A$3</xm:f></x14:formula1><xm:sqref>J5:J6</xm:sqref></x14:dataValidation></x14:dataValidations></ext>171<ext uri="{05C60535-1F16-4fd2-B633-F4F36F0B64E0}"><x14:sparklineGroups><x14:sparklineGroup><x14:sparklines><x14:sparkline><xm:f>Raw!A2:A5</xm:f><xm:sqref>J8</xm:sqref></x14:sparkline></x14:sparklines></x14:sparklineGroup></x14:sparklineGroups></ext></extLst>172</worksheet>''' % (MAIN, REL)173174COMMENTS = HEAD + '''<comments xmlns="%s"><authors><author>Legacy Author</author><author>tc={11111111-1111-1111-1111-111111111111}</author></authors><commentList>175<comment ref="A2" authorId="0"><text><r><rPr><b/></rPr><t>Legacy Author:</t></r><r><t xml:space="preserve">176legacy note</t></r></text></comment>177<comment ref="B2" authorId="1"><text><t>[Threaded comment] placeholder</t></text></comment></commentList></comments>''' % MAIN178179THREADED = HEAD + '''<ThreadedComments xmlns="http://schemas.microsoft.com/office/spreadsheetml/2018/threadedcomments">180<threadedComment ref="B2" dT="2024-05-06T07:08:09.10" personId="{AAAAAAAA-0000-0000-0000-000000000001}" id="{11111111-1111-1111-1111-111111111111}"><text>First message</text></threadedComment>181<threadedComment ref="B2" dT="2024-05-06T08:00:00.00" personId="{AAAAAAAA-0000-0000-0000-000000000002}" id="{22222222-2222-2222-2222-222222222222}" parentId="{11111111-1111-1111-1111-111111111111}"><text>A reply</text></threadedComment></ThreadedComments>'''182183PERSONS = HEAD + '''<personList xmlns="http://schemas.microsoft.com/office/spreadsheetml/2018/threadedcomments"><person displayName="Thread Starter" id="{AAAAAAAA-0000-0000-0000-000000000001}" userId="a" providerId="None"/><person displayName="Replier" id="{AAAAAAAA-0000-0000-0000-000000000002}" userId="b" providerId="None"/></personList>'''184185VML = '''<xml xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"><v:shape id="_x0000_s1025" type="#_x0000_t202"><x:ClientData ObjectType="Note"><x:Row>1</x:Row><x:Column>0</x:Column></x:ClientData></v:shape></xml>'''186187SHEET2 = HEAD + '''<worksheet xmlns="%s" xmlns:r="%s"><sheetData><row r="1"><c r="A1" t="inlineStr"><is><t>one</t></is></c><c r="B1"><v>10</v></c></row>188<row r="2"><c r="A2" t="inlineStr"><is><t>two</t></is></c><c r="B2"><v>20</v></c></row><row r="3"><c r="A3" t="inlineStr"><is><t>three</t></is></c><c r="B3"><v>30</v></c></row></sheetData>189<pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/></worksheet>''' % (MAIN, REL)190191CHARTSHEET = HEAD + '<chartsheet xmlns="%s" xmlns:r="%s"><sheetViews><sheetView workbookViewId="0"/></sheetViews></chartsheet>' % (MAIN, REL)192193EXTERNAL = HEAD + '''<externalLink xmlns="%s" xmlns:r="%s"><externalBook r:id="rId1"><sheetNames><sheetName val="Ext"/></sheetNames><sheetDataSet><sheetData sheetId="0"><row r="1"><cell r="A1"><v>99</v></cell></row></sheetData></sheetDataSet></externalBook></externalLink>''' % (MAIN, REL)194195PIVOT_TABLE = HEAD + '''<pivotTableDefinition xmlns="%s" name="PivotTable1" cacheId="7" dataCaption="Values"><location ref="D1:E4" firstHeaderRow="1" firstDataRow="1" firstDataCol="1"/></pivotTableDefinition>''' % MAIN196PIVOT_CACHE = HEAD + '''<pivotCacheDefinition xmlns="%s" xmlns:r="%s" r:id="rId1" recordCount="3"><cacheSource type="worksheet"><worksheetSource ref="A1:B3" sheet="Second"/></cacheSource><cacheFields count="0"/></pivotCacheDefinition>''' % (MAIN, REL)197PIVOT_RECORDS = HEAD + '<pivotCacheRecords xmlns="%s" count="0"/>' % MAIN198199METADATA = HEAD + '''<metadata xmlns="%s" xmlns:xda="http://schemas.microsoft.com/office/spreadsheetml/2017/dynamicarray"><metadataTypes count="1"><metadataType name="XLDAPR" minSupportedVersion="120000" copy="1" pasteAll="1" pasteValues="1" merge="1" splitFirst="1" rowColShift="1" clearFormats="1" clearComments="1" assign="1" coerce="1" cellMeta="1"/></metadataTypes><futureMetadata name="XLDAPR" count="1"><bk><extLst><ext uri="{bdbb8cdc-fa1e-496e-a857-3c3f30c029c3}"><xda:dynamicArrayProperties fDynamic="1" fCollapsed="0"/></ext></extLst></bk></futureMetadata><cellMetadata count="1"><bk><rc t="1" v="0"/></bk></cellMetadata></metadata>''' % MAIN200201CORE = HEAD + '''<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><dc:title>Raw fixture</dc:title><dc:creator>gen_raw_xlsx</dc:creator><dcterms:created xsi:type="dcterms:W3CDTF">2024-01-01T00:00:00Z</dcterms:created></cp:coreProperties>'''202CUSTOM = HEAD + '''<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"><property fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="2" name="Project"><vt:lpwstr>ORIX</vt:lpwstr></property></Properties>'''203204205def raw_features(path):206 ct = HEAD + '''<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"/><Default Extension="vml" ContentType="application/vnd.openxmlformats-officedocument.vmlDrawing"/>207<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>208<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>209<Override PartName="/xl/worksheets/sheet2.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>210<Override PartName="/xl/chartsheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml"/>211<Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/>212<Override PartName="/xl/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>213<Override PartName="/xl/sharedStrings.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml"/>214<Override PartName="/xl/comments1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml"/>215<Override PartName="/xl/threadedComments/threadedComment1.xml" ContentType="application/vnd.ms-excel.threadedcomments+xml"/>216<Override PartName="/xl/persons/person.xml" ContentType="application/vnd.ms-excel.person+xml"/>217<Override PartName="/xl/metadata.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheetMetadata+xml"/>218<Override PartName="/xl/externalLinks/externalLink1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml"/>219<Override PartName="/xl/pivotTables/pivotTable1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.pivotTable+xml"/>220<Override PartName="/xl/pivotCache/pivotCacheDefinition1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml"/>221<Override PartName="/xl/pivotCache/pivotCacheRecords1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml"/>222<Override PartName="/customXml/itemProps1.xml" ContentType="application/vnd.openxmlformats-officedocument.customXmlProperties+xml"/>223<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>224<Override PartName="/docProps/custom.xml" ContentType="application/vnd.openxmlformats-officedocument.custom-properties+xml"/></Types>'''225 workbook = HEAD + '''<workbook xmlns="%s" xmlns:r="%s"><workbookPr codeName="ThisWorkbook"/><bookViews><workbookView activeTab="2"/></bookViews>226<sheets><sheet name="Raw" sheetId="1" r:id="rId1"/><sheet name="ChartSheet" sheetId="2" r:id="rId2"/><sheet name="Second" sheetId="3" r:id="rId3"/></sheets>227<externalReferences><externalReference r:id="rId8"/></externalReferences>228<definedNames><definedName name="_xlnm.Print_Titles" localSheetId="2">Second!$A:$A,Second!$1:$1</definedName><definedName name="_xlnm.Print_Area" localSheetId="0">Raw!$A$1:$E$5,Raw!$G$1:$H$2</definedName>229<definedName name="HiddenName" hidden="1" comment="a secret">Raw!$A$2:$A$5</definedName><definedName name="ExtName">[1]Ext!$A$1</definedName><definedName name="SecondLocal" localSheetId="2">Second!$B$1</definedName>230<definedName name="Future">_xlfn.XLOOKUP(1,Raw!$A$2:$A$5,Raw!$B$2:$B$5)</definedName></definedNames>231<calcPr calcId="191029"/><pivotCaches><pivotCache cacheId="7" r:id="rId9"/></pivotCaches></workbook>''' % (MAIN, REL)232 wb_rels = rels([("rId1", REL + "/worksheet", "worksheets/sheet1.xml", False), ("rId2", REL + "/chartsheet", "chartsheets/sheet1.xml", False),233 ("rId3", REL + "/worksheet", "worksheets/sheet2.xml", False), ("rId4", REL + "/styles", "styles.xml", False),234 ("rId5", REL + "/theme", "theme/theme1.xml", False), ("rId6", REL + "/sharedStrings", "sharedStrings.xml", False),235 ("rId7", "http://schemas.microsoft.com/office/2017/10/relationships/person", "persons/person.xml", False),236 ("rId8", REL + "/externalLink", "externalLinks/externalLink1.xml", False),237 ("rId9", REL + "/pivotCacheDefinition", "pivotCache/pivotCacheDefinition1.xml", False),238 ("rId10", REL + "/sheetMetadata", "metadata.xml", False), ("rId11", REL + "/customXml", "../customXml/item1.xml", False)])239 with zipfile.ZipFile(path, "w", zipfile.ZIP_DEFLATED) as z:240 z.writestr("[Content_Types].xml", ct)241 z.writestr("_rels/.rels", rels([("rId1", REL + "/officeDocument", "xl/workbook.xml", False),242 ("rId2", "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", "docProps/core.xml", False),243 ("rId3", REL + "/custom-properties", "docProps/custom.xml", False)]))244 z.writestr("docProps/core.xml", CORE)245 z.writestr("docProps/custom.xml", CUSTOM)246 z.writestr("xl/workbook.xml", workbook)247 z.writestr("xl/_rels/workbook.xml.rels", wb_rels)248 z.writestr("xl/styles.xml", STYLES)249 z.writestr("xl/theme/theme1.xml", THEME)250 z.writestr("xl/sharedStrings.xml", SST)251 z.writestr("xl/metadata.xml", METADATA)252 z.writestr("xl/worksheets/sheet1.xml", SHEET1)253 z.writestr("xl/worksheets/_rels/sheet1.xml.rels", rels([254 ("rId1", REL + "/vmlDrawing", "../drawings/vmlDrawing1.vml", False), ("rId2", REL + "/comments", "../comments1.xml", False),255 ("rId3", "http://schemas.microsoft.com/office/2017/10/relationships/threadedComment", "../threadedComments/threadedComment1.xml", False)]))256 z.writestr("xl/drawings/vmlDrawing1.vml", VML)257 z.writestr("xl/comments1.xml", COMMENTS)258 z.writestr("xl/threadedComments/threadedComment1.xml", THREADED)259 z.writestr("xl/persons/person.xml", PERSONS)260 z.writestr("xl/worksheets/sheet2.xml", SHEET2)261 z.writestr("xl/worksheets/_rels/sheet2.xml.rels", rels([("rId1", REL + "/pivotTable", "../pivotTables/pivotTable1.xml", False)]))262 z.writestr("xl/chartsheets/sheet1.xml", CHARTSHEET)263 z.writestr("xl/externalLinks/externalLink1.xml", EXTERNAL)264 z.writestr("xl/externalLinks/_rels/externalLink1.xml.rels", rels([265 ("rId1", REL + "/externalLinkPath", "file:///C:/data/other%20book.xlsx", True)]))266 z.writestr("xl/pivotTables/pivotTable1.xml", PIVOT_TABLE)267 z.writestr("xl/pivotTables/_rels/pivotTable1.xml.rels", rels([("rId1", REL + "/pivotCacheDefinition", "../pivotCache/pivotCacheDefinition1.xml", False)]))268 z.writestr("xl/pivotCache/pivotCacheDefinition1.xml", PIVOT_CACHE)269 z.writestr("xl/pivotCache/_rels/pivotCacheDefinition1.xml.rels", rels([("rId1", REL + "/pivotCacheRecords", "pivotCacheRecords1.xml", False)]))270 z.writestr("xl/pivotCache/pivotCacheRecords1.xml", PIVOT_RECORDS)271 z.writestr("customXml/item1.xml", '<?xml version="1.0"?><root xmlns="urn:orix:test"><value>custom</value></root>')272 z.writestr("customXml/_rels/item1.xml.rels", rels([("rId1", REL + "/customXmlProps", "itemProps1.xml", False)]))273 z.writestr("customXml/itemProps1.xml", HEAD + '<ds:datastoreItem ds:itemID="{0D0D0D0D-0000-0000-0000-000000000000}" xmlns:ds="http://schemas.openxmlformats.org/officeDocument/2006/customXml"/>')274275276def macro(path):277 ct = HEAD + '''<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"/><Default Extension="bin" ContentType="application/vnd.ms-office.vbaProject"/>278<Override PartName="/xl/workbook.xml" ContentType="application/vnd.ms-excel.sheet.macroEnabled.main+xml"/>279<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/></Types>'''280 workbook = HEAD + '''<workbook xmlns="%s" xmlns:r="%s"><workbookPr codeName="ThisWorkbook"/><sheets><sheet name="Macro" sheetId="1" r:id="rId1"/></sheets></workbook>''' % (MAIN, REL)281 sheet = HEAD + '''<worksheet xmlns="%s"><sheetPr codeName="Sheet1"/><sheetData><row r="1"><c r="A1"><v>1</v></c><c r="B1"><f>A1+1</f><v>2</v></c></row></sheetData></worksheet>''' % MAIN282 vba = bytes([0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1]) + b"FAKE VBA PROJECT - never executed - " + bytes(range(256)) * 4283 with zipfile.ZipFile(path, "w", zipfile.ZIP_DEFLATED) as z:284 z.writestr("[Content_Types].xml", ct)285 z.writestr("_rels/.rels", rels([("rId1", REL + "/officeDocument", "xl/workbook.xml", False)]))286 z.writestr("xl/workbook.xml", workbook)287 z.writestr("xl/_rels/workbook.xml.rels", rels([("rId1", REL + "/worksheet", "worksheets/sheet1.xml", False),288 ("rId2", "http://schemas.microsoft.com/office/2006/relationships/vbaProject", "vbaProject.bin", False)]))289 z.writestr("xl/worksheets/sheet1.xml", sheet)290 z.writestr("xl/vbaProject.bin", vba)291292293if __name__ == "__main__":294 out = Path(sys.argv[1])295 out.mkdir(parents=True, exist_ok=True)296 raw_features(out / "raw_features.xlsx")297 macro(out / "macro.xlsm")298 print("ok")299