示例#1
0
def main():
    """
    使用方法:
    set datas=datas/
    set excel=xlsx/stall.xlsx
    set targets=json py
    echo on
    xlsx2py.exe %datas% %excel% %targets%
    """
    try:
        outfile = sys.argv[1]
    except Exception as err:
        print(main.__doc__, err)
        return

    infile = sys.argv[2]
    print("开始导表:[%s]" % (infile))
    if os.path.isfile(infile):
        targets = sys.argv[3:]
        a = xlsx2py(infile, outfile, targets)
        xlsxtool.exportMenu(config.EXPORT_INFO_OK)
        a.run()
    else:
        xlsxError.error_input(config.EXPORT_ERROR_NOEXISTFILE, (infile, ))
    print(
        '-------------------------------THE END------------------------------------------------'
    )

    sys.exit()
示例#2
0
def main():
	"""
	使用方法:将indir下的所有xls或xlsx文件进行转换到output
	python xlsx2py indir outdir (lua or python or json) (client or server)
	"""
	
	if 	len(sys.argv)<5 :
		print( main.__doc__ )
		return
	global EXPORT_INPUT
	global EXPORT_OUTPUT
	global EXPORT_LANG
	global EXPORT_PLARFORM

	EXPORT_INPUT = sys.argv[1] #输入目录
	EXPORT_OUTPUT = sys.argv[2] #输出目录
	if sys.argv[3]=='lua':
		EXPORT_LANG = EXPORT_LANG_LUA
	elif sys.argv[3]=='json':
		EXPORT_LANG = EXPORT_LANG_JSON
	else:
		EXPORT_LANG = EXPORT_LANG_PYTHON

	EXPORT_GLOBAL_HEAD_DATA['lang'] = EXPORT_LANG
	if sys.argv[4]=='client':
		EXPORT_PLARFORM = EXPORT_PLARFORM_CLIENT
	else:
		EXPORT_PLARFORM = EXPORT_PLARFORM_SERVER

	files = os.listdir(EXPORT_INPUT)
	for f in files:
		inFileName = EXPORT_INPUT + '/' + f
		isExportNamePos = f.rfind('_')
		isExcelFileExtPos = f.rfind('.xls')
		if isExcelFileExtPos<0 :
			isExcelFileExtPos = f.rfind('.xlsx')

		isFileOK = isExportNamePos>0 and isExcelFileExtPos>0 and isExcelFileExtPos-isExportNamePos>1
		if isFileOK:
			isFileOK = not f.startswith('~') and os.path.isfile(inFileName)
		if isFileOK :
			print( "开始导表:[%s][%s][%s]" % (f,sys.argv[3],sys.argv[4]) )
			global EXPORT_FILENAME_NO_EXT
			EXPORT_FILENAME_NO_EXT = EXPORT_OUTPUT + '/' +f[isExportNamePos+1:isExcelFileExtPos];
			outfile =  EXPORT_FILENAME_NO_EXT+EXPORT_LANG_EXT[EXPORT_LANG];
			a = xlsx2py(inFileName, outfile)
			xlsxtool.exportMenu(EXPORT_INFO_OK)
			a.run()
			if EXPORT_LANG == EXPORT_LANG_JSON: #删除json多余输出文件
				os.remove(outfile)
	print( '-------------------------------导出成功------------------------------------------------' )		
	sys.exit()
示例#3
0
def main():
	"""
	使用方法:
	python xlsx2py excelName.xls(x) data.py
	"""
	try:
		outfile = sys.argv[1]
	except:
		print( main.__doc__ )
		return
	
	for infile in sys.argv[2:]:
		print( "开始导表:[%s] max=%i" % (infile, len(sys.argv[2:])) )
		if os.path.isfile(infile):
			a = xlsx2py(infile, outfile)
			xlsxtool.exportMenu(EXPORT_INFO_OK)
			a.run()
		else:
			xlsxError.error_input(EXPORT_ERROR_NOEXISTFILE, (infile,))
		print( '-------------------------------THE END------------------------------------------------' )
	
	sys.exit()
示例#4
0
def main():
	"""
	使用方法:
	python xlsx2py excelName.xls(x) data.py
	"""
	try:
		outfile = sys.argv[1]
	except:
		print( main.__doc__ )
		return
	
	for infile in sys.argv[2:]:
		print( "开始导表:[%s] max=%i" % (infile, len(sys.argv[2:])) )
		if os.path.isfile(infile):
			a = xlsx2py(infile, outfile)
			xlsxtool.exportMenu(EXPORT_INFO_OK)
			a.run()
		else:
			xlsxError.error_input(EXPORT_ERROR_NOEXISTFILE, (infile,))
		print( '-------------------------------THE END------------------------------------------------' )
	
	sys.exit()
示例#5
0
	def __initXlsx(self):
		self.xbook = ExcelTool(self.infile)

		while not self.xbook.getWorkbook(forcedClose = True):
			xlsxtool.exportMenu(EXPORT_INFO_RTEXCEL, OCallback = self.resetXlsx)
示例#6
0
	def __initXlsx(self):
		self.xbook = ExcelTool(self.infile)

		while not self.xbook.getWorkbook(forcedClose = True):
			xlsxtool.exportMenu(EXPORT_INFO_RTEXCEL, OCallback = self.resetXlsx)