Esempio n. 1
0
def singlebook():
    opts, args = getopt.getopt(sys.argv[2:], "hi:o:")

    for op, value in opts:
        if op == "-i":
            file_path = value
        elif op == "-o":
            output_path = value
        elif op == "-h":
            #TODO 写说明文字
            # usage()
            sys.exit()

    if not "file_path" in locals().keys():
        # usage()
        sys.exit()
    elif not "output_path" in locals().keys():
        # usage()
        sys.exit()

    SheetManager.addWorkBook(file_path)
    sheetNameList = SheetManager.getSheetNameList()

    for sheet_name in sheetNameList:
        sheetJSON = SheetManager.exportJSON(sheet_name)

        f = file(output_path+sheet_name+'.json', 'w')
        f.write(sheetJSON.encode('UTF-8'))
        f.close()
Esempio n. 2
0
def singlebook():
    opts, args = getopt.getopt(sys.argv[2:], "hi:o:")

    for op, value in opts:
        if op == "-i":
            file_path = value
        elif op == "-o":
            output_path = value
        elif op == "-h":
            #TODO 写说明文字
            # usage()
            sys.exit()

    if not "file_path" in locals().keys():
        # usage()
        sys.exit()
    elif not "output_path" in locals().keys():
        # usage()
        sys.exit()

    SheetManager.addWorkBook(file_path)
    sheetNameList = SheetManager.getSheetNameList()

    for sheet_name in sheetNameList:
        #单表模式下,被引用的表不会输出
        if SheetManager.isReferencedSheet(sheet_name):
            continue

        sheetJSON = SheetManager.exportJSON(sheet_name)

        f = file(output_path + sheet_name + '.json', 'w')
        f.write(sheetJSON.encode('UTF-8'))
        f.close()
Esempio n. 3
0
def mainbook():
    opts, args = getopt.getopt(sys.argv[2:], "hi:o:")

    for op, value in opts:
        if op == "-i":
            file_path = value
        elif op == "-o":
            output_path = value
        elif op == "-h":
            #TODO 写说明文字
            # usage()
            sys.exit()

    if not "file_path" in locals().keys():
        # usage()
        sys.exit()
    elif not "output_path" in locals().keys():
        # usage()
        sys.exit()

    #获取主表各种参数#
    wb = xlrd.open_workbook(file_path)
    sh = wb.sheet_by_index(0)

    workbookPathList = []
    sheetList = []
    for row in range(sh.nrows):
        type = sh.cell(row,0).value

        if type == '__workbook__':
            pass
        else:
            sheetList.append([])
            sheet = sheetList[-1]
            sheet.append(type)

        for col in range(1,sh.ncols):
            value = sh.cell(row,col).value

            if type == '__workbook__' and value != '':
                workbookPathList.append(value)
            elif value != '':
                sheet.append(value)

    #加载所有xlsx文件#
    for workbookPath in workbookPathList:
        #读取所有sheet
        SheetManager.addWorkBook(workbookPath+".xlsx")

    #输出所有表#
    for sheet in sheetList:
        sheet_name = sheet[0]
        sheet_output_field = sheet[1:]

        sheetJSON = SheetManager.exportJSON(sheet_name,sheet_output_field)

        f = file(output_path+sheet_name+'.json', 'w')
        f.write(sheetJSON.encode('UTF-8'))
        f.close()
Esempio n. 4
0
    def __mergePython(self):
        for row in range(self.dataStartRow, self.dataEndRow):

            recordId = self.__getRecordId(row)
            record = self.python_obj[recordId]

            for col in range(1, self.dataEndCol):
                field = self.fieldList[col]
                fieldName = field.name
                fieldType = field.type

                if fieldType == 'r':  #引用
                    value = record[fieldName]
                    reference_sheetName = value.split('.')[0]
                    reference_recordId = value.split('.')[1]

                    if reference_recordId.isdigit():
                        reference_recordId = int(reference_recordId)
                    #TODO 并不支持小数做主�??

                    referenceSheet = SheetManager.getSheet(reference_sheetName)
                    reference_python_obj = referenceSheet.toPython()

                    record[fieldName] = reference_python_obj[
                        reference_recordId]
Esempio n. 5
0
def saveJson(jsonPath, exportPath=""):
    SheetManager.clearJson()
    SheetManager.addJson(jsonPath)
    excelPath = jsonPath.replace("json", "xls")
    if (exportPath.__len__() != 0):
        if (exportPath[-4:] == ".xls"):
            print "receive fileName, ", exportPath
            exportPath = os.path.abspath(exportPath)
        elif os.path.exists(exportPath):
            exportPath = "".join([
                os.path.abspath(exportPath), "\\",
                os.path.basename(jsonPath).replace(".json", ".xls")
            ])
        excelPath = exportPath
    SheetManager.saveWorkBook(excelPath)
    return
Esempio n. 6
0
    def __mergePython(self):
        for row in range(self.dataStartRow, self.dataEndRow):

            recordId = self.__getRecordId(row)
            record = self.python_obj[recordId]

            for col in range(1, self.dataEndCol):
                field = self.fieldList[col]
                fieldName = field.name
                fieldType = field.type

                if fieldType == 'r':  #引用
                    value = record[fieldName]
                    reference_sheetName = value.split('.')[0]
                    reference_recordId = value.split('.')[1]

                    if reference_recordId.isdigit():
                        reference_recordId = int(reference_recordId)
                    #TODO 并不支持小数做主键

                    referenceSheet = SheetManager.getSheet(reference_sheetName)
                    reference_python_obj = referenceSheet.toPython()

                    record[fieldName] = reference_python_obj[reference_recordId]
Esempio n. 7
0
def mainbook():
    opts, args = getopt.getopt(sys.argv[2:], "hi:o:")

    for op, value in opts:
        if op == "-i":
            file_path = value
        elif op == "-o":
            output_path = value
        elif op == "-h":
            #TODO 写说明文字
            # usage()
            sys.exit()

    if not "file_path" in locals().keys():
        # usage()
        sys.exit()
    elif not "output_path" in locals().keys():
        # usage()
        sys.exit()

    #获取主表各种参数#
    wb = xlrd.open_workbook(file_path)
    sh = wb.sheet_by_index(0)

    workbookPathList = []
    sheetList = []
    for row in range(sh.nrows):
        type = sh.cell(row, 0).value

        if type == '__workbook__':
            pass
        else:
            sheetList.append([])
            sheet = sheetList[-1]
            sheet.append(type)

        for col in range(1, sh.ncols):
            value = sh.cell(row, col).value

            if type == '__workbook__' and value != '':
                workbookPathList.append(value)
            elif value != '':
                sheet.append(value)

    #加载所有xlsx文件#
    for workbookPath in workbookPathList:
        #读取所有sheet
        SheetManager.addWorkBook(workbookPath + ".xlsx")

    #输出所有表#
    for sheet in sheetList:

        #表改名处理
        if '->' in sheet[0]:
            sheet_name = sheet[0].split('->')[0]
            sheet_output_name = sheet[0].split('->')[1]
        else:
            sheet_output_name = sheet_name = sheet[0]

        sheet_output_field = sheet[1:]

        sheetJSON = SheetManager.exportJSON(sheet_name, sheet_output_field)

        f = file(output_path + sheet_output_name + '.json', 'w')
        f.write(sheetJSON.encode('UTF-8'))
        f.close()