open xlsx file with password by openpyxl
时间: 2023-10-28 17:04:51 浏览: 163
As an AI language model, I don't have access to files or passwords. However, here is an example code to open an xlsx file with a password using openpyxl:
```python
import openpyxl
# Open the workbook with password
wb = openpyxl.load_workbook('example.xlsx', read_only=True, password='password123')
# Access the sheet
sheet = wb['Sheet1']
# Access the cell value
cell_value = sheet['A1'].value
# Print the cell value
print(cell_value)
# Close the workbook
wb.close()
```
In this example, we use the `load_workbook()` method with the `read_only=True` parameter to open the workbook in read-only mode. We also provide the password as the `password` parameter. Once the workbook is open, we can access the sheet and cell values as usual. Finally, we close the workbook using the `close()` method.
阅读全文
相关推荐


















