Python 2.7 通过Python使用COM API阅读Excel工作表
我在前面使用过xlrd和xlwt,它们易于读取行和列。我正在将当前的excel读写代码(当前正在使用xlrd和xlwt)转换为excel com apiPython 2.7 通过Python使用COM API阅读Excel工作表,python-2.7,Python 2.7,我在前面使用过xlrd和xlwt,它们易于读取行和列。我正在将当前的excel读写代码(当前正在使用xlrd和xlwt)转换为excel com api import win32com.client as win32 excel = win32.Dispatch('Excel.Application') wbtemp = excel.Workbooks.Open(file path) readtemp = wbtemp.Worksheets('Temp') read_1 = readtemp.C
import win32com.client as win32
excel = win32.Dispatch('Excel.Application')
wbtemp = excel.Workbooks.Open(file path)
readtemp = wbtemp.Worksheets('Temp')
read_1 = readtemp.Cells(1,1)
print read_1
System User
used = readtemp.UsedRange
print used.Find('System User')
System User ## it shows System User is present in worksheet, wont give which cell
print used.Find('xyz')
None ## when its not found on worksheet
目前上述代码硬编码到单元格(1,1),但我正在寻找灵活的方法,如在工作表中搜索“系统用户”,并以单元格(1,1)的形式获得回复
import win32com.client as win32
excel = win32.Dispatch('Excel.Application')
wbtemp = excel.Workbooks.Open(file path)
readtemp = wbtemp.Worksheets('Temp')
read_1 = readtemp.Cells(1,1)
print read_1
System User
used = readtemp.UsedRange
a = used.Rows.Find('System User')
print a.Address
$A$1 ## Thats what I was looking for..