码迷,mamicode.com
首页 > 编程语言 > 详细

python excel处理openpyxl

时间:2017-09-17 15:07:02      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:path   sheet   for   open   range   work   port   book   xls   

#!usr/bin/dev python
#utf-8

from openpyxl import load_workbook
import os
import os.path
file_path = ‘C:/Users/Hugo Lester/Desktop/statics.xlsx‘
ws = load_workbook(file_path)
sheet = ws.get_sheet_by_name(‘Sheet1‘)
for i in range(1,10):
clo = str(int(i))

#sheet[‘G‘+clo] = sheet.cell[‘A‘+clo].value +sheet.cell[‘B‘+clo].value+sheet.cell[‘C‘+clo].value+sheet.cell[‘D‘+clo].value+sheet.cell[‘E‘+clo].value+sheet.cell[‘F‘+clo].value
#+ sheet[‘B‘+clo]+ sheet[‘C‘+clo]+ sheet[‘D‘+clo]+ sheet[‘E‘+clo]+ sheet[‘F‘+clo]
#sheet[‘A‘ + clo].value + sheet[‘B‘ + clo].value + sheet[‘C‘ + clo].value +sheet[‘D‘+clo].value+sheet[‘E‘+clo].value+sheet[‘F‘+clo].value
sheet[‘G‘ + clo] = 0
for row in range(0,6):
rownum = chr(ord(‘A‘)+ row)
position = rownum + clo
print sheet[position].value
#print rownum
if not sheet[position].value is None:

sheet[‘G‘ + clo] = sheet[‘G‘ + clo].value +sheet[position].value
#print rownum
#print type(row)
#print type(sheet[‘G‘ + clo].value)
#print rownum
ws.save(file_path)

  

python excel处理openpyxl

标签:path   sheet   for   open   range   work   port   book   xls   

原文地址:http://www.cnblogs.com/HugoLester/p/7535280.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!