예제 #1
0
	def __checkData(self):
		"""
		列数据是否符合命名规范, 生成所需字典
		"""
		self.sheetIndex2Data()
		self.dctDatas = self.g_dctDatas
		self.hasExportedSheet = []

		for dataName, indexList  in self.sheet2Data.items():
			self.curIndexMax = len(indexList)
			self.curProIndex = []
			for index in indexList:
				sheet = self.xbook.getSheetByIndex(index)
				self.curProIndex.append(index)

				cols =  self.xbook.getRowCount(index)
				rows  = self.xbook.getColCount(index)
				if dataName not in self.dctDatas:
					self.dctDatas[dataName] = {}
				self.dctData = self.dctDatas[dataName]

				for row in range(EXPORT_DATA_ROW,  rows + 1):
					rowval = self.xbook.getRowValues(sheet, row - 1)
					childDict = {}
					for col in range(1, cols + 1):
						val = rowval[col - 1]
						if val != None:
							val = (str(rowval[col - 1]),)
						else:
							val = ("",)
						#val = (self.xbook.getText(sheet, row, col),)
						if self.headerDict[index][col-1] is None:
							continue

						name, sign, funcName = self.headerDict[index][col-1]
						if EXPORT_SIGN_DOLLAR in sign and len(val[0]) > 0:
							self.needReplace({'v':val[0], "pos":(row, col)})
							v = self.mapDict[xlsxtool.GTOUC(xlsxtool.val2Str(val[0]))]  #mapDict:key是unicode.key都要转成unicode
						else:
							v = val[0]
						if EXPORT_SIGN_DOT in sign and (v is None or len(v) == 0) :
							self.xlsxClear(EXPORT_ERROR_NOTNULL, (col, row))

						try:
							sv = v#xlsxtool.toGBK(v)
						except:
							sv = v

						func = getFunc(funcName)

						try:
							v = func(self.mapDict, self.dctData, childDict, sv)
						except Exception as errstr:
							self.xlsxClear(EXPORT_ERROR_FUNC, (errstr, funcName, sv, 'row:'+str(row), 'col:'+str(col) ))
							
						for ss in sign.replace('$',''):
							if EXPORT_SIGN[ss] != None :
								EXPORT_SIGN[ss](self,{"v":v,"pos":(row, col)})

						#if isinstance(v, (isinstance, unicode)):
						#	try:
						#		v = v.decode("gb2312").encode("utf-8")
						#	except:
						#		pass
						childDict[name] = v

					print( "当前:%i/%i" % (row, rows) )
					self.dctData[self.tempKeys[-1]] = copy.deepcopy(childDict)

				self.checkGlobalDef()

			#如果有最终检查处理函数,则调用检查
			overFunc = self.mapDict.get('overFunc')
			if overFunc is not None and hasFunc(overFunc):
				func = getFunc(overFunc)
				self.dctData = func(self.mapDict, self.dctDatas, self.dctData, dataName)
				self.dctDatas[dataName] = self.dctData
			
			self.g_dctDatas.update(self.dctDatas)
			self.__onCheckSheet()
			
		self.__onCheckData()
		self.writeFoot()
예제 #2
0
    def __checkData(self):
        """
        列数据是否符合命名规范, 生成所需字典
        """
        self.sheetName2Data()
        self.dctDatas = g_dctDatas
        self.hasExportedSheet = []

        for dataName in self.sheet2Data:
            print('开始处理表:%s' % dataName)
            sheetName = self.sheet2Data[dataName]
            sheet = self.xbook.getSheetBySheetName(sheetName)

            rows = self.xbook.getRowCount(sheetName)
            cols = self.xbook.getColCount(sheetName)
            if dataName not in self.dctDatas:
                self.dctDatas[dataName] = {}
            self.dctData = self.dctDatas[dataName]

            # for row in range(3, rows + 1):
            for row in tqdm.tqdm(range(3, rows + 1), ncols=50):
                keyName: str = None
                rowval = self.xbook.getRowValues(sheet, row - 1)
                childDict = {}
                for col in range(1, cols + 1):
                    val = rowval[col - 1]
                    if val is not None:
                        val = (str(rowval[col - 1]), )
                    else:
                        val = ("", )

                    if self.headerDict[sheetName][col - 1] is None:
                        continue

                    name, sign, funcName = self.headerDict[sheetName][col - 1]
                    if '$' in sign and len(val[0]) > 0:
                        self.needReplace({'v': val[0], "pos": (row, col)})
                        if ',' in val[0]:
                            nv = val[0].strip()
                            vs = nv.split(',')
                            v = ''
                            for item in vs:
                                v += (self.mapDict[xlsxtool.GTOUC(
                                    xlsxtool.val2Str(item))] + ',')
                            v = v[:-1]  # 去掉最后的','
                        else:
                            # mapDict:key是unicode.key都要转成unicode
                            v = self.mapDict[xlsxtool.GTOUC(
                                xlsxtool.val2Str(val[0]))]
                    else:
                        v = val[0]
                    if config.EXPORT_SIGN_DOT in sign and v is None:
                        self.xlsxClear(config.EXPORT_ERROR_NOTNULL, (col, row))

                    sv = v

                    func = getFunc(funcName)

                    try:
                        v = func(self.mapDict, self.dctData, childDict, sv)
                    except Exception as errstr:
                        self.xlsxClear(config.EXPORT_ERROR_FUNC,
                                       (errstr, funcName, sv, row, col))

                    for ss in sign.replace('$', ''):
                        if len(sv) == 0 and ss == '!':
                            continue
                        if ss == '!':
                            keyName = name

                        config.EXPORT_SIGN[ss](self, {
                            'tableName': dataName,
                            "v": v,
                            "pos": (row, col)
                        })

                    childDict[name] = v

                if keyName is not None:
                    self.dctData[childDict[keyName]] = copy.deepcopy(childDict)

            overFunc = self.mapDict.get('overFunc')
            if overFunc is not None:
                func = getFunc(overFunc)
                self.dctData = func(self.mapDict, self.dctDatas, self.dctData,
                                    dataName)
                self.dctDatas[dataName] = self.dctData

            self.tempKeys.clear()
            g_dctDatas.update(self.dctDatas)

        self.writeBody()
예제 #3
0
	def __checkData(self):
		"""
		列数据是否符合命名规范, 生成所需字典
		"""
		self.sheetIndex2Data()
		self.dctDatas = g_dctDatas
		self.hasExportedSheet = []

		for dataName, indexList  in self.sheet2Data.items():
			self.curIndexMax = len(indexList)
			self.curProIndex = []
			for index in indexList:
				sheet = self.xbook.getSheetByIndex(index)
				self.curProIndex.append(index)

				cols =  self.xbook.getRowCount(index)
				rows  = self.xbook.getColCount(index)
				if dataName not in self.dctDatas:
					self.dctDatas[dataName] = {}
				self.dctData = self.dctDatas[dataName]

				for row in range(3,  rows + 1):
					childDict = {}
					for col in range(1, cols + 1):
						val = (self.xbook.getText(sheet, row, col),)
						if self.headerDict[index][col-1] is None:
							continue

						name, sign, funcName = self.headerDict[index][col-1]
						if '$' in sign and len(val[0]) > 0:
							self.needReplace({'v':val[0], "pos":(row, col)})
							v = self.mapDict[xlsxtool.GTOUC(xlsxtool.val2Str(val[0]))]  #mapDict:key是unicode.key都要转成unicode
						else:
							v = val[0]
						if EXPORT_SIGN_DOT in sign and v is None:
							self.xlsxClear(EXPORT_ERROR_NOTNULL, (col, row))

						try:
							sv = v#xlsxtool.toGBK(v)
						except:
							sv = v

						func = getFunc(funcName)

						try:
							v = func(self.mapDict, self.dctData, childDict, sv)
						except Exception as errstr:
							self.xlsxClear(EXPORT_ERROR_FUNC, (errstr, funcName, sv, row, col))
							
						for ss in sign.replace('$',''):
							EXPORT_SIGN[ss](self,{"v":v,"pos":(row, col)})

						#if isinstance(v, (isinstance, unicode)):
						#	try:
						#		v = v.decode("gb2312").encode("utf-8")
						#	except:
						#		pass
						childDict[name] = v

					print( "当前:%i/%i" % (row, rows) )
					self.dctData[self.tempKeys[-1]] = copy.deepcopy(childDict)

				self.writeHead()

			overFunc = self.mapDict.get('overFunc')
			if overFunc is not None:
				func = getFunc(overFunc)
				self.dctData = func(self.mapDict, self.dctDatas, self.dctData, dataName)
				self.dctDatas[dataName] = self.dctData
			
			g_dctDatas.update(self.dctDatas)
			self.__onCheckSheet()
			
		self.__onCheckData()
		self.writeFoot()
예제 #4
0
	def __checkData(self):
		"""
		列数据是否符合命名规范, 生成所需字典
		"""
		self.sheetIndex2Data()
		self.dctDatas = g_dctDatas
		self.dctDatasSN = g_dctDatasSN
		self.dctDatasCN = g_dctDatasCN
		self.hasExportedSheet = []

		for dataName, indexList  in self.sheet2Data.items():
			print( "开始处理sheet:[%s] max=%i" % (dataName, len(self.sheet2Data)) )
			self.curIndexMax = len(indexList)
			self.curProIndex = []
			for index in indexList:
				sheet = self.xbook.getSheetByIndex(index)
				self.curProIndex.append(index)

				cols =  self.xbook.getRowCount(index)
				rows  = self.xbook.getColCount(index)

				if dataName not in self.dctDatas:
					self.dctDatas[dataName] = {}
				self.dctData = self.dctDatas[dataName]

				if dataName not in self.dctDatasSN:
					self.dctDatasSN[dataName] = {}
				self.dctDataSN = self.dctDatasSN[dataName]
				
				if dataName not in self.dctDatasCN:
					self.dctDatasCN[dataName] = {}
				self.dctDataCN = self.dctDatasCN[dataName]

				for row in range(3,  rows + 1):
					childDict = {} # 保存1行数据(所有字段)
					childDictSN = {} # 保存1行数据(Server Need)
					childDictCN = {} # 保存1行数据(Client Need)
					for col in range(1, cols + 1):
						val = (self.xbook.getText(sheet, row, col),)
						if self.headerDict[index][col-1] is None:
							continue

						name, sign, funcName = self.headerDict[index][col-1]
						if '$' in sign and len(val[0]) > 0:
							self.needReplace({'v':val[0], "pos":(row, col)})
							v = self.mapDict[xlsxtool.GTOUC(xlsxtool.val2Str(val[0]))]  #mapDict:key是unicode.key都要转成unicode
						else:
							v = val[0]
						if EXPORT_SIGN_DOT in sign and (v is None or v.strip() == ''):
							self.xlsxClear(EXPORT_ERROR_NOTNULL, (col, row))

						try:
							sv = v#xlsxtool.toGBK(v)
						except:
							sv = v

						func = getFunc(funcName)

						try:
							# 处理1行中的1个字段
							# 注:第2、3参数 目前看起来没有用,可以忽略这2个参数
							v = func(self.mapDict, self.dctData, childDict, sv)
						except Exception as errstr:
							self.xlsxClear(EXPORT_ERROR_FUNC, (errstr, funcName, sv, row, col))
							
						for ss in sign.replace('$',''):
							EXPORT_SIGN[ss](self,{"v":v,"pos":(row, col)})

						#if isinstance(v, (isinstance, unicode)):
						#	try:
						#		v = v.decode("gb2312").encode("utf-8")
						#	except:
						#		pass
						childDict[name] = v
						if 's' in sign:
							childDictSN[name] = v
						if 'c' in sign:
							childDictCN[name] = v

					print( "当前:%i/%i" % (row, rows) )
					# 处理1行结束后,将1行数据加入1个表中
					self.dctData[self.tempKeys[-1]] = copy.deepcopy(childDict)
					self.dctDataSN[self.tempKeys[-1]] = copy.deepcopy(childDictSN)
					self.dctDataCN[self.tempKeys[-1]] = copy.deepcopy(childDictCN)

				self.writeHead()

			# 暂时屏蔽掉这个功能,感觉没什么用。另外,降低代码复杂度
			'''
			overFunc = self.mapDict.get('overFunc')
			if overFunc is not None:
				func = getFunc(overFunc)
				self.dctData = func(self.mapDict, self.dctDatas, self.dctData, dataName)
				self.dctDatas[dataName] = self.dctData
			'''
			
			g_dctDatas.update(self.dctDatas)
			g_dctDatasSN.update(self.dctDatasSN)
			g_dctDatasCN.update(self.dctDatasCN)
			self.__onCheckSheet()
			
		self.__onCheckData()
		self.writeFoot()