python - 使用 xlwings 选择所有单元格 可能使用 specialcells(xlcelltypelastcells)

标签 python excel

我想在 Python 中使用 xlwings 处理 excel 电子表格的所有单元格。我怎样才能做到这一点? 我尝试了各种获取 specialcells(xlcelltypelastcell) 的方法,但无法使其正常工作。有谁知道 xlwings 中的正确语法?或者知道另一种使用 xlwings 获取电子表格中所有单元格的方法? 谢谢, 罗布

最佳答案

根据您的评论,以下情况如何:

>>> from xlwings import Workbook, Range
>>> import numpy as np

>>> wb1 = Workbook('/path/to/wb1.xlsx')
>>> formulas1 = Range('Sheet1', 'A1:Z100').formula

>>> wb2 = Workbook('/path/to/wb2.xlsx')
>>> formulas2 = Range('Sheet1', 'A1:Z100').formula

>>> np.array(formulas1) == np.array(formulas2)
array([[True, True, False, ...],
       [...],
       ....], dtype=bool)

如果您有一个连续的单元格范围,您还可以使用诸如 Range('A1').table.formula 之类的东西。请注意,asarray 关键字目前仅适用于 value 属性,而不适用于 formula,这就是单独的 np.array( )

关于python - 使用 xlwings 选择所有单元格 可能使用 specialcells(xlcelltypelastcells),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26854015/

相关文章:

python - Keras CNN 自动编码器输入形状错误

excel - 从 xml 文件中提取数据到 Excel 或 txt 文件

excel - 数据更改时刷新excel电子表格中的所有数据透视表

python - sklearn GridSearchCV 与管道

python - Telegram Bot 位置 python

python - 在Python中使用CV2在图像中查找图像的两个实例

vba - 如何使用WorksheetFunction.VLookup错误处理1004错误?

python - 使用类方法实现替代构造函数,如何向这些替代构造函数添加函数?

excel - 读取excel文件并上传到数据库Laravel 5

excel - #VBA - 私有(private)子 Worksheet_Change 错误 : Method 'Hidden' of Object 'Range' Field