Chinaunix首页 | 论坛 | 博客
  • 博客访问: 753471
  • 博文数量: 274
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 862
  • 用 户 组: 普通用户
  • 注册时间: 2015-10-24 15:31
个人简介

不合格的程序猿

文章分类

全部博文(274)

文章存档

2019年(3)

2018年(1)

2017年(4)

2016年(160)

2015年(106)

我的朋友

分类: Python/Ruby

2016-10-14 11:08:49

#/usr/bin/python 
#-*- coding: utf-8 -*-


import xlrd
import xlwt
import math
import string


data = xlrd.open_workbook('/root/work/test/shell/key_words.xls')


table = data.sheets()[0]


nrows = table.nrows
ncols = table.ncols

w = xlwt.Workbook(encoding='utf-8')
ws = w.add_sheet('result')


style = xlwt.XFStyle()


#写入第一行和第一列
for i in range(ncols):
ni = table.cell(0, i).value
nj = table.cell(i, 0).value
print ni
if (i != 0):
ws.write(0, i, nj, style)
ws.write(i, 0, ni, style)


#计算并写入
for i in range(nrows):
for j in range(ncols):
if (i != 0) and (j != 0):
#计算
ni = string.atof(table.cell(i,i).value)
nj = string.atof(table.cell(j,j).value)
nij = string.atof(table.cell(i,j).value)
s1 = nij / math.sqrt(ni * nj)
#写入计算结果到新的xls文件
ws.write(i, j, s1)
print s1,
print ' '

#保存写入excel的内容
w.save('result.xls')


阅读(991) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~