python excel操作单元格复制和读取的两种方法

操作单元格

新建一个sheet,

单元格赋值(两种方法)

单元格A1赋值为’xiaxiaoxu’

单元格A2赋值为‘xufengchai’

打印A1和A2单元格的值(两种方法)

#coding=utf-8

from openpyxl import Workbook

wb=Workbook()

ws=wb.create_sheet('New sheet',0)

#first way to write data

ws['A1']='xiaxiaoxu'

ws['A2']='xufengchai'

#second way to write data

ws.cell(row=3,column=1,value=10)

ws.cell(row=4,column=1,value=12)

#first way get cell's value

print ws['A1'].value

print ws['A2'].value

#second way get cell's value

print ws.cell(row=3,column=1).value

print ws.cell(row=4,column=1).value

wb.save('d:\\sample.xlsx')

c:\Python27\Scripts>python task_test.py

xiaxiaoxu

xufengchai

10

12

上一篇:centos 安装单机版 redis4.0.10


下一篇:GIT 常用命令