def chooseFile(self): self.file = QtGui.QFileDialog.getOpenFileName(self, self.trUtf8("选择.xls文件"), ".", self.trUtf8("Image Files(*.xls )")) if self.file==(u'', u''): return; else: i = 1 if self.chooseSheet.count() !=1: self.chooseSheet.clear() self.chooseSheet.addItem(self.trUtf8("请选择")) self.execlnameLineEdit.setText(self.file[0]) sheets = ExportXmlByBeyondsoft2.exceloperate(self.file[0]).getSheetNames() i =0 while i<len(sheets): self.chooseSheet.addItem(sheets[i]) i=i+1
def getFormData(self): execlname = self.execlnameLineEdit.text() sheetname = self.chooseSheet.currentText() output = self.outputLineEdit.text() savename = self.savenameLineEdit.text() if len(execlname) == 0: self.errorTipLable.setText(self.trUtf8("用例文件不能为空")) self.errorTipLable.show() elif len(sheetname) ==0: self.errorTipLable.setText(self.trUtf8("表格名不能为空")) self.errorTipLable.show() elif len(output) ==0: self.errorTipLable.setText(self.trUtf8("输出文件夹不能为空")) self.errorTipLable.show() elif len(savename) ==0: self.errorTipLable.setText(self.trUtf8("XML文件名不能为空")) self.errorTipLable.show() elif len(execlname) >= 100: self.errorTipLable.setText(self.trUtf8("用例文件最大长度为100")) self.errorTipLable.show() elif len(sheetname) >= 100: self.errorTipLable.setText(self.trUtf8("表格名最大长度为100")) self.errorTipLable.show() elif len(output) >= 100: self.errorTipLable.setText(self.trUtf8("输入文件夹最大长度为100")) self.errorTipLable.show() elif len(savename) >= 100: self.errorTipLable.setText(self.trUtf8("XML文件名最大长度为100")) self.errorTipLable.show() elif len(execlname) != 0 and len(sheetname) !=0 and len(output) !=0 and len(savename) !=0: if os.path.exists(execlname): try: sheets = ExportXmlByBeyondsoft2.exceloperate(execlname).getSheetNames() except: self.errorTipLable.setText(self.trUtf8("该用例文件没有表格")) if sheetname in sheets: if os.path.exists(output): xmlfile = output.replace('/',"\\")+"\\"+savename+".xml" aa =ExportXmlByBeyondsoft2.changetoxml(execlname,sheetname,output,savename) try: aa.run() ShellExecute(0,"open",xmlfile,"","",SW_SHOWNOACTIVATE) self.errorTipLable.setText(self.trUtf8("成功转换成XML文件")) except: self.errorTipLable.setText(self.trUtf8("请参照用例模板设计用例")) else: os.mkdir(output) xmlfile = output.replace('/',"\\")+"\\"+savename+".xml" aa =ExportXmlByBeyondsoft2.changetoxml(execlname,sheetname,output,savename) try: aa.run() ShellExecute(0,"open",xmlfile,"","",SW_SHOWNOACTIVATE) self.errorTipLable.setText(self.trUtf8("成功转换成XML文件")) except: self.errorTipLable.setText(self.trUtf8("请参照用例模板设计用例")) else: self.errorTipLable.setText(self.trUtf8("表格名不存在")) else: self.errorTipLable.setText(self.trUtf8("用例文件不存在"))