在Excel或XlsxWriter文件中,一旦啓用了工作表保護,所有單元默認都被鎖定。
要關閉對單元格的保護,您需要添加關閉lock
屬性的格式。
如果你想有一個空手機解鎖,然後使用None
或空字符串''
作爲價值write()
或用格式使用write_blank()
明確,沿着:
import xlsxwriter
workbook = xlsxwriter.Workbook('test.xlsx')
worksheet = workbook.add_worksheet()
# Create a cell format with lock protection turned off.
unlocked = workbook.add_format({'locked': False})
# Format the columns to make the text more visible.
worksheet.set_column('A:A', 40)
# Turn worksheet protection on.
worksheet.protect()
# Write a locked and an unlocked cell.
worksheet.write('A1', 'Cell B1 is locked. It cannot be edited.')
worksheet.write('A2', 'Cell B2 is unlocked. It can be edited.')
worksheet.write('A3', 'Cell B3 is unlocked. It can be edited.')
worksheet.write('B1', 'Hello') # Locked by default.
worksheet.write('B2', None, unlocked)
worksheet.write_blank('B3', None, unlocked)
workbook.close()
輸出:
非常感謝。 – user3117282