下载:需要先安装pywin32com 和 comtypes

下载地址:(用来下载三个packages)

https://pypi.org/project/

在官网搜索就可以下载到

然后放到Scripts下安装

务必先安装pywin32com 和 comtypes ,最后安装xlwings


import xlwings as xls
newbook = xls.Book()  # this will create a new workbook

会打开一个如下,nothing else

python xlwings

 wb = xls.Book(r"D:\中雅兼职资料\待办总.xlsx")  # connect to an existing file in the current working directory

会打开所展示的xlsx文件,仅打开而已

sht = wb.sheets['待办1号']

读取相应工作表

sht.range('A50').value = 'Foo 1'
设置单元格值(并未自动保存)
sht.range('A50').value = [['Foo 1', 'Foo 2', 'Foo 3'], [10.0, 20.0, 30.0]]

扩展:50行填入['Foo 1', 'Foo 2', 'Foo 3']

51行填入[10.0, 20.0, 30.0]

region = sht.range('A1:C3').value

赋值region列表List

关于区域拓展:

 sht.range('A1').expand().value

将会表示与A1相连且连续的所有单元格

还有一些与其他package合作的功能,详见https://docs.xlwings.org/zh_CN/latest/quickstart.html

 

相关文章: