0
我尝试用下面的脚本将值写入excel文件(XLS)。 有4行值,但输出只显示1行。如何在excel(XLS)机器人框架中编写循环?
第二个问题:我可以使用现有的文件吗?
*** Settings ***
Library Collections
Library WriteExcel.Excel
*** Variables ***
*** Test Cases ***
Write Excel Test
[Tags]
@{content} Create List
Append To List ${content} 1 1 Test Case 1
Append To List ${content} 2 1 Test Case 2
Append To List ${content} 3 1 Test Case 3
Append To List ${content} 4 1 Test Case 4
Write To Excel File test3.xls ${content}
这是我WriteExcel.py
import xlwt
class Excel(object):
def __init__(self):
print "write to excel file"
def group(self,lst, n):
return zip(*[lst[i:n] for i in range(n)])
def write_to_excel_file(self,filename,content_list):
# Create an new Excel file and add a worksheet.
workbook = xlwt.Workbook()
worksheet = workbook.add_sheet('wb')
#content_lists=[1,1,'hello',2,1,'brother',3,1,'how are you',4,1,'are you good today']
t=self.group(content_list,3)
#print(t)
for item in t:
worksheet.write(int(item[0]), int(item[1]), item[2])
# close work book
workbook.save(filename)
你't'只包含一个元组进行迭代/写入文件: '>>> MYLIST = [1,1,“测试1“,2,1,”测试2“,3,1,”测试3“,4,1,”测试4“] >>> zip(* [mylist [i:3] (3)])' '[(1,1,'Test 1')]' 所以你需要在'某个地方用'n'来迭代'group'。 –
感谢您的建议 –