Example #1
0
 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
Example #2
0
 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
Example #3
0
    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