zoukankan      html  css  js  c++  java
  • python操作Excel

    pip3 install xlrd

    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    import xlrd
    from xlrd.book import Book
    from xlrd.sheet import Sheet
    from xlrd.sheet import Cell
    
    workbook = xlrd.open_workbook('oldboy.xls')
    
    sheet_names = workbook.sheet_names()
    
    # sheet = workbook.sheet_by_name('工作表1')  按名字取
    sheet = workbook.sheet_by_index(0)     # 按索引取
    
    # 循环Excel文件的所有行
    for row in sheet.get_rows():
        # 循环一行的所有列
        for col in row:
            # 获取一个单元格中的值
            print(col.value)

    pip3 install xlwt

    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    import xlwt
    
    wb = xlwt.Workbook()
    sheet = wb.add_sheet('sheet1')
    
    for row in range(10):
        for col in range(5):
            sheet.write(row, col, '第{0}行第{1}列'.format(row, col))
    
    wb.save('xxx.xls')
    
    
    # 更多示例:https://github.com/python-excel/xlwt/tree/master/examples
    写excel
  • 相关阅读:
    When You Get Troubles
    CentOS 6.8升级到7+
    Tomcat服务器搭建
    Percona Server 安装
    VirtualBox中如何使虚拟机能够上网?
    CentOS
    xen安装
    SSH免密码设置
    打造绿色版的RobotFramework
    零散知识记录-Jira的安装
  • 原文地址:https://www.cnblogs.com/zjchao/p/9136109.html
Copyright © 2011-2022 走看看