zoukankan      html  css  js  c++  java
  • Python编程-Office操作-操作Excel(上)

    首先,需要安装openpyxl库

    http://openpyxl.readthedocs.org/en/default/

    pyton 2.x
    pip install openpyxl

    python 3.x

    easyinstall openpyxl

    准备测试excel文件

    firstExcel.py

    import openpyxl
    
    wb = openpyxl.load_workbook('example.xlsx')
    print(wb.get_sheet_names())
    
    sheet = wb.get_sheet_by_name('Sheet3')
    print(sheet.title)
    
    sheet = wb.get_sheet_by_name('Sheet1')
    print(sheet['A1'].value)
    c = sheet['B1']
    print(c.value)
    print('Row ' + str(c.row) + ', Column ' + c.column + ' is ' + c.value)
    print('Cell ' + c.coordinate + ' is ' + c.value)
    print(sheet['C1'].value)

    运行结果:

    ['Sheet1', 'Sheet2', 'Sheet3']
    Sheet3
    2015-04-05 13:34:02
    Apples
    Row 1, Column B is Apples
    Cell B1 is Apples
    73

  • 相关阅读:
    js练习 导航栏下拉子菜单
    js练习 DIV做下拉列表
    js添加事件
    HTML5音频和视频
    HTML5表单元素拓展
    document对象
    DOM
    函数
    常用的函数及递归
    JavaScript数组示例
  • 原文地址:https://www.cnblogs.com/davidgu/p/4987880.html
Copyright © 2011-2022 走看看