def parseMultipleFilessSheet(sheet, minrow, maxrow, mincol, maxcol, keycol,keyrow):
    lstrees,dictag,lasttag,endtag=[],{},None,None
    for tagrow in range(minrow,maxrow):#查找表格有多少个文件,并且记录每个文件的起始minrow,maxrow
        arrtag=[]
        try:
            cell = sheet.cell(row=tagrow,column=mincol-1)
            cellkey=sheet.cell(row=tagrow,column=mincol)
        except Exception as detaile:
            print(detaile)
            continue
        if(cell.column==None or cell.row==None or cell.value==None or cellkey.column==None or cellkey.row==None or cellkey.value==None):
            continue
        if(dictag.get(cell.value)!=None):
            continue
        if(lasttag==None or lasttag!=cell.value):#first one  or different one
            arrtag.extend([cell.value,cell.row])
            dictag[cell.value]=arrtag
            if(lasttag!=None):
                arrlasttag=dictag[lasttag]
                arrlasttag.extend([cell.row-1])
            lasttag=cell.value
        endtag=cell.value
    if(endtag!=None):
        arrlasttag=dictag[endtag]
        arrlasttag.extend([maxrow])

    for i,v in enumerate(dictag):
        arrtag=dictag[v]
        lstree=ETTool.createETRoot("root")
        parseSheetSimple.parseSimpleSheet(sheet,arrtag[1],arrtag[2],mincol,maxcol,keycol,keyrow,lstree)
        writeXml.writeXml("languageoutput/"+v+".xml",lstree)
        lstrees.append([v,lstree])
    return lstrees
Example #2
0
 def saveone(self, filename, lstree):
     arrinfo=getSheetInfos(filename,lstree)#[filename,datename,arrerrorfiles,arrsuccessfiles,arrnewfiles,arrsheetlanguage,arrtreeinfo]
     self.arrErrorFile.extend(list(set(arrinfo[2])))
     self.arrNewFile.extend(list(set(arrinfo[4])))
     self.arrSuccFile.extend(list(set(arrinfo[3])))
     self.datetime=arrinfo[1]
     #merge the two xml tree
     for i,v in enumerate(arrinfo[5]):# v -> every language
         for k,m in enumerate(v.arroldtree): # m->language files, for example, french has fr_fr, fr_se
             self.mergeXmls(m,v.googletree)
             writeXml.writeXml(v.arrfilepath[k],m)
def parseSimpleSheet(sheet, minrow, maxrow, mincol, maxcol, keycol,keyrow,lstree,tagname=readConfig.defaultTagName):
    if(lstree==None):
        lstree=ETTool.createETRoot("root")
    for row in sheet.get_squared_range(mincol,minrow,maxcol,maxrow):
        for cell in row:
            if(cell.column==None or cell.row==None or cell.value==None):#not valid cell
                continue
            if((column_index_from_string(cell.column) - keycol)%2==0 or (column_index_from_string(cell.column)==keycol)):# 语言配置项所在的col和key所在的col相差是有规律的
                continue
            keyname=sheet.cell(row=cell.row,column=keycol).value
            lanuagename=sheet.cell(row=keyrow,column=column_index_from_string(cell.column)).value
            if(keyname==None or lanuagename==None): #没有语言项 或 没有键值
                continue
            let=ETTool.getElement(lstree,lanuagename)
            taget=ETTool.getElement(let,tagname)
            ETTool.setElementAttriByName(taget,readConfig.defaultKeyName,keyname,cell.value)
    writeXml.writeXml("languageoutput/xoutput.xml",lstree)
    return lstree