Add HighlightMergeCell.py
This commit is contained in:
parent
bb08c7ae00
commit
3c1fee2907
26
HighlightMergeCell.py
Normal file
26
HighlightMergeCell.py
Normal file
@ -0,0 +1,26 @@
|
||||
from openpyxl import load_workbook
|
||||
from openpyxl.styles import PatternFill
|
||||
|
||||
# Load the workbook
|
||||
file_path = "/Users/z/Downloads/NTL.xlsx" # Change this to your Excel file
|
||||
wb = load_workbook(file_path)
|
||||
ws = wb.active # Select the active sheet (change to a specific sheet if needed)
|
||||
|
||||
# Get all merged cell ranges
|
||||
merged_ranges = ws.merged_cells.ranges
|
||||
|
||||
if merged_ranges:
|
||||
print("Merged Cells Found:")
|
||||
for merged in merged_ranges:
|
||||
print(f"Range: {merged}, Start: ({merged.min_row}, {merged.min_col}), End: ({merged.max_row}, {merged.max_col})")
|
||||
|
||||
# Highlight the top-left cell of each merged range
|
||||
top_left_cell = ws.cell(row=merged.min_row, column=merged.min_col)
|
||||
top_left_cell.fill = PatternFill(start_color="FFFF00", end_color="FFFF00", fill_type="solid")
|
||||
else:
|
||||
print("No merged cells found.")
|
||||
|
||||
# Save the workbook with highlighted merged cells
|
||||
output_file = "highlighted_merged_cells.xlsx"
|
||||
wb.save(output_file)
|
||||
print(f"Highlighted merged cells saved to '{output_file}'.")
|
||||
Loading…
x
Reference in New Issue
Block a user