コード例 #1
0
 def postHandler(self,renderer):
     
     form = web.input(userfile={},comment=None)
     
     submittedFileName = str(form['userfile'].filename)
     
     if Util.getIndexOfStringInString(submittedFileName, ".csv", None):
         pass # do stuff with csv to xlsx
     
     tempDir=Util.createDirForTempFiles()
     result = "Success!"
     
     isError = 0
     
     try:
         
         filePath= Util.createTempFileWithData(tempDir,form['userfile'].value)
         
         workBook=Util.openWorkBook(filePath)
         result = Util.dictToJson(self.workBookToJson(workBook))
         fileName = None
         
         try:
             metaSheet=workBook.sheet_by_name(Rules.metaSheetName)
             fileName = Util.cellVal(metaSheet,0,1)
         except:
             None
             
         if(not fileName):
             fileName = "data.py"
         
         attachmentName =  'attachment; filename="%s" ' % (fileName)
         web.header('Content-type','application/octet-stream')
         web.header('Content-transfer-encoding','base64')
         web.header('Content-Disposition',attachmentName)
         
         return result
         
     except Exception, e:
         isError = 1
         print "IN Excepetion"
         Util.printStackTraceInConsole()
         result = "Failed %s " % str(e)
         print str("result it %s " % result)
コード例 #2
0
                idKeyValue = long(float(Util.cellVal(currSheet, row_index, col))) # pick the 0th column value
            except Exception , e:
                raise Exception("Exception %s while working with Sheet ('%s')  Row_No=%i and Col=%i -------- Celll_Value =%s " % (str(e), currSheet.name,row_index, col, str(Util.cellVal(currSheet, row_index, col))))
                
            currRow = dataDict[str(idKeyValue)] = {}
            for column in arrColumns:
                cellValue = Util.cellVal(currSheet, row_index, col)
                try:
                    cellValue = Util.getCastedValue(cellValue,column.fieldType)
                except Exception , e:
                    print (str(e))
                    print "exception in sheet %s in row =%i col=%i " % (currSheet.name,row_index,col)
                    raise Exception("exception %s  %s sheet in row =%i col=%i " % (str(e), currSheet.name,row_index,col))
                
                if(cellValue):
                    currRow[column.fieldName] = cellValue 
                
                col = col + 1
        
        jsonForKey = Util.dictToJson(dataDict)
        key = Util.getSh1OfStr(jsonForKey)
        # do encryption here once done with other work
        
        mainDataDict[Rules.keyName] = key 
            
        return mainDataDict
            
            
        # add all the columns in dict