理想情况下,我是从另一个excel工作表复制整行。所以,我的问题不是显示代码,而是从列表中有那一行开始,现在如何将它放在另一个excel工作表中?我希望它看起来一模一样。目标:选择其中一种数据格式,并将其放入空白的excel工作表中,例如第1行。我希望这是一个快的东西,因为我计划扩大到10000行。
数据可以采用以下任一格式:
data = [number:6842.0, xldate:41771.0, xldate:0.005555555555555556,
text:u'Hello World']
data = [6842.0, 41771.0, 0.005555555555555556, u'Hello World']
我的代码:
import xlwt
wb = xlwt.Workbook()
data = [6842.0, 41771.0, 0.005555555555555556, u'Hello World'] #either format
sheet1 = wb.add_sheet("MyData")
sheet1.write(1,0,data)
wb.save('C:\\Python27\\helloworld.xls')
这就是我从excel文件中获取数据的方式:
from xlrd import *
import xlwt
book = open_workbook(filename= 'C:\Users\ssheikh\Desktop\CopyFile.xls')
sh = book.sheet_by_index(0)
workbook = xlwt.Workbook()
sheet = workbook.add_sheet("MyData")
b = xldate.xldate_from_date_tuple((2014,5,12), 0)
c = xldate.xldate_from_date_tuple((2014,5,13), 0)
mylist = []
listc = []
listd = []
for i in xrange(0,sh.nrows):
if sh.cell_value(rowx=i, colx =1) == b:
mylist.append(i)
listd.append(sh.row_values(i))
print 'the number', b ,'was found in row=', i, 'and column =0'
if sh.cell_value(rowx=i,colx =1) == c:
listc.append(i)
listd.append(sh.row(i))
#mylist[0] #upper limit of my rows
#listc[-1] #lower limit of my rows
listd # this has all of my rows that i want to put in a new excel file
我在xlwt中看不到任何} 或
write_row
方法,就像在xlrd中有row_values
一样。如果需要的话,只有工作表对象的^{write_rich_text
。如果有特殊样式,可以使用
write
的可选style
参数。相关问题 更多 >
编程相关推荐