zoukankan      html  css  js  c++  java
  • python操作excel小试牛刀

    
    

    #修改excel表内第一个空格的内容为 'elan best' 并保存

    >>> from openpyxl import Workbook    
    >>> from openpyxl import load_workbook
    >>> from openpyxl.writer.excel import ExcelWriter
    >>> wb = load_workbook ('C:\Users\elan\Desktop\python\test.xlsx')
    >>> wb.sheetnames

    ['Sheet1']

    >>> ws = wb['Sheet1']

    >>> ws.cell (1,1).value
    1

    >>> ws.cell (1,1).value = '公务员职位表'

    >>> ws.cell (1,1).value

    'elan best'

    >>> wb.save ('C:\Users\elan\Desktop\python\test.xlsx')

    ######################################################################################

    >>> wb = load_workbook ('C:\Users\elan\Desktop\python\1.xlsx')
    >>> sheet = wb.active

    #输出最大行数
    >>> print(sheet.max_row)
    4

    #输出最大列数
    >>> print(sheet.max_column)
    129

    #获取并打印出B4的值

    >>> b4 = sheet['B4']
    >>> print(f'({b4.column}, {b4.row}) is {b4.value}')
    (2, 4) is 1e74752a-176a-4d4e-a706-dd7822b0f95b

    #获取并打印出B4的值

    >>> b4_too = sheet.cell(row=4, column=2)
    >>> print(b4_too.value)
    1e74752a-176a-4d4e-a706-dd7822b0f95b

    #按行输出excel的数据

    >>> for row in sheet.rows:
    for cell in row:
    print(cell.value)

    #按列输出excel的数据

    >>> for column in sheet.columns:
    for cell in column:
    print(cell.value)

    #打印第二行的excel数据

    >>> for cell in list(sheet.rows)[2]:
    print(cell.value)

     
  • 相关阅读:
    mysql应用技巧
    Python httplib学习
    桌标相关知识
    行业百科知识--Github
    Ghost win7 系统安装(虚拟机)
    记一次pycharm和vscode因网络问题插件下载失败的问题
    Pydiction补全插件
    MS17-010远程溢出漏洞(CVE-2017-0143)
    shell快速入门
    Yarn架构
  • 原文地址:https://www.cnblogs.com/Elanlalala/p/10531516.html
Copyright © 2011-2022 走看看