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

  • 相关阅读:
    模拟
    广搜——最优方案
    动态规划——背包
    动态规划——树规
    动态规划——区间
    fill 的用法
    状态压缩dp
    超大背包问题
    lower_bound
    弹性碰撞 poj 3684
  • 原文地址:https://www.cnblogs.com/davidgu/p/4987880.html
Copyright © 2011-2022 走看看