首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python处理excel隐藏单元格解决办法

2012-04-12 
python处理excel隐藏单元格excel里面有的内容是隐藏的,现在想用python读取excel里面的值,隐藏的内容也都一

python处理excel隐藏单元格
excel里面有的内容是隐藏的,现在想用python读取excel里面的值,隐藏的内容也都一并被读取出来了,有没什么办法和属性可以不读取到隐藏的单元格,请懂的帮忙下啊,谢谢了。。。在线等!

[解决办法]
http://groups.google.com/group/python-excel/browse_thread/thread/de8838a452ac0cb

Python code
#!/usr/bin/env python#encoding:utf-8from xlrd import open_workbook,cellnamedef main():    #打开文件    xlsfilename='c:/temp/workbook1.xls'    book=open_workbook(xlsfilename,formatting_info=True)    print 'book.nsheets:',book.nsheets    #三种方式得到sheet对象    #begin    print 'begin get sheet objects:'    #索引    mysheets=[]    for sheet_index in range(book.nsheets):        sheet=book.sheet_by_index(sheet_index)        mysheets.append(sheet)        print sheet    #名字    print book.sheet_names()    for sheet_name in book.sheet_names():        print book.sheet_by_name(sheet_name)    #对象集    for sheet in book.sheets():        print sheet    #end    cursheet=mysheets[0]    cinfomap=cursheet.colinfo_map    rinfomap=cursheet.rowinfo_map    #print 'colinfo_map:',cinfomap    #print 'rowinfo_map:',rinfomap    print 'show row and column hidden attribute:'    for key,value in cinfomap.items():        print 'col %d hidden attribute:%d' % (key,value.hidden)    for key,value in rinfomap.items():        print 'col %d hidden attribute:%d' % (key,value.hidden)    #内省一个表格,包括隐藏行列    #begin    print 'begin introspect a sheet(including all):'    print 'name:',cursheet.name    print 'nrows:',cursheet.nrows    print 'ncols:',cursheet.ncols    for row_index in range(cursheet.nrows):        for col_index in range(cursheet.ncols):            tcell=cursheet.cell(row_index,col_index)            cname=cellname(row_index,col_index)            cvalue=tcell.value            print cname,'=',cvalue    #end    #内省一个表格,不包括隐藏行列    #begin    print 'begin introspect a sheet(not including hidden):'    print 'name:',cursheet.name    print 'nrows:',cursheet.nrows    print 'ncols:',cursheet.ncols    for row_index in range(cursheet.nrows):        if rinfomap.get(row_index,0) and rinfomap[row_index].hidden==1:            continue        for col_index in range(cursheet.ncols):            if cinfomap.get(col_index,0) and cinfomap[col_index].hidden==1:                continue            tcell=cursheet.cell(row_index,col_index)            cname=cellname(row_index,col_index)            cvalue=tcell.value            print cname,'=',cvalue    #endif __name__ == '__main__':    main() 

热点排行