import openpyxl
# Load workbook
wb = openpyxl.load_workbook('workbook.xlsx')
# Initialize formatting styles
no_fill = openpyxl.styles.PatternFill(fill_type=None)
side = openpyxl.styles.Side(border_style=None)
no_border = openpyxl.styles.borders.Border(
left=side,
right=side,
top=side,
bottom=side,
)
# Loop through all cells in all worksheets
for sheet in wb.worksheets:
for row in sheet:
for cell in row:
# Apply colorless and borderless styles
cell.fill = no_fill
cell.border = no_border
# Save workbook
wb.save('workbook_modified.xlsx')
2条答案
按热度按时间ddrv8njm1#
必须创建一个带有参数
fill_type=None
的PatternFill
对象,才能不获取单元格颜色。下面是一段代码片段,用于去除现有excel工作簿中所有单元格的颜色和边框:sg24os4d2#
最简单的解决方案: