使用python-xlswriter或bash打开受密码保护的ods文件 [英] Open password-protected ods file with python-xlswriter or bash

查看:87
本文介绍了使用python-xlswriter或bash打开受密码保护的ods文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个代码来通过python3(首选)或bash打开电子表格,并给他们提供密码,然后他们才能读取它们.

I need a code to open spreadsheet via python3 (preferred) or bash that I give them password and they read them.

我尝试使用python-module"xlswriter"

I try by python-module "xlswriter"

我用这种方法保护xlsx:

I protect xlsx with this method:

import xlsxwriter
workbook = xlsxwriter.Workbook('for-test-password.xlsx')
worksheet = workbook.add_worksheet()
content = (
    ['Gas', 10],
    ['Gasoline',   20],
    ['Potro',  30],
    ['Other',40],
)

row = 0
col = 0
for item, cost in (content):
    worksheet.write(row, col,     item)
    worksheet.write(row, col + 1, cost)
    row += 1
worksheet.protect('Passwd')

或尝试在bash脚本中使用此代码

or try with this code in bash-script

LibreOffice -p password -f xlsx for-test-password.xlsx

但这不会返回电子表格中的数据.

But this does not return data in spreadsheet.

推荐答案

我用这种方法保护xlsx:

I protect xlsx with this method:

worksheet.protect('Passwd')

这不是保护工作簿的密码.它正在保护工作表.XlsxWriter不支持密码保护工作簿/xlsx文件.

This is not password protecting the workbook. It is protecting the worksheet. There is no support in XlsxWriter for password protecting a workbook/xlsx file.

关于Protect()的XlsxWriter文档:

注意

Excel中的工作表级别密码提供了非常弱的保护.它们不加密您的数据,非常容易停用.XlsxWriter不支持完全工作簿加密,因为它需要完全不同的文件格式,并且要花几个月的时间才能实现.

Worksheet level passwords in Excel offer very weak protection. They do not encrypt your data and are very easy to deactivate. Full workbook encryption is not supported by XlsxWriter since it requires a completely different file format and would take several man months to implement.

这篇关于使用python-xlswriter或bash打开受密码保护的ods文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆