#/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')
阅读(1061) | 评论(0) | 转发(0) |