XLWT TypeError at /XLS 'tuple' object is not callable
Я получаю вышеупомянутую ошибку при нажатии на кнопку "экспорт в excel" на моей форме.
Я использую модуль XLWT для печати листа excel, поэтому я думаю, что это может быть как-то связано с этим.
Пожалуйста, посмотрите приведенный ниже код и полное сообщение об ошибке:
Views.py
from django.shortcuts import render, redirect, get_object_or_404
from django.http import HttpResponse
import pyodbc
from django.http import FileResponse
from django.contrib import messages
from django.views import View
from django.template.loader import render_to_string
from weasyprint import HTML
import tempfile
from django.db.models import Sum
import datetime
from datetime import datetime
from dateutil.relativedelta import relativedelta
import xlwt
def printToXLS(request):
response = HttpResponse(content_type= 'application/ms-excel')
response['Content-Disposition']= 'attachment; filename=TrialBalance' + \
str(datetime.now()) + '.xls'
wb=xlwt.Workbook(encoding='utf-8')
ws = wb.add_sheet('TrialBalance')
row_num = 0
font_style = xlwt.XFStyle()
columns = ('Account' , 'Description' , 'Debit' , 'Credit')
all = 'SELECT Master_Sub_Account , cAccountTypeDescription , Debit , Credit FROM [Kyle].[dbo].[PostGL] AS genLedger'\
' Inner JOIN [Kyle].[dbo].[Accounts] '\
'on Accounts.AccountLink = genLedger.AccountLink '\
'Inner JOIN [Kyle].[dbo].[_etblGLAccountTypes] as AccountTypes '\
'on Accounts.iAccountType = AccountTypes.idGLAccountType'\
' WHERE genLedger.AccountLink not in (161,162,163,164,165,166,167,168,122)'
cursor = cnxn.cursor();
cursor.execute(all);
xAll = cursor.fetchall()
cursor.close()
xAll_l = []
for row in xAll:
rdict = {}
rdict["Description"] = row[0]
rdict["Account"] = row[1]
rdict["Credit"] = row[2]
rdict["Debit"] = row[3]
xAll_l.append(rdict)
for col_num in range(len(xAll_l)):
ws.write(row_num , col_num , columns(col_num) , font_style )
font_style = xlwt.XFStyle()
for row in xAll_l:
row_num += 1
for col_num in range(len(row)):
ws.write(row_num , col_num , str(row(col_num)) , font_style)
wb.save(response)
return response
.HTML:
Ошибка :
TypeError at /XLS 'tuple' object is not callable Request Method: GET URL запроса: http://localhost:8000/XLS Django Версия: 3.2 Исключение Тип: TypeError Exception Value: 'tuple' object is not callable Местоположение исключения: C:\Users\KylePOG\Documents\GMA Programming\accConnect\main\views.py, line 163, in printToXLS Python Исполняемый файл: C:\Users\KylePOG\AppData\Local\Programs\Python\Python39\python.exe Версия Python: 3.9.4 Python Path:
['C:\Users\KylePOG\Documents\GMA Programming\accConnect', 'C:\Users\KylePOG\AppData\Local\Programs\Python\Python39\python39.zip', 'C:\Users\KylePOG\AppData\Local\Programs\Python\Python39\DLLs', 'C:\Users\KylePOG\AppData\Local\Programs\Python\Python39\lib', 'C:\Users\KylePOG\AppData\Local\Programs\Python\Python39', 'C:\Users\KylePOG\AppData\Local\Programs\Python\Python39\lib\site-packages']. Время сервера: Tue, 07 Sep 2021 06:28:03 +0000 Traceback Switch to копирование и вставка C:\Users\KylePOG\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py, строка 47, в inner response = get_response(request) ... ▶ Локальные вары C:\Users\KylePOG\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py, строка 181, в _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) ... ▶ Local vars C:\Users\KylePOG\Documents\GMA Programming\accConnect\main\views.py, line 163, in printToXLS ws.write(row_num , col_num , columns(col_num) , font_style )