简体   繁体   English

如何在没有保护的情况下编写 Excel 工作表?

[英]How do I write Excel sheet without protected it?

I got an Excel sheet, which included some protected cells.我得到了一个 Excel 工作表,其中包含一些受保护的单元格。 I used python program to write some other cells, then the cells were all protected.我用python程序写了一些其他的单元格,然后单元格都被保护了。 I dont want to protect the cells I write.我不想保护我写的单元格。 How should I do?我应该怎么做? Thanks.谢谢。

wb = openpyxl.load_workbook('SecGen.xlsx')
ws = wb['5.1 Frame.Info']
cell = ws['K1']
cell.value = 'Oi, cm'
cell = ws['L1']
cell.value = 'Oj, cm'
for i in range(0, len(ori_e2k.line_se_point_list), 1):
    for j in range(0, len(ori_e2k.line_se_point_list[i]), 1):
        cell = ws.cell(row=i+2, column=j+2)
        cell.value = ori_e2k.line_se_point_list[i][j]
wb.close()

openpyxl default enables protection. openpyxl 默认启用保护。 Just disable it.只需禁用它。

import openpyxl
from openpyxl.styles import Protection, Font
...
...
wb = openpyxl.load_workbook('SecGen.xlsx')
ws = wb['5.1 Frame.Info']
font = Font(name='Calibri')
cell = ws['K1']
cell.value = 'Oi, cm'
cell.protection = Protection(locked=False)
cell.font = Font(name='Calibri')
cell = ws['L1']
cell.value = 'Oj, cm'
cell.protection = Protection(locked=False)
cell.font = Font(name='Calibri')
for i in range(0, len(ori_e2k.line_se_point_list), 1):
    for j in range(0, len(ori_e2k.line_se_point_list[i]), 1):
        cell = ws.cell(row=i+2, column=j+2)
        cell.value = ori_e2k.line_se_point_list[i][j]
        cell.protection = Protection(locked=False)
        cell.font = Font(name='Calibri')
wb.save('SecGen.xlsx')
wb.close()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将多个数据框写入一张 Excel 表格? - How do I write multiple dataframes to one excel sheet? 如何将多个工作表添加到Excel文件而不删除其他工作表,以及如何在第65563行之后的第二个工作表中写入最终文件 - How do I add more than one sheet to Excel file without deleting the other sheets and how to write in 2nd sheet after line 65563 to the end file 如何在Python中已存在的excel工作表中写入工作表? - How do I write to one sheet in an already existing excel sheet in Python? 如何在不先导出数据框的情况下写入 Excel 工作表? - How to write to an Excel sheet without exporting a dataframe first? 如何在现有 Excel 工作表下方写入数据框而不会丢失数据透视表中的 excel 切片器? - How to write dataframe below an existing Excel sheet without losing slicer of excel in pivot table sheet? 如何在python中编写模块私有/受保护的方法? - How do I write module private/protected methods in python? 如何在不删除其余内容的情况下将信息添加到Excel工作表中? - How do I add information to an excel sheet without deleting the rest in Python? 如何使用 pygsheets(带或不带 Pandas)将 Excel 工作表或 CSV 插入 Google 表格? - How do I insert an Excel sheet or CSV into Google Sheets using pygsheets (with or without Pandas)? 如何使用 openpyxl 将 csv 文件写入 Excel 工作表? - How can i write a csv file to an excel sheet using openpyxl? Python xlsxwriter:如何编写引用不同工作表的公式 - Python xlsxwriter: How do I write a formula that references a different sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM