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
Ejemplo n.º 2
0
 def parseSheet(self):
     lstree,lstrees=None,None
     for row in self.lsws.iter_rows():
         for cell in row:
             if(cell.value==readConfig.keyColumn):#读取到  cell内容为 Key的关键字,表格开始解析
                 if(column_index_from_string(cell.column)==1 or (column_index_from_string(cell.column)>1 and self.lsws.cell(row=cell.row, column=column_index_from_string(cell.column)-1).value==None)):#cell.column=A, cell.row=1
                     #第一种类型的表格,表格的名字对应一个.xml,表格中只有key值,无需指定tag值
                     lstree=parseSheetSimple.parseSimpleSheet(self.lsws,cell.row+1,self.lsws.max_row,column_index_from_string(cell.column),self.lsws.max_column,column_index_from_string(cell.column),cell.row,None)
                     self.files.append([self.lsws.title,lstree])
                 elif(column_index_from_string(cell.column)>=2 and self.lsws.cell(row=cell.row, column=column_index_from_string(cell.column)-1).value==readConfig.tagColumn):
                     #第二种类型表格,表格的名字对应一个.xml,表格中有key值,tag值
                     lstree=parseSheetMultipleTags.parseMultipleTagsSheet(self.lsws,cell.row+1,self.lsws.max_row,column_index_from_string(cell.column),self.lsws.max_column,column_index_from_string(cell.column),cell.row)
                     self.files.append([self.lsws.title,lstree])
                 elif(column_index_from_string(cell.column)>=2 and self.lsws.cell(row=cell.row,column=column_index_from_string(cell.column)-1).value==readConfig.fileColumn):
                     #第三种类型表格,表格的名字无意义,表格中含有导出的.xml文件名,tag值
                     lstrees=parseSheetMultipleFiles.parseMultipleFilessSheet(self.lsws,cell.row+1,self.lsws.max_row,column_index_from_string(cell.column),self.lsws.max_column,column_index_from_string(cell.column),cell.row)
                     self.files.extend(lstrees)
                 return