python - How to communicate with Excel files via subprocess using python?
问题描述
How do I change cells in an excel file with subprocess? So far, my code is:
import subprocess
ob =subprocess.Popen(['*Path to excel file*'], shell=True)
ob.communicate('H2=test')
But, it doesn't do anything!
Any help would be appreciated
解决方案
我想也许你在这里很难理解子流程模块的实际作用。
当您在其中使用shell=True
参数时,就像您打开终端(或 Windows 中的 cmd)并输入该参数一样。
如果您在 Windows 上,请尝试运行subprocess.call('dir', shell=True)
,看看会发生什么。您应该会看到显示的当前目录的内容。如果你在 mac/linux 上运行subprocess.call('ls', shell=True)
,它应该做同样的事情。
因此,对于您目前的任务,这不是正确的工具。但是,此模块对于其他任务可能非常有用。
就个人而言,我喜欢结合使用 openpyxl 和 Pandas 将 Excel 工作表读取到 DataFrame 并在 python 内部对其进行操作。Pandas 有一个很好的read_excel
功能,文档在这里。
推荐阅读
- java - Jsoup select方法总是返回null
- php - PHP 代码中的错误“$agent”意外
- spring-boot - EC2 上的 Kafka 集群面临“正在缩小分区的 ISR”和“缓存的 zkVersion [] 不等于 Zookeeper 中的,跳过更新 ISR”
- java - 如何从字符串中获取 ipAddresses 列表?
- angular - 某些页面中未显示离子图标
- c# - 未观察到/未等待的任务是否会影响 ASP.Net 网站性能
- android - 上传视频的文件路径为空
- ios - Facebook SharePhoto 对话框未在 swift 4 中显示
- python - 如何使用 plotly 离线显示/隐藏带有复选框的子图
- html - 一个 html 元素被另一个重叠。如何解决?