Exemple #1
0
def getSheetDataString(sheet,key_name,segmentList):
    data = {}
    nrows = sheet.nrows

    (closlit,key_index) = getUsedColsList(sheet,sheet.ncols,key_name,segmentList)

    #获取各行数据
    clos = 0
    for i in range(1,nrows):
        row_data = []
        col_index = 0

        for j in closlit:
            item =  sheet.cell_value(i,j)
            isString =  not tool.isNum(item)
            if isString :
                if item == None:
                    item = ""
            else:
                item = str(int(item))

            row_data.insert(col_index,item)
            col_index = col_index + 1

        temp = row_data[0]
        data[temp] = row_data

        clos = max(clos,col_index)

    return data,key_index,clos
Exemple #2
0
def saveSheetDataDic(FileName,data,saveDir,clos):
    print (u'正在生成  xlsx:',FileName)

    saveFileName = FileName + "_"+"CSVFile"
    nrows = len(data)

    saveFileData = saveFileName + "={\n"
    hash_list = []
    #获取各行数据

    for key in data.keys():
        itemStr = ""
        itemStr = itemStr +  "[" + str(len(hash_list)) +"]={"
        print ('line: ' + str(key))
        index = 0

        for item in data[key]:
            isString = not tool.isNum(item)
            if isString :
                if item == None:
                    item = ""
            else:
                item = str(int(item))

            if index == 0:
                hash_list.append(item)



            item = checkItemChangeLine(item)
            itemStr = itemStr + "[" + str(index) + '] = "' + item + '",'
            index = index + 1

        itemStr = itemStr + '["m_datalen"]=' + str(clos) + ","
        itemStr = itemStr + "},\n"
        saveFileData = saveFileData + itemStr

    saveFileData = saveFileData + "};\n\n"

    #获取行数
    saveFileData = saveFileData +  getRows(nrows ,saveFileName)
    #获取列数
    saveFileData = saveFileData + getCols(clos,saveFileName)


    saveFileData = saveFileData + getHashList(saveFileName,hash_list,True)


    longName = saveFileName+".lua"
    longName = os.path.join(saveDir,longName)
    print (longName)
    f = open(longName, 'wb')
    f.write(saveFileData.encode("utf-8"))
    f.close()
Exemple #3
0
def getFileData(sheet,saveFileName):
    retStr = saveFileName + "={\n"

    nrows = sheet.nrows

    (closlit,key_index) = getUsedColsList(sheet,sheet.ncols,None,[])

    key_type = tool.checkSegmentTypeInt(sheet.cell_value(0,closlit[0]))

    hash_list = []
    #获取各行数据
    for i in range(1,nrows):
        retStr = retStr +  "[" + str(i-1) +"]={"
        print ('line: ' + str(i))
        index = 0
        for j in closlit:

            item =  sheet.cell_value(i,j)
            isString = not tool.isNum(item)
            if isString :
                if item == None:
                    item = ''
            else:
                item = str(int(item))

            item = checkItemChangeLine(item)
            if j== 0:
                hash_list.append(item)

            item = "[" + str(index) + "] = '" + item + "',"
            retStr = retStr + item
            index = index + 1

        retStr = retStr + '["m_datalen"]=' + str(len(closlit)) + ","
        retStr = retStr + "},\n"
    retStr = retStr + "};\n\n"

    #获取行数
    retStr = retStr +  getRows(nrows - 1,saveFileName)
    #获取列数
    retStr = retStr + getCols(len(closlit),saveFileName)

    retStr = retStr + getHashList(saveFileName,hash_list,key_type)
    return retStr