python 功能很强大, 它自身带的类库,或者是第三方的库,可以直接操作Excel的内容
#!/usr/bin/python# coding:utf-8#**************************************##**这个程序两个目的:#**1.打开一个指定的excel,然后读取里面存储的内容,以最后一个单元格的内容为界,#** 打印出其所在的行号,列号,并且打印出其前面所有单元格的内容#**2.创建一个新的excel表格,然后往里面写入一些东西#****************************************import xlrdfrom pyExcelerator import *fname = "reflect.xls"bk = xlrd.open_workbook(fname)shxrange = range(bk.nsheets)try: sh = bk.sheet_by_name("Sheet1")except: PRint "no sheet in %s named Sheet1" % fnamenrows = sh.nrowsncols = sh.ncolsprint "nrows is %d,ncols is %d" % (nrows,ncols)cell_value = sh.cell_value(1,1)print "cell_value is ",cell_valuerow_list = [ ]for i in range(0,nrows): print i raw_data = sh.row_values(i) print raw_data row_list.append(raw_data) print "Start creat excel"w = Workbook()ws = w.add_sheet('JM_sheet')ws.write(0,1,'bites')ws.write(0,5,'changsheng')ws.write(10,8,4)ws = w.add_sheet('JM_sheet1')for i in xrange(10): ws.write(i,i,i)ws = w.add_sheet('JM_sheet2')for i in xrange(len(row_list)): for j in xrange(len(row_list[i])): ws.write(i,j,str(row_list[i][j]))w.save('JM_cel.xls')
新闻热点
疑难解答