zoukankan      html  css  js  c++  java
  • python处理excel

    xlrd, xlwt 用来处理xls,支持Excel2003版,pyexcel处理xlsx,支持excel2007版
    我这里我用xlrd,xlwt来生成excel,可能会存在不兼容,但是功能没有问题

    用的python3,因为python2会有乱码问题。
    # -*- coding: utf-8 -*-
    import xlrd, xlwt
    
    
    def read():
        data = xlrd.open_workbook("D:\pyproject\python_excel\1.xlsx")  #打開已存在的excel
        # data.sheets()
        tables = data.sheet_names()             #获取sheet表名字
    
        for table in tables:
            data1 = xlwt.Workbook()
            sheet1 = data1.add_sheet('汇总', cell_overwrite_ok=True) #写入excel
    
            sheet = data.sheet_by_name(table)
            print(table)
    
            a = sheet.col_values(1, 1)                    #读取对应列的数据
            b = sheet.col_values(4, 1)
            c = sheet.col_values(7, 1)
            print(a, b, c)
            for i in range(0, len(a)):
                sheet1.write(i, 0, a[i])                 #在excel中写入对应位置
                sheet1.write(i, 1, b[i])
                sheet1.write(i, 2, c[i])
    
    
            data1.save('D:\pyproject\python_excel\2.xls')
    
    
    if __name__ == '__main__':
        read()
  • 相关阅读:
    C
    C
    你好,欢迎到这里来
    数组专题
    web前端的性能优化
    MornUI 源码阅读笔记
    application tips
    [转]就这样,创建了自己的运行时共享库(RSL)
    [转]glew, glee与 gl glu glut glx glext的区别和关系
    编码相关了解
  • 原文地址:https://www.cnblogs.com/jinjidedale/p/8929936.html
Copyright © 2011-2022 走看看