如何使用xlsxwriter库在excel列中插入for循环中的所有返回值?因为现在这里是我的脚本循环中的输出:
Value : 4.0
Value : 17.2
Value : 7.0
excel列的结果只是 - >>> ' Vaue:7.0'
这是我的代码:
for line, file in enumerate(PM2Line):
if POA in file:
count = count + 1
#print file
worksheet.write('B2', file)#---here is my issue..
我需要将它们全部插入到一列中,但是现在它只是更新哪个是最后一个返回值。
答案 0 :(得分:1)
import xlsxwriter
workbook = xlsxwriter.Workbook('test.xlsx')
worksheet = workbook.add_worksheet()
PM2Line = ["Value: 4.0",
"Value: 17.2",
"Value: 7.0"]
row = 0
col = 0
for item in PM2Line:
worksheet.write(row, col, item)
row += 1
workbook.close()
答案 1 :(得分:0)
您可以连接所有文件(假设它们是我的示例中的字符串),然后将其添加到列中:
files = ""
count = 0
for line, file in enumerate(PM2Line):
if POA in file:
count = count + 1
files = files + file + "\n"
#print file
if count > 0:
worksheet.write('B2', files)