def write_properties_app(workbook): """Write the properties xml.""" worksheets_count = len(workbook.worksheets) root = Element('Properties', {'xmlns': 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties', 'xmlns:vt': 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes'}) SubElement(root, 'Application').text = 'Microsoft Excel' SubElement(root, 'DocSecurity').text = '0' SubElement(root, 'ScaleCrop').text = 'false' SubElement(root, 'Company') SubElement(root, 'LinksUpToDate').text = 'false' SubElement(root, 'SharedDoc').text = 'false' SubElement(root, 'HyperlinksChanged').text = 'false' SubElement(root, 'AppVersion').text = '12.0000' # heading pairs part heading_pairs = SubElement(root, 'HeadingPairs') vector = SubElement(heading_pairs, 'vt:vector', {'size': '2', 'baseType': 'variant'}) variant = SubElement(vector, 'vt:variant') SubElement(variant, 'vt:lpstr').text = 'Worksheets' variant = SubElement(vector, 'vt:variant') SubElement(variant, 'vt:i4').text = '%d' % worksheets_count # title of parts title_of_parts = SubElement(root, 'TitlesOfParts') vector = SubElement(title_of_parts, 'vt:vector', {'size': '%d' % worksheets_count, 'baseType': 'lpstr'}) for ws in workbook.worksheets: SubElement(vector, 'vt:lpstr').text = '%s' % ws.title return get_document_content(root)
def write_workbook(workbook): """Write the core workbook xml.""" root = Element('workbook', {'xmlns': 'http://schemas.openxmlformats.org/spreadsheetml/2006/main', 'xml:space': 'preserve', 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'}) SubElement(root, 'fileVersion', {'appName': 'xl', 'lastEdited': '4', 'lowestEdited': '4', 'rupBuild': '4505'}) SubElement(root, 'workbookPr', {'defaultThemeVersion': '124226', 'codeName': 'ThisWorkbook'}) book_views = SubElement(root, 'bookViews') SubElement(book_views, 'workbookView', {'activeTab': '%d' % workbook.get_index(workbook.get_active_sheet()), 'autoFilterDateGrouping': '1', 'firstSheet': '0', 'minimized': '0', 'showHorizontalScroll': '1', 'showSheetTabs': '1', 'showVerticalScroll': '1', 'tabRatio': '600', 'visibility': 'visible'}) # worksheets sheets = SubElement(root, 'sheets') for i, sheet in enumerate(workbook.worksheets): sheet_node = SubElement(sheets, 'sheet', {'name': sheet.title, 'sheetId': '%d' % (i + 1), 'r:id': 'rId%d' % (i + 1)}) if not sheet.sheet_state == sheet.SHEETSTATE_VISIBLE: sheet_node.set('state', sheet.sheet_state) # Defined names defined_names = SubElement(root, 'definedNames') # named ranges for named_range in workbook.get_named_ranges(): name = SubElement(defined_names, 'definedName', {'name': named_range.name}) if named_range.scope: name.set('localSheetId', '%s' % workbook.get_index(named_range.scope)) if isinstance(named_range, NamedRange): # as there can be many cells in one range, generate the list of ranges dest_cells = [] for worksheet, range_name in named_range.destinations: dest_cells.append("'%s'!%s" % (worksheet.title.replace("'", "''"), absolute_coordinate(range_name))) # finally write the cells list name.text = ','.join(dest_cells) else: assert isinstance(named_range, NamedRangeContainingValue) name.text = named_range.value # autoFilter for i, sheet in enumerate(workbook.worksheets): #continue auto_filter = sheet.auto_filter if not auto_filter: continue name = SubElement(defined_names, 'definedName', dict(name='_xlnm._FilterDatabase', localSheetId=str(i), hidden='1')) name.text = "'%s'!%s" % (sheet.title.replace("'", "''"), absolute_coordinate(auto_filter)) SubElement(root, 'calcPr', {'calcId': '124519', 'calcMode': 'auto', 'fullCalcOnLoad': '1'}) return get_document_content(root)
def write_root_rels(workbook): """Write the relationships xml.""" root = Element('Relationships', { 'xmlns': 'http://schemas.openxmlformats.org/package/2006/relationships' }) SubElement( root, 'Relationship', { 'Id': 'rId1', 'Target': ARC_WORKBOOK, 'Type': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument' }) SubElement( root, 'Relationship', { 'Id': 'rId2', 'Target': ARC_CORE, 'Type': 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties' }) SubElement( root, 'Relationship', { 'Id': 'rId3', 'Target': ARC_APP, 'Type': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties' }) return get_document_content(root)
def write_rels(self, drawing_id): root = Element('Relationships', {'xmlns' : 'http://schemas.openxmlformats.org/package/2006/relationships'}) attrs = {'Id' : 'rId1', 'Type' : 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartUserShapes', 'Target' : '../drawings/drawing%s.xml' % drawing_id } SubElement(root, 'Relationship', attrs) return get_document_content(root)
def write_root_rels(workbook): """Write the relationships xml.""" root = Element('Relationships', {'xmlns': 'http://schemas.openxmlformats.org/package/2006/relationships'}) SubElement(root, 'Relationship', {'Id': 'rId1', 'Target': ARC_WORKBOOK, 'Type': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument'}) SubElement(root, 'Relationship', {'Id': 'rId2', 'Target': ARC_CORE, 'Type': 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties'}) SubElement(root, 'Relationship', {'Id': 'rId3', 'Target': ARC_APP, 'Type': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties'}) return get_document_content(root)
def write_table(self): number_format_table = self._write_number_formats() fonts_table = self._write_fonts() fills_table = self._write_fills() borders_table = self._write_borders() self._write_cell_style_xfs() self._write_cell_xfs(number_format_table, fonts_table, fills_table, borders_table) self._write_cell_style() self._write_dxfs() self._write_table_styles() return get_document_content(xml_node=self._root)
def write(self): """ write a chart """ root = Element('c:chartSpace', {'xmlns:c':"http://schemas.openxmlformats.org/drawingml/2006/chart", 'xmlns:a':"http://schemas.openxmlformats.org/drawingml/2006/main", 'xmlns:r':"http://schemas.openxmlformats.org/officeDocument/2006/relationships"}) SubElement(root, 'c:lang', {'val':self.chart.lang}) self._write_chart(root) self._write_print_settings(root) self._write_shapes(root) return get_document_content(root)
def write_worksheet_rels(worksheet, idx): """Write relationships for the worksheet to xml.""" root = Element('Relationships', {'xmlns': 'http://schemas.openxmlformats.org/package/2006/relationships'}) for rel in worksheet.relationships: attrs = {'Id': rel.id, 'Type': rel.type, 'Target': rel.target} if rel.target_mode: attrs['TargetMode'] = rel.target_mode SubElement(root, 'Relationship', attrs) if worksheet._charts or worksheet._images: attrs = {'Id' : 'rId1', 'Type' : 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing', 'Target' : '../drawings/drawing%s.xml' % idx } SubElement(root, 'Relationship', attrs) return get_document_content(root)
def write_properties_core(properties): """Write the core properties to xml.""" root = Element('cp:coreProperties', {'xmlns:cp': NAMESPACES['cp'], 'xmlns:xsi': NAMESPACES['xsi'], 'xmlns:dc': NAMESPACES['dc'], 'xmlns:dcterms': NAMESPACES['dcterms'], 'xmlns:dcmitype': NAMESPACES['dcmitype'], }) SubElement(root, 'dc:creator').text = properties.creator SubElement(root, 'cp:lastModifiedBy').text = properties.last_modified_by SubElement(root, 'dcterms:created', \ {'xsi:type': 'dcterms:W3CDTF'}).text = \ datetime_to_W3CDTF(properties.created) SubElement(root, 'dcterms:modified', {'xsi:type': 'dcterms:W3CDTF'}).text = \ datetime_to_W3CDTF(properties.modified) return get_document_content(root)
def write_rels(self, chart_id, image_id): root = Element('Relationships', {'xmlns' : 'http://schemas.openxmlformats.org/package/2006/relationships'}) i = 0 for i, chart in enumerate(self._sheet._charts): attrs = {'Id' : 'rId%s' % (i + 1), 'Type' : 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', 'Target' : '../charts/chart%s.xml' % (chart_id + i) } SubElement(root, 'Relationship', attrs) for j, img in enumerate(self._sheet._images): attrs = {'Id' : 'rId%s' % (i + j + 1), 'Type' : 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', 'Target' : '../media/image%s.png' % (image_id + j) } SubElement(root, 'Relationship', attrs) return get_document_content(root)
def write(self, shape_id): root = Element('c:userShapes', {'xmlns:c' : 'http://schemas.openxmlformats.org/drawingml/2006/chart'}) for shape in self._shapes: anchor = SubElement(root, 'cdr:relSizeAnchor', {'xmlns:cdr' : "http://schemas.openxmlformats.org/drawingml/2006/chartDrawing"}) xstart, ystart, xend, yend = shape.get_coordinates() _from = SubElement(anchor, 'cdr:from') SubElement(_from, 'cdr:x').text = str(xstart) SubElement(_from, 'cdr:y').text = str(ystart) _to = SubElement(anchor, 'cdr:to') SubElement(_to, 'cdr:x').text = str(xend) SubElement(_to, 'cdr:y').text = str(yend) sp = SubElement(anchor, 'cdr:sp', {'macro':'', 'textlink':''}) nvspr = SubElement(sp, 'cdr:nvSpPr') SubElement(nvspr, 'cdr:cNvPr', {'id':str(shape_id), 'name':'shape %s' % shape_id}) SubElement(nvspr, 'cdr:cNvSpPr') sppr = SubElement(sp, 'cdr:spPr') frm = SubElement(sppr, 'a:xfrm', {'xmlns:a':self.schema}) # no transformation SubElement(frm, 'a:off', {'x':'0', 'y':'0'}) SubElement(frm, 'a:ext', {'cx':'0', 'cy':'0'}) prstgeom = SubElement(sppr, 'a:prstGeom', {'xmlns:a':self.schema, 'prst':str(shape.style)}) SubElement(prstgeom, 'a:avLst') fill = SubElement(sppr, 'a:solidFill', {'xmlns:a':self.schema}) SubElement(fill, 'a:srgbClr', {'val':shape.color}) border = SubElement(sppr, 'a:ln', {'xmlns:a':self.schema, 'w':str(shape._border_width)}) sf = SubElement(border, 'a:solidFill') SubElement(sf, 'a:srgbClr', {'val':shape.border_color}) self._write_style(sp) self._write_text(sp, shape) shape_id += 1 return get_document_content(root)
def write_workbook_rels(workbook): """Write the workbook relationships xml.""" root = Element('Relationships', {'xmlns': 'http://schemas.openxmlformats.org/package/2006/relationships'}) for i in range(len(workbook.worksheets)): SubElement(root, 'Relationship', {'Id': 'rId%d' % (i + 1), 'Type': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet', 'Target': 'worksheets/sheet%s.xml' % (i + 1)}) rid = len(workbook.worksheets) + 1 SubElement(root, 'Relationship', {'Id': 'rId%d' % rid, 'Target': 'sharedStrings.xml', 'Type': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings'}) SubElement(root, 'Relationship', {'Id': 'rId%d' % (rid + 1), 'Target': 'styles.xml', 'Type': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles'}) SubElement(root, 'Relationship', {'Id': 'rId%d' % (rid + 2), 'Target': 'theme/theme1.xml', 'Type': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme'}) return get_document_content(root)
def write_properties_core(properties): """Write the core properties to xml.""" root = Element( 'cp:coreProperties', { 'xmlns:cp': NAMESPACES['cp'], 'xmlns:xsi': NAMESPACES['xsi'], 'xmlns:dc': NAMESPACES['dc'], 'xmlns:dcterms': NAMESPACES['dcterms'], 'xmlns:dcmitype': NAMESPACES['dcmitype'], }) SubElement(root, 'dc:creator').text = properties.creator SubElement(root, 'cp:lastModifiedBy').text = properties.last_modified_by SubElement(root, 'dcterms:created', \ {'xsi:type': 'dcterms:W3CDTF'}).text = \ datetime_to_W3CDTF(properties.created) SubElement(root, 'dcterms:modified', {'xsi:type': 'dcterms:W3CDTF'}).text = \ datetime_to_W3CDTF(properties.modified) return get_document_content(root)
def write_workbook_rels(workbook): """Write the workbook relationships xml.""" root = Element('Relationships', { 'xmlns': 'http://schemas.openxmlformats.org/package/2006/relationships' }) for i in range(len(workbook.worksheets)): SubElement( root, 'Relationship', { 'Id': 'rId%d' % (i + 1), 'Type': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet', 'Target': 'worksheets/sheet%s.xml' % (i + 1) }) rid = len(workbook.worksheets) + 1 SubElement( root, 'Relationship', { 'Id': 'rId%d' % rid, 'Target': 'sharedStrings.xml', 'Type': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings' }) SubElement( root, 'Relationship', { 'Id': 'rId%d' % (rid + 1), 'Target': 'styles.xml', 'Type': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles' }) SubElement( root, 'Relationship', { 'Id': 'rId%d' % (rid + 2), 'Target': 'theme/theme1.xml', 'Type': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme' }) return get_document_content(root)
def write_properties_app(workbook): """Write the properties xml.""" worksheets_count = len(workbook.worksheets) root = Element( 'Properties', { 'xmlns': 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties', 'xmlns:vt': 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes' }) SubElement(root, 'Application').text = 'Microsoft Excel' SubElement(root, 'DocSecurity').text = '0' SubElement(root, 'ScaleCrop').text = 'false' SubElement(root, 'Company') SubElement(root, 'LinksUpToDate').text = 'false' SubElement(root, 'SharedDoc').text = 'false' SubElement(root, 'HyperlinksChanged').text = 'false' SubElement(root, 'AppVersion').text = '12.0000' # heading pairs part heading_pairs = SubElement(root, 'HeadingPairs') vector = SubElement(heading_pairs, 'vt:vector', { 'size': '2', 'baseType': 'variant' }) variant = SubElement(vector, 'vt:variant') SubElement(variant, 'vt:lpstr').text = 'Worksheets' variant = SubElement(vector, 'vt:variant') SubElement(variant, 'vt:i4').text = '%d' % worksheets_count # title of parts title_of_parts = SubElement(root, 'TitlesOfParts') vector = SubElement(title_of_parts, 'vt:vector', { 'size': '%d' % worksheets_count, 'baseType': 'lpstr' }) for ws in workbook.worksheets: SubElement(vector, 'vt:lpstr').text = '%s' % ws.title return get_document_content(root)
def write_content_types(workbook): """Write the content-types xml.""" root = Element('Types', {'xmlns': 'http://schemas.openxmlformats.org/package/2006/content-types'}) SubElement(root, 'Override', {'PartName': '/' + ARC_THEME, 'ContentType': 'application/vnd.openxmlformats-officedocument.theme+xml'}) SubElement(root, 'Override', {'PartName': '/' + ARC_STYLE, 'ContentType': 'application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml'}) SubElement(root, 'Default', {'Extension': 'rels', 'ContentType': 'application/vnd.openxmlformats-package.relationships+xml'}) SubElement(root, 'Default', {'Extension': 'xml', 'ContentType': 'application/xml'}) SubElement(root, 'Default', {'Extension': 'png', 'ContentType': 'image/png'}) SubElement(root, 'Override', {'PartName': '/' + ARC_WORKBOOK, 'ContentType': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml'}) SubElement(root, 'Override', {'PartName': '/' + ARC_APP, 'ContentType': 'application/vnd.openxmlformats-officedocument.extended-properties+xml'}) SubElement(root, 'Override', {'PartName': '/' + ARC_CORE, 'ContentType': 'application/vnd.openxmlformats-package.core-properties+xml'}) SubElement(root, 'Override', {'PartName': '/' + ARC_SHARED_STRINGS, 'ContentType': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml'}) drawing_id = 1 chart_id = 1 for sheet_id, sheet in enumerate(workbook.worksheets): SubElement(root, 'Override', {'PartName': '/xl/worksheets/sheet%d.xml' % (sheet_id + 1), 'ContentType': 'application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml'}) if sheet._charts or sheet._images: SubElement(root, 'Override', {'PartName' : '/xl/drawings/drawing%d.xml' % drawing_id, 'ContentType' : 'application/vnd.openxmlformats-officedocument.drawing+xml'}) drawing_id += 1 for chart in sheet._charts: SubElement(root, 'Override', {'PartName' : '/xl/charts/chart%d.xml' % chart_id, 'ContentType' : 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml'}) chart_id += 1 if chart._shapes: SubElement(root, 'Override', {'PartName' : '/xl/drawings/drawing%d.xml' % drawing_id, 'ContentType' : 'application/vnd.openxmlformats-officedocument.drawingml.chartshapes+xml'}) drawing_id += 1 return get_document_content(root)
def write_workbook(workbook): """Write the core workbook xml.""" root = Element( 'workbook', { 'xmlns': 'http://schemas.openxmlformats.org/spreadsheetml/2006/main', 'xml:space': 'preserve', 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships' }) SubElement( root, 'fileVersion', { 'appName': 'xl', 'lastEdited': '4', 'lowestEdited': '4', 'rupBuild': '4505' }) SubElement(root, 'workbookPr', { 'defaultThemeVersion': '124226', 'codeName': 'ThisWorkbook' }) book_views = SubElement(root, 'bookViews') SubElement( book_views, 'workbookView', { 'activeTab': '%d' % workbook.get_index(workbook.get_active_sheet()), 'autoFilterDateGrouping': '1', 'firstSheet': '0', 'minimized': '0', 'showHorizontalScroll': '1', 'showSheetTabs': '1', 'showVerticalScroll': '1', 'tabRatio': '600', 'visibility': 'visible' }) # worksheets sheets = SubElement(root, 'sheets') for i, sheet in enumerate(workbook.worksheets): sheet_node = SubElement( sheets, 'sheet', { 'name': sheet.title, 'sheetId': '%d' % (i + 1), 'r:id': 'rId%d' % (i + 1) }) if not sheet.sheet_state == sheet.SHEETSTATE_VISIBLE: sheet_node.set('state', sheet.sheet_state) # Defined names defined_names = SubElement(root, 'definedNames') # named ranges for named_range in workbook.get_named_ranges(): name = SubElement(defined_names, 'definedName', {'name': named_range.name}) if named_range.scope: name.set('localSheetId', '%s' % workbook.get_index(named_range.scope)) if isinstance(named_range, NamedRange): # as there can be many cells in one range, generate the list of ranges dest_cells = [] for worksheet, range_name in named_range.destinations: dest_cells.append("'%s'!%s" % (worksheet.title.replace( "'", "''"), absolute_coordinate(range_name))) # finally write the cells list name.text = ','.join(dest_cells) else: assert isinstance(named_range, NamedRangeContainingValue) name.text = named_range.value # autoFilter for i, sheet in enumerate(workbook.worksheets): #continue auto_filter = sheet.auto_filter if not auto_filter: continue name = SubElement( defined_names, 'definedName', dict(name='_xlnm._FilterDatabase', localSheetId=str(i), hidden='1')) name.text = "'%s'!%s" % (sheet.title.replace( "'", "''"), absolute_coordinate(auto_filter)) SubElement(root, 'calcPr', { 'calcId': '124519', 'calcMode': 'auto', 'fullCalcOnLoad': '1' }) return get_document_content(root)
def write_content_types(workbook): """Write the content-types xml.""" root = Element('Types', { 'xmlns': 'http://schemas.openxmlformats.org/package/2006/content-types' }) SubElement( root, 'Override', { 'PartName': '/' + ARC_THEME, 'ContentType': 'application/vnd.openxmlformats-officedocument.theme+xml' }) SubElement( root, 'Override', { 'PartName': '/' + ARC_STYLE, 'ContentType': 'application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml' }) SubElement( root, 'Default', { 'Extension': 'rels', 'ContentType': 'application/vnd.openxmlformats-package.relationships+xml' }) SubElement(root, 'Default', { 'Extension': 'xml', 'ContentType': 'application/xml' }) SubElement(root, 'Default', { 'Extension': 'png', 'ContentType': 'image/png' }) SubElement( root, 'Override', { 'PartName': '/' + ARC_WORKBOOK, 'ContentType': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml' }) SubElement( root, 'Override', { 'PartName': '/' + ARC_APP, 'ContentType': 'application/vnd.openxmlformats-officedocument.extended-properties+xml' }) SubElement( root, 'Override', { 'PartName': '/' + ARC_CORE, 'ContentType': 'application/vnd.openxmlformats-package.core-properties+xml' }) SubElement( root, 'Override', { 'PartName': '/' + ARC_SHARED_STRINGS, 'ContentType': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml' }) drawing_id = 1 chart_id = 1 for sheet_id, sheet in enumerate(workbook.worksheets): SubElement( root, 'Override', { 'PartName': '/xl/worksheets/sheet%d.xml' % (sheet_id + 1), 'ContentType': 'application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml' }) if sheet._charts or sheet._images: SubElement( root, 'Override', { 'PartName': '/xl/drawings/drawing%d.xml' % drawing_id, 'ContentType': 'application/vnd.openxmlformats-officedocument.drawing+xml' }) drawing_id += 1 for chart in sheet._charts: SubElement( root, 'Override', { 'PartName': '/xl/charts/chart%d.xml' % chart_id, 'ContentType': 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml' }) chart_id += 1 if chart._shapes: SubElement( root, 'Override', { 'PartName': '/xl/drawings/drawing%d.xml' % drawing_id, 'ContentType': 'application/vnd.openxmlformats-officedocument.drawingml.chartshapes+xml' }) drawing_id += 1 return get_document_content(root)
def write_theme(): """Write the theme xml.""" xml_node = fromstring( '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' '<a:theme xmlns:a="http://schemas.openxmlformats.org/' 'drawingml/2006/main" name="Office Theme">' '<a:themeElements>' '<a:clrScheme name="Office">' '<a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1>' '<a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1>' '<a:dk2><a:srgbClr val="1F497D"/></a:dk2>' '<a:lt2><a:srgbClr val="EEECE1"/></a:lt2>' '<a:accent1><a:srgbClr val="4F81BD"/></a:accent1>' '<a:accent2><a:srgbClr val="C0504D"/></a:accent2>' '<a:accent3><a:srgbClr val="9BBB59"/></a:accent3>' '<a:accent4><a:srgbClr val="8064A2"/></a:accent4>' '<a:accent5><a:srgbClr val="4BACC6"/></a:accent5>' '<a:accent6><a:srgbClr val="F79646"/></a:accent6>' '<a:hlink><a:srgbClr val="0000FF"/></a:hlink>' '<a:folHlink><a:srgbClr val="800080"/></a:folHlink>' '</a:clrScheme>' '<a:fontScheme name="Office">' '<a:majorFont>' '<a:latin typeface="Cambria"/>' '<a:ea typeface=""/>' '<a:cs typeface=""/>' '<a:font script="Jpan" typeface="MS Pゴシック"/>' '<a:font script="Hang" typeface="맑은 고딕"/>' '<a:font script="Hans" typeface="宋体"/>' '<a:font script="Hant" typeface="新細明體"/>' '<a:font script="Arab" typeface="Times New Roman"/>' '<a:font script="Hebr" typeface="Times New Roman"/>' '<a:font script="Thai" typeface="Tahoma"/>' '<a:font script="Ethi" typeface="Nyala"/>' '<a:font script="Beng" typeface="Vrinda"/>' '<a:font script="Gujr" typeface="Shruti"/>' '<a:font script="Khmr" typeface="MoolBoran"/>' '<a:font script="Knda" typeface="Tunga"/>' '<a:font script="Guru" typeface="Raavi"/>' '<a:font script="Cans" typeface="Euphemia"/>' '<a:font script="Cher" typeface="Plantagenet Cherokee"/>' '<a:font script="Yiii" typeface="Microsoft Yi Baiti"/>' '<a:font script="Tibt" typeface="Microsoft Himalaya"/>' '<a:font script="Thaa" typeface="MV Boli"/>' '<a:font script="Deva" typeface="Mangal"/>' '<a:font script="Telu" typeface="Gautami"/>' '<a:font script="Taml" typeface="Latha"/>' '<a:font script="Syrc" typeface="Estrangelo Edessa"/>' '<a:font script="Orya" typeface="Kalinga"/>' '<a:font script="Mlym" typeface="Kartika"/>' '<a:font script="Laoo" typeface="DokChampa"/>' '<a:font script="Sinh" typeface="Iskoola Pota"/>' '<a:font script="Mong" typeface="Mongolian Baiti"/>' '<a:font script="Viet" typeface="Times New Roman"/>' '<a:font script="Uigh" typeface="Microsoft Uighur"/>' '</a:majorFont>' '<a:minorFont>' '<a:latin typeface="Calibri"/>' '<a:ea typeface=""/>' '<a:cs typeface=""/>' '<a:font script="Jpan" typeface="MS Pゴシック"/>' '<a:font script="Hang" typeface="맑은 고딕"/>' '<a:font script="Hans" typeface="宋体"/>' '<a:font script="Hant" typeface="新細明體"/>' '<a:font script="Arab" typeface="Arial"/>' '<a:font script="Hebr" typeface="Arial"/>' '<a:font script="Thai" typeface="Tahoma"/>' '<a:font script="Ethi" typeface="Nyala"/>' '<a:font script="Beng" typeface="Vrinda"/>' '<a:font script="Gujr" typeface="Shruti"/>' '<a:font script="Khmr" typeface="DaunPenh"/>' '<a:font script="Knda" typeface="Tunga"/>' '<a:font script="Guru" typeface="Raavi"/>' '<a:font script="Cans" typeface="Euphemia"/>' '<a:font script="Cher" typeface="Plantagenet Cherokee"/>' '<a:font script="Yiii" typeface="Microsoft Yi Baiti"/>' '<a:font script="Tibt" typeface="Microsoft Himalaya"/>' '<a:font script="Thaa" typeface="MV Boli"/>' '<a:font script="Deva" typeface="Mangal"/>' '<a:font script="Telu" typeface="Gautami"/>' '<a:font script="Taml" typeface="Latha"/>' '<a:font script="Syrc" typeface="Estrangelo Edessa"/>' '<a:font script="Orya" typeface="Kalinga"/>' '<a:font script="Mlym" typeface="Kartika"/>' '<a:font script="Laoo" typeface="DokChampa"/>' '<a:font script="Sinh" typeface="Iskoola Pota"/>' '<a:font script="Mong" typeface="Mongolian Baiti"/>' '<a:font script="Viet" typeface="Arial"/>' '<a:font script="Uigh" typeface="Microsoft Uighur"/>' '</a:minorFont>' '</a:fontScheme>' '<a:fmtScheme name="Office">' '<a:fillStyleLst>' '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' '<a:gradFill rotWithShape="1"><a:gsLst>' '<a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="50000"/>' '<a:satMod val="300000"/></a:schemeClr></a:gs>' '<a:gs pos="35000"><a:schemeClr val="phClr"><a:tint val="37000"/>' '<a:satMod val="300000"/></a:schemeClr></a:gs>' '<a:gs pos="100000"><a:schemeClr val="phClr"><a:tint val="15000"/>' '<a:satMod val="350000"/></a:schemeClr></a:gs></a:gsLst>' '<a:lin ang="16200000" scaled="1"/></a:gradFill>' '<a:gradFill rotWithShape="1"><a:gsLst>' '<a:gs pos="0"><a:schemeClr val="phClr"><a:shade val="51000"/>' '<a:satMod val="130000"/></a:schemeClr></a:gs>' '<a:gs pos="80000"><a:schemeClr val="phClr"><a:shade val="93000"/>' '<a:satMod val="130000"/></a:schemeClr></a:gs>' '<a:gs pos="100000"><a:schemeClr val="phClr">' '<a:shade val="94000"/>' '<a:satMod val="135000"/></a:schemeClr></a:gs></a:gsLst>' '<a:lin ang="16200000" scaled="0"/></a:gradFill></a:fillStyleLst>' '<a:lnStyleLst>' '<a:ln w="9525" cap="flat" cmpd="sng" algn="ctr">' '<a:solidFill><a:schemeClr val="phClr"><a:shade val="95000"/>' '<a:satMod val="105000"/></a:schemeClr></a:solidFill>' '<a:prstDash val="solid"/></a:ln>' '<a:ln w="25400" cap="flat" cmpd="sng" algn="ctr"><a:solidFill>' '<a:schemeClr val="phClr"/></a:solidFill>' '<a:prstDash val="solid"/></a:ln>' '<a:ln w="38100" cap="flat" cmpd="sng" algn="ctr"><a:solidFill>' '<a:schemeClr val="phClr"/></a:solidFill>' '<a:prstDash val="solid"/></a:ln></a:lnStyleLst>' '<a:effectStyleLst><a:effectStyle><a:effectLst>' '<a:outerShdw blurRad="40000" dist="20000" dir="5400000" ' 'rotWithShape="0"><a:srgbClr val="000000">' '<a:alpha val="38000"/></a:srgbClr></a:outerShdw></a:effectLst>' '</a:effectStyle><a:effectStyle><a:effectLst>' '<a:outerShdw blurRad="40000" dist="23000" dir="5400000" ' 'rotWithShape="0"><a:srgbClr val="000000">' '<a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst>' '</a:effectStyle><a:effectStyle><a:effectLst>' '<a:outerShdw blurRad="40000" dist="23000" dir="5400000" ' 'rotWithShape="0"><a:srgbClr val="000000">' '<a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst>' '<a:scene3d><a:camera prst="orthographicFront">' '<a:rot lat="0" lon="0" rev="0"/></a:camera>' '<a:lightRig rig="threePt" dir="t">' '<a:rot lat="0" lon="0" rev="1200000"/></a:lightRig>' '</a:scene3d><a:sp3d><a:bevelT w="63500" h="25400"/>' '</a:sp3d></a:effectStyle></a:effectStyleLst>' '<a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/>' '</a:solidFill><a:gradFill rotWithShape="1"><a:gsLst>' '<a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="40000"/>' '<a:satMod val="350000"/></a:schemeClr></a:gs>' '<a:gs pos="40000"><a:schemeClr val="phClr"><a:tint val="45000"/>' '<a:shade val="99000"/><a:satMod val="350000"/>' '</a:schemeClr></a:gs>' '<a:gs pos="100000"><a:schemeClr val="phClr">' '<a:shade val="20000"/><a:satMod val="255000"/>' '</a:schemeClr></a:gs></a:gsLst>' '<a:path path="circle">' '<a:fillToRect l="50000" t="-80000" r="50000" b="180000"/>' '</a:path>' '</a:gradFill><a:gradFill rotWithShape="1"><a:gsLst>' '<a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="80000"/>' '<a:satMod val="300000"/></a:schemeClr></a:gs>' '<a:gs pos="100000"><a:schemeClr val="phClr">' '<a:shade val="30000"/><a:satMod val="200000"/>' '</a:schemeClr></a:gs></a:gsLst>' '<a:path path="circle">' '<a:fillToRect l="50000" t="50000" r="50000" b="50000"/></a:path>' '</a:gradFill></a:bgFillStyleLst></a:fmtScheme>' '</a:themeElements>' '<a:objectDefaults/><a:extraClrSchemeLst/>' '</a:theme>') return get_document_content(xml_node)
def write(self): """ write drawings for one sheet in one file """ root = Element('xdr:wsDr', {'xmlns:xdr' : "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing", 'xmlns:a' : "http://schemas.openxmlformats.org/drawingml/2006/main"}) for i, chart in enumerate(self._sheet._charts): drawing = chart.drawing # anchor = SubElement(root, 'xdr:twoCellAnchor') # (start_row, start_col), (end_row, end_col) = drawing.coordinates # # anchor coordinates # _from = SubElement(anchor, 'xdr:from') # x = SubElement(_from, 'xdr:col').text = str(start_col) # x = SubElement(_from, 'xdr:colOff').text = '0' # x = SubElement(_from, 'xdr:row').text = str(start_row) # x = SubElement(_from, 'xdr:rowOff').text = '0' # _to = SubElement(anchor, 'xdr:to') # x = SubElement(_to, 'xdr:col').text = str(end_col) # x = SubElement(_to, 'xdr:colOff').text = '0' # x = SubElement(_to, 'xdr:row').text = str(end_row) # x = SubElement(_to, 'xdr:rowOff').text = '0' # we only support absolute anchor atm (TODO: oneCellAnchor, twoCellAnchor x, y, w, h = drawing.get_emu_dimensions() anchor = SubElement(root, 'xdr:absoluteAnchor') SubElement(anchor, 'xdr:pos', {'x':str(x), 'y':str(y)}) SubElement(anchor, 'xdr:ext', {'cx':str(w), 'cy':str(h)}) # graph frame frame = SubElement(anchor, 'xdr:graphicFrame', {'macro':''}) name = SubElement(frame, 'xdr:nvGraphicFramePr') SubElement(name, 'xdr:cNvPr', {'id':'%s' % i, 'name':'Graphique %s' % i}) SubElement(name, 'xdr:cNvGraphicFramePr') frm = SubElement(frame, 'xdr:xfrm') # no transformation SubElement(frm, 'a:off', {'x':'0', 'y':'0'}) SubElement(frm, 'a:ext', {'cx':'0', 'cy':'0'}) graph = SubElement(frame, 'a:graphic') data = SubElement(graph, 'a:graphicData', {'uri':'http://schemas.openxmlformats.org/drawingml/2006/chart'}) SubElement(data, 'c:chart', { 'xmlns:c':'http://schemas.openxmlformats.org/drawingml/2006/chart', 'xmlns:r':'http://schemas.openxmlformats.org/officeDocument/2006/relationships', 'r:id':'rId%s' % (i + 1)}) SubElement(anchor, 'xdr:clientData') for i, img in enumerate(self._sheet._images): drawing = img.drawing x, y, w, h = drawing.get_emu_dimensions() anchor = SubElement(root, 'xdr:absoluteAnchor') SubElement(anchor, 'xdr:pos', {'x':str(x), 'y':str(y)}) SubElement(anchor, 'xdr:ext', {'cx':str(w), 'cy':str(h)}) pic = SubElement(anchor, 'xdr:pic') name = SubElement(pic, 'xdr:nvPicPr') SubElement(name, 'xdr:cNvPr', {'id':'%s' % i, 'name':'Picture %s' % i}) SubElement(SubElement(name, 'xdr:cNvPicPr'), 'a:picLocks', {'noChangeAspect':"1" if img.nochangeaspect else '0','noChangeArrowheads':"1" if img.nochangearrowheads else '0'}) blipfill = SubElement(pic, 'xdr:blipFill') SubElement(blipfill, 'a:blip', { 'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships', 'r:embed': 'rId%s' % (i + 1), 'cstate':'print' }) SubElement(blipfill, 'a:srcRect') SubElement(SubElement(blipfill, 'a:stretch'), 'a:fillRect') sppr = SubElement(pic, 'xdr:spPr', {'bwMode':'auto'}) frm = SubElement(sppr, 'a:xfrm') # no transformation SubElement(frm, 'a:off', {'x':'0', 'y':'0'}) SubElement(frm, 'a:ext', {'cx':'0', 'cy':'0'}) SubElement(SubElement(sppr, 'a:prstGeom', {'prst':'rect'}), 'a:avLst') SubElement(sppr, 'a:noFill') ln = SubElement(sppr, 'a:ln', {'w':'1'}) SubElement(ln, 'a:noFill') SubElement(ln, 'a:miter', {'lim':'800000'}) SubElement(ln, 'a:headEnd') SubElement(ln, 'a:tailEnd', {'type':'none', 'w':'med', 'len':'med'}) SubElement(sppr, 'a:effectLst') SubElement(anchor, 'xdr:clientData') return get_document_content(root)
def write_theme(): """Write the theme xml.""" xml_node = fromstring( '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' '<a:theme xmlns:a="http://schemas.openxmlformats.org/' 'drawingml/2006/main" name="Office Theme">' '<a:themeElements>' '<a:clrScheme name="Office">' '<a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1>' '<a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1>' '<a:dk2><a:srgbClr val="1F497D"/></a:dk2>' '<a:lt2><a:srgbClr val="EEECE1"/></a:lt2>' '<a:accent1><a:srgbClr val="4F81BD"/></a:accent1>' '<a:accent2><a:srgbClr val="C0504D"/></a:accent2>' '<a:accent3><a:srgbClr val="9BBB59"/></a:accent3>' '<a:accent4><a:srgbClr val="8064A2"/></a:accent4>' '<a:accent5><a:srgbClr val="4BACC6"/></a:accent5>' '<a:accent6><a:srgbClr val="F79646"/></a:accent6>' '<a:hlink><a:srgbClr val="0000FF"/></a:hlink>' '<a:folHlink><a:srgbClr val="800080"/></a:folHlink>' '</a:clrScheme>' '<a:fontScheme name="Office">' '<a:majorFont>' '<a:latin typeface="Cambria"/>' '<a:ea typeface=""/>' '<a:cs typeface=""/>' '<a:font script="Jpan" typeface="MS Pゴシック"/>' '<a:font script="Hang" typeface="맑은 고딕"/>' '<a:font script="Hans" typeface="宋体"/>' '<a:font script="Hant" typeface="新細明體"/>' '<a:font script="Arab" typeface="Times New Roman"/>' '<a:font script="Hebr" typeface="Times New Roman"/>' '<a:font script="Thai" typeface="Tahoma"/>' '<a:font script="Ethi" typeface="Nyala"/>' '<a:font script="Beng" typeface="Vrinda"/>' '<a:font script="Gujr" typeface="Shruti"/>' '<a:font script="Khmr" typeface="MoolBoran"/>' '<a:font script="Knda" typeface="Tunga"/>' '<a:font script="Guru" typeface="Raavi"/>' '<a:font script="Cans" typeface="Euphemia"/>' '<a:font script="Cher" typeface="Plantagenet Cherokee"/>' '<a:font script="Yiii" typeface="Microsoft Yi Baiti"/>' '<a:font script="Tibt" typeface="Microsoft Himalaya"/>' '<a:font script="Thaa" typeface="MV Boli"/>' '<a:font script="Deva" typeface="Mangal"/>' '<a:font script="Telu" typeface="Gautami"/>' '<a:font script="Taml" typeface="Latha"/>' '<a:font script="Syrc" typeface="Estrangelo Edessa"/>' '<a:font script="Orya" typeface="Kalinga"/>' '<a:font script="Mlym" typeface="Kartika"/>' '<a:font script="Laoo" typeface="DokChampa"/>' '<a:font script="Sinh" typeface="Iskoola Pota"/>' '<a:font script="Mong" typeface="Mongolian Baiti"/>' '<a:font script="Viet" typeface="Times New Roman"/>' '<a:font script="Uigh" typeface="Microsoft Uighur"/>' '</a:majorFont>' '<a:minorFont>' '<a:latin typeface="Calibri"/>' '<a:ea typeface=""/>' '<a:cs typeface=""/>' '<a:font script="Jpan" typeface="MS Pゴシック"/>' '<a:font script="Hang" typeface="맑은 고딕"/>' '<a:font script="Hans" typeface="宋体"/>' '<a:font script="Hant" typeface="新細明體"/>' '<a:font script="Arab" typeface="Arial"/>' '<a:font script="Hebr" typeface="Arial"/>' '<a:font script="Thai" typeface="Tahoma"/>' '<a:font script="Ethi" typeface="Nyala"/>' '<a:font script="Beng" typeface="Vrinda"/>' '<a:font script="Gujr" typeface="Shruti"/>' '<a:font script="Khmr" typeface="DaunPenh"/>' '<a:font script="Knda" typeface="Tunga"/>' '<a:font script="Guru" typeface="Raavi"/>' '<a:font script="Cans" typeface="Euphemia"/>' '<a:font script="Cher" typeface="Plantagenet Cherokee"/>' '<a:font script="Yiii" typeface="Microsoft Yi Baiti"/>' '<a:font script="Tibt" typeface="Microsoft Himalaya"/>' '<a:font script="Thaa" typeface="MV Boli"/>' '<a:font script="Deva" typeface="Mangal"/>' '<a:font script="Telu" typeface="Gautami"/>' '<a:font script="Taml" typeface="Latha"/>' '<a:font script="Syrc" typeface="Estrangelo Edessa"/>' '<a:font script="Orya" typeface="Kalinga"/>' '<a:font script="Mlym" typeface="Kartika"/>' '<a:font script="Laoo" typeface="DokChampa"/>' '<a:font script="Sinh" typeface="Iskoola Pota"/>' '<a:font script="Mong" typeface="Mongolian Baiti"/>' '<a:font script="Viet" typeface="Arial"/>' '<a:font script="Uigh" typeface="Microsoft Uighur"/>' '</a:minorFont>' '</a:fontScheme>' '<a:fmtScheme name="Office">' '<a:fillStyleLst>' '<a:solidFill><a:schemeClr val="phClr"/></a:solidFill>' '<a:gradFill rotWithShape="1"><a:gsLst>' '<a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="50000"/>' '<a:satMod val="300000"/></a:schemeClr></a:gs>' '<a:gs pos="35000"><a:schemeClr val="phClr"><a:tint val="37000"/>' '<a:satMod val="300000"/></a:schemeClr></a:gs>' '<a:gs pos="100000"><a:schemeClr val="phClr"><a:tint val="15000"/>' '<a:satMod val="350000"/></a:schemeClr></a:gs></a:gsLst>' '<a:lin ang="16200000" scaled="1"/></a:gradFill>' '<a:gradFill rotWithShape="1"><a:gsLst>' '<a:gs pos="0"><a:schemeClr val="phClr"><a:shade val="51000"/>' '<a:satMod val="130000"/></a:schemeClr></a:gs>' '<a:gs pos="80000"><a:schemeClr val="phClr"><a:shade val="93000"/>' '<a:satMod val="130000"/></a:schemeClr></a:gs>' '<a:gs pos="100000"><a:schemeClr val="phClr">' '<a:shade val="94000"/>' '<a:satMod val="135000"/></a:schemeClr></a:gs></a:gsLst>' '<a:lin ang="16200000" scaled="0"/></a:gradFill></a:fillStyleLst>' '<a:lnStyleLst>' '<a:ln w="9525" cap="flat" cmpd="sng" algn="ctr">' '<a:solidFill><a:schemeClr val="phClr"><a:shade val="95000"/>' '<a:satMod val="105000"/></a:schemeClr></a:solidFill>' '<a:prstDash val="solid"/></a:ln>' '<a:ln w="25400" cap="flat" cmpd="sng" algn="ctr"><a:solidFill>' '<a:schemeClr val="phClr"/></a:solidFill>' '<a:prstDash val="solid"/></a:ln>' '<a:ln w="38100" cap="flat" cmpd="sng" algn="ctr"><a:solidFill>' '<a:schemeClr val="phClr"/></a:solidFill>' '<a:prstDash val="solid"/></a:ln></a:lnStyleLst>' '<a:effectStyleLst><a:effectStyle><a:effectLst>' '<a:outerShdw blurRad="40000" dist="20000" dir="5400000" ' 'rotWithShape="0"><a:srgbClr val="000000">' '<a:alpha val="38000"/></a:srgbClr></a:outerShdw></a:effectLst>' '</a:effectStyle><a:effectStyle><a:effectLst>' '<a:outerShdw blurRad="40000" dist="23000" dir="5400000" ' 'rotWithShape="0"><a:srgbClr val="000000">' '<a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst>' '</a:effectStyle><a:effectStyle><a:effectLst>' '<a:outerShdw blurRad="40000" dist="23000" dir="5400000" ' 'rotWithShape="0"><a:srgbClr val="000000">' '<a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst>' '<a:scene3d><a:camera prst="orthographicFront">' '<a:rot lat="0" lon="0" rev="0"/></a:camera>' '<a:lightRig rig="threePt" dir="t">' '<a:rot lat="0" lon="0" rev="1200000"/></a:lightRig>' '</a:scene3d><a:sp3d><a:bevelT w="63500" h="25400"/>' '</a:sp3d></a:effectStyle></a:effectStyleLst>' '<a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/>' '</a:solidFill><a:gradFill rotWithShape="1"><a:gsLst>' '<a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="40000"/>' '<a:satMod val="350000"/></a:schemeClr></a:gs>' '<a:gs pos="40000"><a:schemeClr val="phClr"><a:tint val="45000"/>' '<a:shade val="99000"/><a:satMod val="350000"/>' '</a:schemeClr></a:gs>' '<a:gs pos="100000"><a:schemeClr val="phClr">' '<a:shade val="20000"/><a:satMod val="255000"/>' '</a:schemeClr></a:gs></a:gsLst>' '<a:path path="circle">' '<a:fillToRect l="50000" t="-80000" r="50000" b="180000"/>' '</a:path>' '</a:gradFill><a:gradFill rotWithShape="1"><a:gsLst>' '<a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="80000"/>' '<a:satMod val="300000"/></a:schemeClr></a:gs>' '<a:gs pos="100000"><a:schemeClr val="phClr">' '<a:shade val="30000"/><a:satMod val="200000"/>' '</a:schemeClr></a:gs></a:gsLst>' '<a:path path="circle">' '<a:fillToRect l="50000" t="50000" r="50000" b="50000"/></a:path>' '</a:gradFill></a:bgFillStyleLst></a:fmtScheme>' '</a:themeElements>' '<a:objectDefaults/><a:extraClrSchemeLst/>' '</a:theme>') return get_document_content(xml_node)