【发布时间】:2020-05-26 14:34:32
【问题描述】:
我正在将一些数据导出到 Excel,并且在导出到 Excel 文件时,我已经成功地实现了对列中每个填充单元格的格式设置:
import openpyxl
from openpyxl.utils import get_column_letter
wb = openpyxl.Workbook()
ws = wb.active
# Add rows to worksheet
for row in data:
ws.append(row)
# Disable formatting numbers in columns from column `D` onwards
# Need to do this manually for every cell
for col in range(3, ws.max_column+1):
for cell in ws[get_column_letter(col)]:
cell.number_format = '@'
# Export data to Excel file...
但这只会格式化每列中填充的单元格。此列中的其他单元格仍然具有General 格式。
如何将此列中的所有空单元格设置为@,以便在此导出的 Excel 文件中编辑这些列中的单元格的任何人在插入电话号码作为实际数字时不会遇到问题。
【问题讨论】:
标签: python django excel openpyxl