python - Check worksheet name with win32com -
i have program reads data worksheet in opened excel file. if wrong file/worksheet open data corrupted.
i initiate excel using following. cannot find object of xcel contains filename or worksheet name.
import win32com.client xcel = win32com.client.dispatch("excel.application")
what looking way read filename of excel file , name of worksheet.
there no filename if open new excel application ... open new file way excel.workbooks.open(filename,readonly)
and checking sheet name
import win32com.client excel = win32com.client.dispatch('excel.application') wb = excel.workbooks.add() ws = wb.sheets(1) if ws.name!="thesheetimlookingfor": raise valueerror(ws.name)
Comments
Post a Comment