-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetect_stylings.py
More file actions
69 lines (61 loc) · 2.89 KB
/
detect_stylings.py
File metadata and controls
69 lines (61 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from openpyxl import load_workbook
def check_cells_xlsx(file_path):
wb = load_workbook(file_path)
for sheet_name in wb.sheetnames:
sheet = wb[sheet_name]
empty_cell_count = 0
for row in sheet.iter_rows():
for cell in row:
if cell.value is not None:
print('------------------------\n')
print(f'cell value is {cell.value}')
print(f'cell fill is {cell.fill}')
print(f'cell fill patterntype: {cell.fill.patternType}')
print(f'indexed color: {cell.fill.fgColor.indexed}')
print('-------------------------\n')
elif cell.value is None and empty_cell_count <= 1:
print('--------------------\n')
print(f'EMPTY CELL\n')
print(f'cell fill is {cell.fill}')
print(f'cell fill patterntype: {cell.fill.patternType}')
print(f'indexed color: {cell.fill.fgColor.indexed}')
print('---------------------\n')
empty_cell_count += 1
def check_colored_cells_xlsx(file_path):
wb = load_workbook(file_path)
has_color = False
for sheet_name in wb.sheetnames:
sheet = wb[sheet_name]
for row in sheet.iter_rows():
for cell in row:
# Check if the cell has a fill and the fill is not "none"
if cell.fill and cell.fill.patternType != 'none':
# Get the start color
color = cell.fill.start_color
# Check if the color is not default (e.g., transparent or white)
if color.index not in ['00000000', 'FFFFFFFF']:
print(f"Color {color.index} found in cell {cell.coordinate} of sheet '{sheet_name}'")
has_color = True
return has_color
def check_styles_xlsx(file_path):
workbook = load_workbook(file_path)
has_styling = False
for sheet_name in workbook.sheetnames:
sheet = workbook[sheet_name]
for row in sheet.iter_rows():
for cell in row:
if cell.font.bold or cell.fill.patternType != 'none' or cell.fill.start_color.index != '00000000':
print(f"Styling found in cell {cell.coordinate} of sheet '{sheet_name}'")
has_styling = True
return has_styling
if __name__ == '__main__':
# Example usage:
file_path = "/Users/gibbons/registerdynamics/python_projects/url_tester/test_sheet_colored.xlsx"
'''merged_cells = check_merged_cells_xlsx(file_path)
if merged_cells:
print("Merged cells detected:")
for sheet_name, merged_range in merged_cells:
print(f"- {merged_range} in sheet '{sheet_name}'")
else:
print("No merged cells found.")'''
check_cells_xlsx(file_path)