예제 #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
예제 #2
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