def onFindScripts(self, event=None): pageNum = self.getFieldText(self.pageNumText).strip().split(',') promptName = self.getFieldText(self.promptNameText).strip().split(',') foundList = [] scriptList = self.getScriptList() if not scriptList: self.error(TEXT_ENTER_SCRIPTS) return False if not (pageNum and promptName): self.error(TEXT_ENTER_SOMETHING) return None else: print "PAGE NUMBERS: ", pageNum print "PROMPT NAMES: ", promptName xl = ExcelWorkbook() try: for filename in scriptList: found = False xl.openFile(filename) for num in pageNum: if not num: continue if xl.findInColumn(num,'C'): found = True print "Found ", num, " in file ", filename break else: continue if not found and promptName: for name in promptName: if not name: continue if xl.findInColumn(name,'B',True): print "Found ", name, " in file ", filename found = True break if found: foundList.append(filename) xl.closeWorkbook() foundList.sort() self.onClearListbox() for f in foundList: self.listbox.insert(END, f) finally: print 'Closing Excel' xl.close() del xl showinfo('Done', 'Finished searching!') return True
def readPromptFile(self, filename): promptDictionary = {} xl = ExcelWorkbook(filename) promptNameColumn = 2 promptTextColumn = 3 row = 2 promptName = xl.getCellValue(row,promptNameColumn) while promptName: #print 'Reading prompt with name: [%s]' % promptName promptName = unicode(promptName).strip() promptText = unicode(xl.getCellValue(row, promptTextColumn)).strip() promptDictionary[promptName]=promptText row = row + 1 promptName = xl.getCellValue(row,promptNameColumn) xl.close() del xl return promptDictionary
def writeComparison(self): if not self.xlApp: xlApp = ExcelWorkbook() else: if not self.xlApp.isClosed(): self.xlApp.closeWorkbook() xlApp = self.xlApp xlApp.createNewWorkbook() #xlApp.setVisible(True) currentSheet = 1 xlApp.setCurrentSheet(currentSheet) print "Writing out differences..." for i in xrange(1, len(self.differences)+1): if xlApp.getNumberOfSheets() < i: xlApp.addSheet() for diff in self.differences: if len(diff.keys()) == 0 or diff == {}: continue row = 1 column = 1 xlApp.renameSheet("%s"%(diff[FILE_NAME]), currentSheet) if diff.has_key(NUMBER_DIFFERENCE): xlApp.setCellValue(row, column, NUMBER_DIFFERENCE) column = 2 xlApp.setCellValue(row, column, diff[NUMBER_DIFFERENCE][0]) column = 3 xlApp.setCellValue(row, column, diff[NUMBER_DIFFERENCE][1]) column = 1 row = row + 1 if diff.has_key(HEADER_DIFFERENCE): xlApp.setCellValue(row, column, HEADER_DIFFERENCE) column = 2 xlApp.setCellValue(row, column, diff[HEADER_DIFFERENCE][0]) column = 3 xlApp.setCellValue(row, column, diff[HEADER_DIFFERENCE][1]) column = 1 row = row + 1 if diff.has_key(TITLE_DIFFERENCE): xlApp.setCellValue(row, column, TITLE_DIFFERENCE) column = 2 xlApp.setCellValue(row, column, diff[TITLE_DIFFERENCE][0]) column = 3 xlApp.setCellValue(row, column, diff[TITLE_DIFFERENCE][1]) column = 1 row = row + 1 if diff.has_key(ROW_DIFFERENCE): #print "number of differences: ",len(diff[ROW_DIFFERENCE]) #print diff[ROW_DIFFERENCE] for entry in diff[ROW_DIFFERENCE]: xlApp.setCellValue(row, column, ROW_DIFFERENCE) column = 2 xlApp.setCellValue(row, column, entry[0]) column = 3 xlApp.setCellValue(row, column, entry[1]) column = 1 row = row + 1 currentSheet = currentSheet +1 xlApp.setCurrentSheet(currentSheet) i = i + 1 outputFile = self.saveFileText.get() if not outputFile: outputFile = self.default_output xlApp.saveAs(outputFile) xlApp.closeWorkbook() self.xlApp = None return
def loadScript(self, excelFile): if not self.xlApp: xlApp = ExcelWorkbook(excelFile) else: if not self.xlApp.isClosed(): self.xlApp.closeWorkbook() xlApp = self.xlApp xlApp.openFile(excelFile) xlApp.setCurrentSheet(1) row = 1 script = Script() script.setNumber(xlApp.getCellValue(row,1)) script.setHeader(xlApp.getCellValue(row,2)) script.setThirdColumn(xlApp.getCellValue(row,3)) row = 2 script.setTitleRow([xlApp.getCellValue(row, column) for column in xrange(1,4)]) row = 3 column = 1 speakerCell = xlApp.getCellValue(row, column) while speakerCell: script.addRow([xlApp.getCellValue(row, column) for column in xrange(1,4)]) row = row + 1 column = 1 speakerCell = xlApp.getCellValue(row, column) xlApp.closeWorkbook() self.xlApp = xlApp return script
def writeOutput(self, differencePrompts, outputFile=None): if not outputFile: outputFile = self.default_output xl = ExcelWorkbook() xl.createNewWorkbook() xl.setColumnWidth(1, 20) xl.setColumnWidth(2, 50) xl.setColumnWidth(3, 50) promptNames = differencePrompts.keys() promptNames.sort() row = 1 for prompt in promptNames: column = 1 xl.setCellValue(row, column, prompt) xl.setCellWrapText(row, column, True) for val in differencePrompts[prompt]: column += 1 xl.setCellWrapText(row, column, True) xl.setCellValue(row, column, val) row += 1 xl.saveAs(outputFile) xl.close() del xl