xlrdnameAPIdemo.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:smartschool 作者: asifkodur 项目源码 文件源码
def show_name_object(book, nobj, show_contents=0, f=sys.stdout):
    print >> f, "\nName: %r, scope: %r (%s)" \
        % (nobj.name, nobj.scope, scope_as_string(book, nobj.scope))
    res = nobj.result
    print >> f, "Formula eval result: %r" % res
    if res is None:
        return
    # result should be an instance of the Operand class
    kind = res.kind
    value = res.value
    if kind >= 0:
        # A scalar, or unknown ... you've seen all there is to see.
        pass
    elif kind == xlrd.oREL:
        # A list of Ref3D objects representing *relative* ranges
        for i in xrange(len(value)):
            ref3d = value[i]
            print >> f, "Range %d: %r ==> %s"% (i, ref3d.coords, xlrd.rangename3drel(book, ref3d))
    elif kind == xlrd.oREF:
        # A list of Ref3D objects
        for i in xrange(len(value)):
            ref3d = value[i]
            print >> f, "Range %d: %r ==> %s"% (i, ref3d.coords, xlrd.rangename3d(book, ref3d))
            if not show_contents:
                continue
            datemode = book.datemode
            for shx in xrange(ref3d.shtxlo, ref3d.shtxhi):
                sh = book.sheet_by_index(shx)
                print >> f, "   Sheet #%d (%s)" % (shx, sh.name)
                rowlim = min(ref3d.rowxhi, sh.nrows)
                collim = min(ref3d.colxhi, sh.ncols)
                for rowx in xrange(ref3d.rowxlo, rowlim):
                    for colx in xrange(ref3d.colxlo, collim):
                        cty = sh.cell_type(rowx, colx)
                        if cty == xlrd.XL_CELL_EMPTY and show_contents == 1:
                            continue
                        cval = sh.cell_value(rowx, colx)
                        sval = showable_cell_value(cty, cval, datemode)
                        print >> f, "      (%3d,%3d) %-5s: %r" \
                            % (rowx, colx, xlrd.cellname(rowx, colx), sval)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号