Anonymous avatar Anonymous committed 65aba5c

Cleaned whitespace.

Comments (0)

Files changed (8)

openpyxl/reader/excel.py

         raise InvalidFileException(unicode(e))
 
     if not keep_vba:
-	    archive.close()
+        archive.close()
     return wb
 
 def _load_workbook(wb, archive, filename, use_iterators, keep_vba):
     # If are going to preserve the vba then attach the archive to the
     # workbook so that is available for the save.
     if keep_vba:
-	    wb.vba_archive = archive
+        wb.vba_archive = archive
 
     # get workbook-level information
     try:

openpyxl/reader/style.py

                         if bgColor.get('tint') is not None:
                             newFill.end_color.index = 'theme:%s:%s' % (bgColor.get('theme'), bgColor.get('tint'))
                         else:
-                            newFill.end_color.index = 'theme:%s:' % bgColor.get('theme') # prefix color with theme
+                            newFill.end_color.index = 'theme:%s:' % bgColor.get('theme')  # prefix color with theme
                     elif bgColor.get('rgb'):
                         newFill.end_color.index = bgColor.get('rgb')
                 count += 1

openpyxl/tests/test_named_range.py

 
     eq_(10, cell.value)
 
+
 def test_print_titles():
+    wb = Workbook()
+    ws1 = wb.create_sheet()
+    ws2 = wb.create_sheet()
+    ws1.add_print_title(2)
+    ws2.add_print_title(3, rows_or_cols='cols')
 
-	wb = Workbook()
-	ws1 = wb.create_sheet()
-	ws2 = wb.create_sheet()
-	ws1.add_print_title(2)
-	ws2.add_print_title(3, rows_or_cols='cols')
+    def mystr(nr):
+        return ','.join(['%s!%s' % (sheet.title, name) for sheet, name in nr.destinations])
 
-	def mystr(nr):
-		return ','.join(['%s!%s' % (sheet.title, name) for sheet, name in nr.destinations])
+    actual_named_ranges = set([(nr.name, nr.scope, mystr(nr)) for nr in wb.get_named_ranges()])
+    expected_named_ranges = set([('_xlnm.Print_Titles', ws1, 'Sheet1!$1:$2'),
+                                 ('_xlnm.Print_Titles', ws2, 'Sheet2!$A:$C')])
+    assert(actual_named_ranges == expected_named_ranges)
 
-	actual_named_ranges = set([(nr.name, nr.scope, mystr(nr)) for nr in wb.get_named_ranges()])
-	expected_named_ranges = set([('_xlnm.Print_Titles', ws1, 'Sheet1!$1:$2'), ('_xlnm.Print_Titles', ws2, 'Sheet2!$A:$C')])
-	assert(actual_named_ranges == expected_named_ranges)
 
 class TestNameRefersToValue(object):
     def setUp(self):
         self.wb = load_workbook(os.path.join(DATADIR, 'genuine', 'NameWithValueBug.xlsx'))
-	print self.wb.vba_archive
         self.ws = self.wb.get_sheet_by_name("Sheet1")
         make_tmpdir()
 

openpyxl/tests/test_vba.py

 
 def test_save_without_vba():
     path = os.path.join(DATADIR, 'reader', 'vba-test.xlsm')
-    vbFiles = {'xl/activeX/activeX2.xml', 'xl/drawings/_rels/vmlDrawing1.vml.rels',
-               'xl/activeX/_rels/activeX1.xml.rels', 'xl/drawings/vmlDrawing1.vml', 'xl/activeX/activeX1.bin',
-               'xl/media/image1.emf', 'xl/vbaProject.bin', 'xl/activeX/_rels/activeX2.xml.rels',
-               'xl/worksheets/_rels/sheet1.xml.rels', 'customUI/customUI.xml', 'xl/media/image2.emf',
-               'xl/ctrlProps/ctrlProp1.xml', 'xl/activeX/activeX2.bin', 'xl/activeX/activeX1.xml',
-               'xl/ctrlProps/ctrlProp2.xml', 'xl/drawings/drawing1.xml'}
+    vbFiles = set(['xl/activeX/activeX2.xml', 'xl/drawings/_rels/vmlDrawing1.vml.rels',
+                   'xl/activeX/_rels/activeX1.xml.rels', 'xl/drawings/vmlDrawing1.vml', 'xl/activeX/activeX1.bin',
+                   'xl/media/image1.emf', 'xl/vbaProject.bin', 'xl/activeX/_rels/activeX2.xml.rels',
+                   'xl/worksheets/_rels/sheet1.xml.rels', 'customUI/customUI.xml', 'xl/media/image2.emf',
+                   'xl/ctrlProps/ctrlProp1.xml', 'xl/activeX/activeX2.bin', 'xl/activeX/activeX1.xml',
+                   'xl/ctrlProps/ctrlProp2.xml', 'xl/drawings/drawing1.xml'])
 
     wb = load_workbook(path, keep_vba=False)
     buf = save_virtual_workbook(wb)

openpyxl/worksheet.py

         self._freeze_panes = None
         self.paper_size = None
         self.orientation = None
-	self.xml_source = None
+        self.xml_source = None
 
     def __repr__(self):
         return self.repr_format % self.title
                            "Get or set frozen panes")
 
     def add_print_title(self, n, rows_or_cols='rows'):
-        """Print Titles are rows or columns that are repeated on each printed sheet.
-        This adds n rows or columns at the top or left of the sheet"""
-    	if rows_or_cols == 'cols':
-		r = '$A:$%s' % get_column_letter(n)
-	else:
-		r = '$1:$%d' % n
-	self.parent.create_named_range('_xlnm.Print_Titles', self, r, self)
+        """ Print Titles are rows or columns that are repeated on each printed sheet.
+        This adds n rows or columns at the top or left of the sheet
+        """
+        if rows_or_cols == 'cols':
+            r = '$A:$%s' % get_column_letter(n)
+        else:
+            r = '$1:$%d' % n
 
+        self.parent.create_named_range('_xlnm.Print_Titles', self, r, self)
 
     def cell(self, coordinate=None, row=None, column=None):
         """Returns a cell object based on the given coordinates.

openpyxl/writer/excel.py

         shared_string_table = self._write_string_table(archive)
         
         archive.writestr(ARC_CONTENT_TYPES, write_content_types(self.workbook))
-	if not self.workbook.vba_archive:
-		archive.writestr(ARC_ROOT_RELS, write_root_rels(self.workbook))
+        if not self.workbook.vba_archive:
+            archive.writestr(ARC_ROOT_RELS, write_root_rels(self.workbook))
         archive.writestr(ARC_WORKBOOK_RELS, write_workbook_rels(self.workbook))
         archive.writestr(ARC_APP, write_properties_app(self.workbook))
-        archive.writestr(ARC_CORE,
-                write_properties_core(self.workbook.properties))
+        archive.writestr(ARC_CORE, write_properties_core(self.workbook.properties))
         if self.workbook.loaded_theme:
             archive.writestr(ARC_THEME, self.workbook.loaded_theme)
         else:
         archive.writestr(ARC_STYLE, self.style_writer.write_table())
         archive.writestr(ARC_WORKBOOK, write_workbook(self.workbook))
 
-	if self.workbook.vba_archive:
-		vba_archive = self.workbook.vba_archive
-		for name in vba_archive.namelist():
-			for s in ARC_VBA:
-				if name.startswith(s):
-					archive.writestr(name, vba_archive.read(name))
-					break
+        if self.workbook.vba_archive:
+            vba_archive = self.workbook.vba_archive
+            for name in vba_archive.namelist():
+                for s in ARC_VBA:
+                    if name.startswith(s):
+                        archive.writestr(name, vba_archive.read(name))
+                        break
 
         self._write_worksheets(archive, shared_string_table, self.style_writer)
 

openpyxl/writer/workbook.py

     """Write the content-types xml."""
     seen = set()
     if workbook.vba_archive:
-    	root = fromstring(workbook.vba_archive.read(ARC_CONTENT_TYPES))
-	register_namespace('', 'http://schemas.openxmlformats.org/package/2006/content-types')
-	for elem in root.findall('{http://schemas.openxmlformats.org/package/2006/content-types}Override'):
-	    seen.add(elem.attrib['PartName'])
+        root = fromstring(workbook.vba_archive.read(ARC_CONTENT_TYPES))
+        register_namespace('', 'http://schemas.openxmlformats.org/package/2006/content-types')
+        for elem in root.findall('{http://schemas.openxmlformats.org/package/2006/content-types}Override'):
+            seen.add(elem.attrib['PartName'])
     else:
-	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'})
+        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'})
+        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):
-	part_name = '/xl/worksheets/sheet%d.xml' % (sheet_id + 1)
-	if part_name not in seen:
-		SubElement(root, 'Override', {'PartName': part_name,
-		'ContentType': 'application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml'})
+        part_name = '/xl/worksheets/sheet%d.xml' % (sheet_id + 1)
+        if part_name not in seen:
+            SubElement(root, 'Override',
+                       {'PartName': part_name,
+                        'ContentType': 'application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml'})
         if sheet._charts or sheet._images:
-	    part_name = '/xl/drawings/drawing%d.xml' % drawing_id
-	    if part_name not in seen:
-		    SubElement(root, 'Override', {'PartName' : part_name,
-			'ContentType' : 'application/vnd.openxmlformats-officedocument.drawing+xml'})
+            part_name = '/xl/drawings/drawing%d.xml' % drawing_id
+            if part_name not in seen:
+                SubElement(root, 'Override',
+                           {'PartName': part_name,
+                            'ContentType': 'application/vnd.openxmlformats-officedocument.drawing+xml'})
             drawing_id += 1
 
             for chart in sheet._charts:
-		part_name = '/xl/charts/chart%d.xml' % chart_id
-		if part_name not in seen:
-			SubElement(root, 'Override', {'PartName' : part_name,
-			    'ContentType' : 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml'})
-                chart_id += 1
-                if chart._shapes:
-		    part_name = '/xl/drawings/drawing%d.xml' % drawing_id
-		    if part_name not in seen:
-			    SubElement(root, 'Override', {'PartName' : part_name,
-				'ContentType' : 'application/vnd.openxmlformats-officedocument.drawingml.chartshapes+xml'})
-                    drawing_id += 1
+                part_name = '/xl/charts/chart%d.xml' % chart_id
+
+                if part_name not in seen:
+                    SubElement(root, 'Override',
+                               {'PartName': part_name,
+                                'ContentType': 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml'})
+                    chart_id += 1
+                    if chart._shapes:
+                        part_name = '/xl/drawings/drawing%d.xml' % drawing_id
+                        if part_name not in seen:
+                            SubElement(root, 'Override',
+                                       {'PartName': part_name,
+                                        'ContentType': 'application/vnd.openxmlformats-officedocument.drawingml.chartshapes+xml'})
+                        drawing_id += 1
 
     return get_document_content(root)
 
             {'Id': 'rId%d' % (rid + 2), 'Target': 'theme/theme1.xml',
             'Type': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme'})
     if workbook.vba_archive:
-	    SubElement(root, 'Relationship',
-		    {'Id': 'rId%d' % (rid + 3), 'Target': 'vbaProject.bin',
-		    'Type': 'http://schemas.microsoft.com/office/2006/relationships/vbaProject'})
+        SubElement(root, 'Relationship',
+                   {'Id': 'rId%d' % (rid + 3), 'Target': 'vbaProject.bin',
+                    'Type': 'http://schemas.microsoft.com/office/2006/relationships/vbaProject'})
     return get_document_content(root)

openpyxl/writer/worksheet.py

     return column_index_from_string(cell.column)
 
 def write_etree(doc, element):
-	start_tag(doc, element.tag, element)
-	for e in element.getchildren():
-		write_etree(doc, e)
-	end_tag(doc, element.tag)
+    start_tag(doc, element.tag, element)
+    for e in element.getchildren():
+        write_etree(doc, e)
+    end_tag(doc, element.tag)
 	
 def write_worksheet(worksheet, string_table, style_table):
     """Write a worksheet to an xml file."""
     if worksheet.xml_source:
-    	vba_root = fromstring(worksheet.xml_source)
-	register_namespace("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships")
-	register_namespace("", "http://schemas.openxmlformats.org/spreadsheetml/2006/main")
+        vba_root = fromstring(worksheet.xml_source)
+        register_namespace("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships")
+        register_namespace("", "http://schemas.openxmlformats.org/spreadsheetml/2006/main")
     else:
-    	vba_root = None
+        vba_root = None
     xml_file = StringIO()
     doc = XMLGenerator(out=xml_file, encoding='utf-8')
     start_tag(doc, 'worksheet',
             'xmlns': 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
             'xmlns:r': 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'})
     if vba_root is not None:
-    	codename = vba_root.find('{http://schemas.openxmlformats.org/spreadsheetml/2006/main}sheetPr').get('codeName', worksheet.title)
+        codename = vba_root.find('{http://schemas.openxmlformats.org/spreadsheetml/2006/main}sheetPr').get('codeName', worksheet.title)
         start_tag(doc, 'sheetPr', {"codeName": codename})
     else:
         start_tag(doc, 'sheetPr')
     # been loaded with keep-vba true and we need to extract any control
     # elements.
     if vba_root is not None:
-	for t in ('{http://schemas.openxmlformats.org/spreadsheetml/2006/main}legacyDrawing',
-		  '{http://schemas.openxmlformats.org/spreadsheetml/2006/main}controls'):
-	    for elem in vba_root.findall(t):
-		xml_file.write(re.sub(r' xmlns[^ >]*', '', tostring(elem)))
+        for t in ('{http://schemas.openxmlformats.org/spreadsheetml/2006/main}legacyDrawing',
+                  '{http://schemas.openxmlformats.org/spreadsheetml/2006/main}controls'):
+            for elem in vba_root.findall(t):
+                xml_file.write(re.sub(r' xmlns[^ >]*', '', tostring(elem)))
 
     end_tag(doc, 'worksheet')
     doc.endDocument()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.