我正在开发一个Python脚本,它使用win32com打开一个excel并对其进行修改。
我在调用objNewRange=objWrkBook.Worksheets('Sheet1').Range('$A$2:$T$15')
时遇到问题。
我收到错误:
Run-time error -2147352573: Member not found.
当我从python shell运行它时脚本工作正常,但我从HP ALM调用相同的代码。我可以使用'Cells'方法专门编写一个单元格,但看起来Python无法找到Range方法。
以下是代码片段
# Newin [PythonScript]
# Created by Application Lifecycle Management
# 7/7/2016 4:06:15 PM
# ====================================================
import win32com.client
import pythoncom
import xlsxwriter
import string
import os
import shutil
import pythoncom
import sys
import win32com.client as win32
import datetime
import imp
import argparse
import glob
import re
from xml.etree.ElementTree import parse, tostring
from xml.etree import ElementTree as et
# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
# StrVerifyExpResults Function:
# Description: This is the main fucntion that is used to compare the expected values to the actual ones. This calls in subfucntions to perform different operations
# Debug - Boolean. Equals to false if running in [Test Mode] : reporting to Application Lifecycle Management
# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
def StrVerifyExpResults(strFileName, strFilePath, strCurrentTestCaseID, intRowNum):
'''Opening the Input sheet'''
#strFileOpenStatus ='Success'
strFileOpenStatus, objWrkBook=OpenInputSheet(strFileName, strFilePath)
if strFileOpenStatus=='Success':
'''Get all row numbers from the input sheet'''
objWrkSheet=objWrkBook.Worksheets('Sheet1')
objDataRange=GetUsedRowRange(objWrkBook, 'Sheet1')
#Getting Range where the Data Is available
objNewRange=objWrkBook.Worksheets('Sheet1').Range('$A$2:$T$15')
print objNewRange.Address
# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Main Function:
# Description: This is the main fucntion that is used to compare the expected values to the actual ones. This calls in subfucntions to perform different operations
# Debug - Boolean. Equals to false if running in [Test Mode] : reporting to Application Lifecycle Management
# CurrentTestSet - [OTA COM Library].TestSet.
# CurrentTSTest - [OTA COM Library].TSTest.
# CurrentRun - [OTA COM Library].Run.
# ---------------------------------------------------------------------------------------------------------------------------------------------------------------------
def Test_Main(Debug, CurrentTestSet, CurrentTSTest, CurrentRun):
try:
# clear output window
TDOutput.Clear()
# TODO: put your code here
status=StrVerifyExpResults('input.xlsx','D:\\GVOL\\01 - Docs\\Automation\\WS Automation\\Input Sheet\\','1',2)
except pythoncom.com_error, (hr, desc, exc, arg):
TDOutput.Print("Run-time error %d: %s" % (hr, desc))
def OpenInputSheet(strFileName2, strFilePath2):
#excel = win32.gencache.EnsureDispatch('Excel.Application')
excel = win32.Dispatch('Excel.Application')
excel.Visible = False
wb = win32.GetObject(strFilePath2 + strFileName2)
ws = wb.Worksheets('Sheet1')
return ('Success', wb)