1

Python (xlwt) で Excel にリストをエクスポートします。

response = HttpResponse(mimetype="application/ms-excel")
response['Content-Disposition'] = 'attachment; filename=MyList.xls'

wb = xlwt.Workbook()
ws = wb.add_sheet('my_list')

ws.write(0, 0, 'Country ID')
if var =='with_flag':
    ws.write(0, X, 'Country Flag')
ws.write(0, 1, 'Country Name')

フラグなしでエクスポートすると、エクスポートはニッケルを通過しました ;) が、問題はフラグ付きでエクスポートすることを選択した場合です。列の順序 (1- country_name、2- country_flag、3- country_id) を尊重する必要があります。Python が をサポートしていないことは知ってい++ます。X特定の順序でエクスポートするためにコードで行う条件はありますか?

4

1 に答える 1

1

私があなたの質問を正しく理解していれば、次のようなものが必要です。

X = 1
if var =='with_flag':
    ws.write(0, X, 'Country Flag')
    X += 1
ws.write(0, X, 'Country Name')
于 2013-05-27T11:38:09.710 に答える