简体   繁体   English

是否可以在没有python中的任何库的情况下从xlsx文件中读取信息?

[英]Is it possible to read information from an xlsx file without any libraries in python?

I am forced to ask this question我被迫问这个问题

My mentor has given me a task to extract data from files with pure python, there were some txt file which were easy but there is a file with xlsx extension and I can't find any where if it is possible to extract the data from it with pure python (I have been searching for more than 3 weeks now).我的导师给了我一个任务,用纯 python 从文件中提取数据,有一些txt文件很容易,但有一个扩展名为xlsx的文件,如果可以从中提取数据,我找不到任何地方使用纯 python(我已经搜索了 3 个多星期了)。

Please if it is not possible tell me so that I can show this to her with confidence because my mentor keeps insisting that it is possible and I should do it with pure python but she refuses to give me any clues and tips.如果不可能,请告诉我,以便我可以自信地向她展示这一点,因为我的导师一直坚持认为这是可能的,我应该用纯 python 来做,但她拒绝给我任何线索和提示。

And If it is possible tell me how to do it or where to read more about it.如果可能,请告诉我如何操作或在哪里阅读更多相关信息。

All MS Office files with extensions ending in x are in fact zip archives (so you can change the extension and unpack) and they typically contain a handful of XML files along with media (images, videos, etc.).所有扩展名以x结尾的 MS Office 文件实际上都是 zip 存档(因此您可以更改扩展名和解压缩),它们通常包含少量 XML 文件以及媒体(图像、视频等)。

You can process all of these XML files as text, or using xml module from standard Python library - you can work with them in a slightly more advanced way.您可以将所有这些 XML 文件作为文本处理,或者使用标准 Python 库中的xml模块 - 您可以以稍微更高级的方式使用它们。

The formats are complex but often times you can do basic things without going through thousands of pages of documentation. 格式很复杂,但通常你可以做一些基本的事情,而无需阅读数千页的文档。

简短的回答是否定的,长期的回答是,您可以解压缩 .xls 文件并“手动”遍历生成的 .xml。

Previous answers regarding unpacking/unzipping the XLSX file is the correct starting point.以前关于解压/解压 XLSX 文件的答案是正确的起点。 Thereafter you'll need to know how the extracted files work together.此后,您需要知道提取的文件如何协同工作。 It's rather convoluted.比较纠结。

The best thing to do is be specific about exactly what data you want to extract then I'm sure you'll get some sample code that shows how you achieve your objective最好的办法是具体说明您想要提取的数据,然后我相信您会得到一些示例代码,显示您如何实现目标

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

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