简体   繁体   English

在 Linux 上的 Python 中使用受密码保护的 Excel 表格

[英]Working with Password Protected Excel Sheets in Python on Linux

The problem is pretty simple.问题很简单。 Every week I receive a bunch of password protected excel files.每周我都会收到一堆受密码保护的 excel 文件。 I have to parse through them and write certain parts to a new file using Python.我必须解析它们并使用 Python 将某些部分写入新文件。 I am given the password for the files.我得到了文件的密码。

This was simple to handle when this was being done on Windows and I could just import win32com and use client.Dispatch.当这在 Windows 上完成时,这很容易处理,我可以只导入 win32com 并使用 client.Dispatch。 But we are now moving all our code to linux so no more win32com for me.但是我们现在正在将所有代码移至 linux,因此对我而言不再使用 win32com。

Is there a way to open and read data from a password protected excel sheet in python on linux?有没有办法在linux上的python中打开和读取受密码保护的excel表中的数据?

I have been searching for simple way to open a password protected excel file but no luck.我一直在寻找打开受密码保护的 excel 文件的简单方法,但没有成功。 I also tried finding a way to just remove the password protection so I can use xlrd like I would on a file that is not password protected but no luck going that route either.我还尝试找到一种方法来删除密码保护,这样我就可以像在不受密码保护的文件上一样使用 xlrd,但也没有走这条路的运气。

Any help would be most appreciated.非常感激任何的帮助。

with libreoffice and unoconv使用libreofficeunoconv

unoconv --password='p4ssw0rd' -f csv  protectedFile.xls

and then parse the csv file.然后解析csv文件。 Or export to another xls if you need the formatting or want to torture yourself如果您需要格式化或想折磨自己,或者导出到另一个 xls

NB Edited after accepted. NB 接受后编辑。 ( --password is the correct switch, not -p , as noted by @enharmonic) --password是正确的开关,而不是-p ,如@enharmonic 所述)

I've recently had an easier time using xlsxunpass我最近更轻松地使用xlsxunpass

java -jar ./xlsxunpass.jar protected.xlsx unprotected.xlsx 'p4ssw0rd'

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM