Skip to content

Commit 6b58a82

Browse files
EricEric
authored andcommitted
remove all blank sheets
1 parent f567681 commit 6b58a82

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

fmut.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
Python functions for the Factorial Mass ERP Univariate Toolbox
99
1010
AUTHOR: Eric Fields
11-
VERSION DATE: 16 June 2017
11+
VERSION DATE: 21 August 2017
1212
"""
1313

1414
import sys
15+
import re
1516
import openpyxl
1617
if int(openpyxl.__version__[0]) < 2:
1718
raise RuntimeError('openpyxl must be version 2.0 or greater.')
@@ -30,11 +31,12 @@ def format_xls(spreadsheet):
3031

3132
wb = openpyxl.load_workbook(spreadsheet)
3233

33-
#Delete Sheet1
34-
if 'Sheet1' in wb.get_sheet_names():
35-
s1 = wb.get_sheet_by_name('Sheet1')
36-
wb.remove_sheet(s1)
37-
wb.active = 0
34+
#Delete blank sheets
35+
for sheet_name in wb.get_sheet_names():
36+
if re.match('Sheet\d', sheet_name):
37+
sheet2remove = wb.get_sheet_by_name(sheet_name)
38+
wb.remove_sheet(sheet2remove)
39+
wb.active = 0
3840

3941
#Define some fill styles for use below
4042
whiteFill = PatternFill(start_color='ffffff', end_color='ffffff', fill_type='solid')

0 commit comments

Comments
 (0)