Exemplo n.º 1
0
def toPy(outfile, dataName, datas):
    # 创建目录
    pyPath = checkSubPath(outfile, 'py')
    """
    dict = {value}
    value = key:value
    key = int|float|string
    value = int|float|string|[value]|dict
    """

    # 写py
    strList = []
    strList.append('datas = {\n')
    spaces4 = ' ' * 4
    spaces8 = ' ' * 8
    for k in datas:
        key = k
        if isinstance(k, int):
            key = str(k)
        elif isinstance(k, str):
            key = '"%s"' % key
        else:
            raise xlsxError.xe(config.EXPORT_ERROR_KEY_FLOAT, dataName)

        strList.append('%s%s: {\n' % (spaces4, key))

        for e in datas[k]:
            key1 = e
            if isinstance(e, int):
                key1 = str(e)
            elif isinstance(e, str):
                key1 = '"%s"' % key1
            else:
                raise xlsxError.xe(config.EXPORT_ERROR_KEY_FLOAT, dataName)

            value = datas[k][e]
            if isinstance(value, int) or isinstance(
                    value, float) or isinstance(value, tuple) or isinstance(
                        value, list):
                value = str(value)
            elif isinstance(value, str):
                value = '"%s"' % value
            else:
                raise xlsxError.xe(config.EXPORT_ERROR_NOFUNC, dataName)

            strList.append('%s%s: %s' % (spaces8, key1, value))
            strList.append(',\n')

        strList.pop()
        strList.append('\n%s}' % spaces4)
        strList.append(',\n')

    strList.pop()
    strList.append('\n}\n')
    pyFilePath = os.path.join(pyPath, 'd_%s.py' % dataName)
    pyHandle = codecs.open(pyFilePath, 'w+', 'utf-8')
    dataStr = ''.join(strList)
    pyHandle.write(dataStr)
    pyHandle.close()
Exemplo n.º 2
0
	def xlsxClear(self, errno = 0, msg = ''):
		"""
		程序异常退出清理打开的Excel
		"""
		self.xlsxClose()
		if errno > 0:
			raise xlsxError.xe(errno, msg)
		else:
			sys.exit(1)
Exemplo n.º 3
0
	def xlsxClear(self, errno = 0, msg = ''):
		"""
		程序异常退出清理打开的Excel
		"""
		self.xlsxClose()
		if errno > 0:
			raise xlsxError.xe(errno, msg)
		else:
			sys.exit(1)
Exemplo n.º 4
0
def __checkPath(dirPath):
		"""
		必须有driverName E:,D: ==
		"""
		driveName = os.path.splitdrive(dirPath)[0]
		if not os.path.isdir(driveName):
			raise xlsxError.xe(EXPORT_ERROR_CPATH, (dirPath, ))

		__onCheckPath(dirPath)

		return
Exemplo n.º 5
0
def __checkPath(dirPath):
		"""
		必须有driverName E:,D: ==
		"""
		driveName = os.path.splitdrive(dirPath)[0]
		if not os.path.isdir(driveName):
			raise xlsxError.xe(EXPORT_ERROR_CPATH, (dirPath, ))

		__onCheckPath(dirPath)

		return