こんにちは、ここでは奇妙なエラーが発生しています。残念ながら、私はそれを理解することができないほど多くの可能性があります。私は、データベースから戻ってくるいくつかのタイムストリングを持っています。ランダムに生成されたいくつかの値を使って、それらをスプレッドシートに入れたいと思います。任意のアイデアをいただければ幸いです:)複数の列を使用してExcel文書を書き込む
import xlsxwriter
# Create a workbook and add a worksheet.
workbook = xlsxwriter.Workbook('Expenses042.xlsx')
worksheet = workbook.add_worksheet()
# Add a bold format to use to highlight cells.
bold = workbook.add_format({'bold': True})
# Write some data headers.
worksheet.write('A1', 'Facility', bold)
worksheet.write('B1', 'Type', bold)
# Some data we want to write to the worksheet.
expenses=[]
for T in list1:
FM = random.randint(0,13)
RUL = random.randint(1,365)
SL = random.randint(0,4)
S = str(T['value'])
expenses= (['rent', S])
print expenses
# Start from the first cell below the headers.
row = 1
col = 0
# Iterate over the data and write it out row by row.
for item, cost in (expenses):
worksheet.write(row, col, item)
worksheet.write(row, col + 1, cost, money)
row += 1
workbook.close()
OUTPUTあなたがループ内dates
たびに上書き
runfile('C:/Users/123/Documents/emerson/CSVFILE.py', wdir='C:/Users/123/Documents/emerson')
Extracting all files from MongoDB
['rent', '24-08-2016 14:59:08']
['rent', '24-08-2016 14:59:08']
['rent', '21-08-2016 6:59:08']
['rent', '21-08-2016 6:59:08']
['rent', '22-08-2016 4:59:09']
['rent', '22-08-2016 4:59:09']
['rent', '23-08-2016 7:59:12']
['rent', '23-08-2016 7:59:12']
['rent', '21-08-2016 7:55:40']
['rent', '21-08-2016 7:55:40']
['rent', '24-08-2016 7:57:06']
['rent', '24-08-2016 7:57:06']
['rent', '24-08-2016 16:56:49']
['rent', '24-08-2016 16:56:49']
['rent', '23-08-2016 8:56:59']
['rent', '23-08-2016 8:56:59']
['rent', '21-08-2016 12:55:38']
['rent', '21-08-2016 12:55:38']
['rent', '24-08-2016 23:59:16']
['rent', '24-08-2016 23:59:16']
['rent', '24-08-2016 14:59:08']
['rent', '24-08-2016 14:59:08']
['rent', '21-08-2016 6:59:08']
['rent', '21-08-2016 6:59:08']
['rent', '22-08-2016 4:59:09']
['rent', '22-08-2016 4:59:09']
['rent', '23-08-2016 7:59:12']
['rent', '23-08-2016 7:59:12']
['rent', '21-08-2016 7:55:40']
['rent', '21-08-2016 7:55:40']
['rent', '24-08-2016 7:57:06']
['rent', '24-08-2016 7:57:06']
['rent', '24-08-2016 16:56:49']
['rent', '24-08-2016 16:56:49']
['rent', '23-08-2016 8:56:59']
['rent', '23-08-2016 8:56:59']
['rent', '21-08-2016 12:55:38']
['rent', '21-08-2016 12:55:38']
['rent', '24-08-2016 23:59:16']
['rent', '24-08-2016 23:59:16']
Exception Exception: Exception('Exception caught in workbook destructor. Explicit close() may be required for workbook.',) in <bound method Workbook.__del__ of <xlsxwriter.workbook.Workbook object at 0x0AD755B0>> ignored
Traceback (most recent call last):
File "<ipython-input-132-bfb0167086a1>", line 1, in <module>
runfile('C:/Users/123/Documents/emerson/CSVFILE.py', wdir='C:/Users/123/Documents/emerson')
File "C:\Users\123\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "C:\Users\123\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Users/123/Documents/emerson/CSVFILE.py", line 237, in <module>
for item, cost in (expenses):
ValueError: too many values to unpack
コードがエラーと一致しません... –
間違いがあるかどうかわかりませんが、もう一度(今)実行してコードをコピーして、再度エラーを確認してください –
[mcve ]。 '日付'には何がありますか? – jonrsharpe