更新时间:2022-11-14 12:12:44
尝试使用 xlwings
与python接口的库
他们的文档示例:
从xlwings导入工作簿,工作表,范围,图表
wb = Workbook()#创建与新工作簿的连接
Range('A1')。value ='Foo 1'
Range('A1')。value
>>> 'Foo 1'
Range('A1')。value = [['Foo 1','Foo 2','Foo 3'],[10.0,20.0,30.0]]
I have an Excel file with one worksheet that has sediment collection data. I am running a long Python script.
In the worksheet is a column titled "CollectionYear." Say I want the year 2010. If the year 2010 exists in the "CollectionYear" column, I want the rest of the script to run, if not then I want the script to stop.
This seems like an easy enough task but for the life of me I cannot figure it out nor find any examples.
Any help would be greatly appreciated.
Try using xlwings
library to interface with Excel from python
example from their docs:
from xlwings import Workbook, Sheet, Range, Chart
wb = Workbook() # Creates a connection with a new workbook
Range('A1').value = 'Foo 1'
Range('A1').value
>>> 'Foo 1'
Range('A1').value = [['Foo 1', 'Foo 2', 'Foo 3'], [10.0, 20.0, 30.0]]