Example #1
0
def next_record_info():
    global ptr
    identity = hexa(wbk[ptr : ptr + 2])
    off = ptr + 4
    size = integer(wbk[ptr + 2 : ptr + 4])
    ptr = ptr + 4 + size
    return (identity, off, size)
Example #2
0
def read_float_record(off, size):
    r = integer(wbk[off : off + 2])
    c = integer(wbk[off + 2 : off + 4])
    i = integer(wbk[off + 4 : off + 6])
    fs = xf[i]
    fv = floating(hexa(wbk[off + 6 : off + 14]))
    return r, c, fv, "f", fs
def read_float_record(off, size):
    r = integer(wbk[off : off+2])
    c = integer(wbk[off+2 : off+4])
    i = integer(wbk[off+4 : off+6])
    fs=xf[i]
    fv = floating(hexa(wbk[off+6:off+14]))
    return r, c, fv, 'f', fs
def next_record_info():
    global ptr
    identity = hexa(wbk[ptr : ptr+2]) 
    off = ptr + 4
    size = integer(wbk[ptr+2 : ptr+4])
    ptr = ptr +4 +size
    return (identity, off, size)
Example #5
0
def read_additional(s, pos, tid):
    ans = ''
    np = pos
    if tid == 0x20 or tid == 0x40 or tid == 0x60:
        ans += '{'
        nc = integer(s[pos]) + 1
        nr = integer(s[pos + 1:pos + 3]) + 1
        np += 3
        for i in range(0, nr):
            for j in range(0, nc):
                if integer(s[np]) == 0x00:  # empty
                    ans += ','
                    np += 9
                elif integer(s[np]) == 0x01:  # float
                    ans += str(floating(hexa(s[np + 1:np + 9]))) + ','
                    np += 9
                elif integer(s[np]) == 0x02:  # string
                    st, bytes = read_string(s, np + 1, 2)
                    ans += '"' + st + '"' + ','
                    np += 1 + bytes
                elif integer(s[np]) == 0x04:  # boolean
                    if integer(s[np + 1]) == 1:
                        ans += 'TRUE,'
                    else:
                        ans += 'FALSE,'
                    np += 9
                elif integer(s[np]) == 0x10:  # error value
                    ans += err_value[integer(s[np + 1])] + ','
                    np += 9
                else:
                    pass
            ans = ans[:len(ans) - 1] + ';'
        ans = ans[:len(ans) - 1] + '}'
        return ans, np - pos
    return '', 0
Example #6
0
def read_additional(s, pos, tid):
    ans=''
    np=pos
    if tid == 0x20 or tid == 0x40 or tid == 0x60:
        ans+='{'
        nc= integer(s[pos])+1
        nr= integer(s[pos+1:pos+3])+1
        np+=3
        for i in range(0, nr):
            for j in range(0, nc):
               if integer(s[np])==0x00: # empty
                   ans += ','
                   np += 9
               elif integer(s[np])==0x01: # float
                   ans += str(floating(hexa(s[np+1:np+9])))+','
                   np+=9
               elif integer(s[np])==0x02:  # string
                   st,bytes = read_string(s, np+1, 2)
                   ans+= '"' + st + '"' + ','
                   np+=1+bytes
               elif integer(s[np])==0x04:  # boolean
                   if integer(s[np+1])==1:
                       ans+='TRUE,'
                   else:
                       ans+='FALSE,'
                   np+=9
               elif integer(s[np])==0x10:   # error value
                   ans+=err_value[integer(s[np+1])]+','
                   np+=9
               else:
                   pass
            ans=ans[:len(ans)-1]+';'
        ans=ans[:len(ans)-1]+'}'
        return ans, np-pos
    return '', 0
Example #7
0
def read_rk_record(off, size):
    r = integer(wbk[off : off + 2])
    c = integer(wbk[off + 2 : off + 4])
    i = integer(wbk[off + 4 : off + 6])
    fs = xf[i]
    rk_val = hexa(wbk[off + 6 : off + 10])
    val, typ = read_rk_value(rk_val)
    if int(val) == val:
        val = int(val)
        typ = "i"
    return r, c, str(val), typ, fs
def read_rk_record(off, size):
    r = integer(wbk[off : off+2])
    c = integer(wbk[off+2 : off+4])
    i = integer(wbk[off+4 : off+6])
    fs=xf[i]
    rk_val = hexa(wbk[off+6 : off+10])
    val, typ = read_rk_value(rk_val)
    if int(val) == val:
        val = int(val)
        typ = 'i'
    return r, c, str(val), typ, fs
Example #9
0
def read_formula(s):
    rpn = []  # rpn array
    add_list = []
    size = integer(s[:2])
    pos = 2
    while pos != 2 + size:
        tid = integer(s[pos])
        if tid >= 0x00 and tid <= 0x02: return 'UNKNOWN'

        elif tid >= 0x03 and tid <= 0x16:
            rpn += [token_list[tid]]
            pos += 1
        elif tid == 0x17:  # string
            st, bytes = read_string(s, pos + 1, 1)
            pos = pos + 1 + bytes
            rpn += ['"' + st + '"']
        elif tid == 0x1C:  # error value
            er = err_value[integer(s[pos + 1])]
            rpn += [er]
            pos += 2
        elif tid == 0x1D:  # bool
            nt = integer(s[pos + 1])
            if nt == 0: rpn += ['FALSE']
            else: rpn += ['TRUE']
            pos += 2
        elif tid == 0x1E:  # integer
            rpn += [str(integer(s[pos + 1:pos + 3]))]
            pos += 3
        elif tid == 0x1F:  # float
            fv = floating(hexa(s[pos + 1:pos + 9]))
            pos += 9
            rpn += [str(fv)]
        elif tid == 0x21 or tid == 0x41 or tid == 0x61:  # const argc function name
            (fn, argc) = fn_list[integer(s[pos + 1:pos + 3])]
            rpn += [(fn, argc)]
            pos += 3
        elif tid == 0x22 or tid == 0x42 or tid == 0x62:  # variable argc function name
            try:
                fn, argc = fn_list[integer(s[pos + 2:pos + 4])]
            except:
                return 'UNKNOWN'
            argc = integer(s[pos + 1])
            rpn += [(fn, argc)]
            pos += 4
        elif tid == 0x24 or tid == 0x44 or tid == 0x64:  # tRef
            rpn += [read_cell_address(s[pos + 1:pos + 5])]
            pos += 5
        elif tid == 0x25 or tid == 0x45 or tid == 0x65:  # tArea
            rpn += [read_cellrange_address(s[pos + 1:pos + 9])]
            pos += 9
        elif tid == 0x20 or tid == 0x40 or tid == 0x60:  # tArray
            add_list += [(len(rpn), tid)]
            pos += 8
        elif tid == 0x26 or tid == 0x46 or tid == 0x66:
            pos += 7
        elif tid == 0x19:
            bytes, t = skip_attr(s, pos)
            pos += bytes
            if t == 0x10:
                rpn += [('SUM', 1)
                        ]  # tAttrSum replaces the tFuncVar token here
        else:
            return 'UNKNOWN'  # has to take care of some other tokens too

    for i in range(0, len(add_list)):  # additional data
        index, tid = add_list[i]
        dt, bytes = read_additional(s, pos, tid)
        pos += bytes
        rpn.insert(index, dt)

    l = len(rpn)
    stk = []
    for i in range(0, l):  # converting RPN to formula using stack
        if rpn[i] in token_list[:18]:
            t2 = stk.pop()
            t1 = stk.pop()
            stk += [t1 + rpn[i] + t2]
        elif rpn[i] == 'u+' or rpn[i] == 'u-':
            t1 = stk.pop()
            ch = rpn[i]
            stk += [ch[1] + t1]
        elif rpn[i] == '%':
            t1 = stk.pop()
            stk += [t1 + '%']
        elif rpn[i] == '()':
            t1 = stk.pop()
            stk += ['(' + t1 + ')']
        elif type(rpn[i]) == tuple:
            fname, argc = rpn[i]
            fnstr = ')'
            for j in range(0, argc):
                fnstr = ',' + stk.pop() + fnstr
            if argc != 0:
                fnstr = fnstr[1:]
            fnstr = fname + '(' + fnstr
            stk += [fnstr]
        else:
            stk += [rpn[i]]
    return stk[0]
Example #10
0
def read_formula(s):
    rpn=[] # rpn array
    add_list=[]
    size=integer(s[:2])
    pos = 2
    while pos != 2+size:
        tid = integer(s[pos])
        if tid>=0x00 and tid<=0x02: return 'UNKNOWN'
        
        elif tid>=0x03 and tid<=0x16:
            rpn+=[token_list[tid]]
            pos+=1
        elif tid==0x17:  # string
            st, bytes = read_string(s, pos+1, 1)
            pos=pos+1+bytes
            rpn+=['"'+st+'"']
        elif tid==0x1C: # error value
            er=err_value[integer(s[pos+1])]
            rpn+=[er]
            pos+=2
        elif tid==0x1D:  # bool
            nt=integer(s[pos+1])
            if nt==0: rpn+=['FALSE']
            else: rpn+=['TRUE']
            pos+=2
        elif tid==0x1E: # integer
            rpn+=[str(integer(s[pos+1:pos+3]))]
            pos+=3
        elif tid==0x1F:  # float
            fv = floating(hexa(s[pos+1:pos+9]))
            pos+=9
            rpn+=[str(fv)]
        elif tid==0x21 or tid==0x41 or tid==0x61: # const argc function name
            ( fn, argc )= fn_list[integer(s[pos+1:pos+3])]
            rpn+=[(fn, argc)]
            pos+=3
        elif tid==0x22 or tid==0x42 or tid==0x62: # variable argc function name
            try:
                fn, argc = fn_list[integer(s[pos+2:pos+4])]
            except:
                return 'UNKNOWN'
            argc=integer(s[pos+1])
            rpn+=[(fn, argc)]
            pos+=4
        elif tid == 0x24 or tid==0x44 or tid==0x64: # tRef
            rpn+=[read_cell_address(s[pos+1:pos+5])]
            pos+=5
        elif tid == 0x25 or tid==0x45 or tid==0x65:   # tArea
            rpn+=[read_cellrange_address(s[pos+1:pos+9])]
            pos+=9
        elif tid == 0x20 or tid == 0x40 or tid == 0x60: # tArray
            add_list+=[ (len(rpn), tid) ]
            pos+=8
        elif tid == 0x26 or tid == 0x46 or tid == 0x66:
            pos+=7
        elif tid == 0x19:
            bytes, t = skip_attr(s, pos)
            pos += bytes
            if t==0x10:
                rpn+=[('SUM', 1)] # tAttrSum replaces the tFuncVar token here
        else:
            return 'UNKNOWN' # has to take care of some other tokens too

    for i in range(0, len(add_list)): # additional data
        index, tid = add_list[i]
        dt, bytes = read_additional(s, pos, tid)
        pos+=bytes
        rpn.insert(index, dt)
             
    l=len(rpn)
    stk=[]
    for i in range(0,l): # converting RPN to formula using stack
        if rpn[i] in token_list[:18]:
            t2=stk.pop()
            t1=stk.pop()
            stk+=[t1+rpn[i]+t2]
        elif rpn[i]=='u+' or rpn[i]=='u-':
            t1=stk.pop()
            ch=rpn[i]
            stk+=[ch[1]+t1]
        elif rpn[i]=='%':
            t1=stk.pop()
            stk+=[t1+'%']
        elif rpn[i]=='()':
            t1=stk.pop()
            stk+=['('+t1+')']
        elif type(rpn[i])==tuple:
            fname, argc = rpn[i]
            fnstr=')'
            for j in range(0, argc):
                fnstr=',' + stk.pop() + fnstr
            if argc != 0:
                fnstr=fnstr[1:]
            fnstr= fname+'('+fnstr
            stk+=[fnstr]
        else:
            stk+=[rpn[i]]
    return stk[0]