微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何从Django导出数据以将excel用作计算器,以便稍后在Django网站中显示结果?

如何解决如何从Django导出数据以将excel用作计算器,以便稍后在Django网站中显示结果?

我已经使用Django创建了一个表单,我想在我拥有的excel模板中使用此表单中的输入数据。该模板具有许多复杂的公式,而且方式太多。我想导出表单的输入数据,使用excel工作表进行所有计算,然后再将结果导入到我的Django网站中。

我尝试使用xlutils.copy用新数据编辑文件,但这样做会消除所有公式。我将如何做到这一点? 我也是Django的新手,所以我不确定在哪里放置导出数据的命令。如果有人可以帮助我,我将非常感激。

from django.db import models
from django.contrib.auth.models import User
from django.urls import reverse
from django.shortcuts import redirect

import sys; sys.path
import pandas as pd
import numpy as np
from openpyxl import load_workbook

# Create your models here.
class Pregunta(models.Model):
    genero                  = (('Hombre','Hombre'),('Mujer','Mujer'))
    res                     = (('Verdadero','1'),('Falso','2'),('Blanco','3'))
    nombre                  = models.CharField(max_length=255,null= True)
    edad                    = models.IntegerField( null=True,blank=True)
    fecha                   = models.DateField(null= True)
    sexo                    = models.CharField(choices = genero,max_length=6,null= True)
    estado                  = models.CharField(max_length=255,null= True)
    titulacion              = models.CharField(max_length=255,null= True)
    centro                  = models.CharField( max_length=255,null= True)
    p1                      = models.CharField(choices = res,max_length=9,blank=True,default = 'Blanco')
    p2                      = models.CharField(choices = res,default = 'Blanco')
    p3                      = models.CharField(choices = res,default = 'Blanco')
    p4                      = models.CharField(choices = res,default = 'Blanco')
    p5                      = models.CharField(choices = res,default = 'Blanco')
    p6                      = models.CharField(choices = res,default = 'Blanco')
    p7                      = models.CharField(choices = res,default = 'Blanco')
    p8                      = models.CharField(choices = res,default = 'Blanco')
    p9                      = models.CharField(choices = res,default = 'Blanco')
    p10                     = models.CharField(choices = res,default = 'Blanco')
    p11                     = models.CharField(choices = res,default = 'Blanco')
    p12                     = models.CharField(choices = res,default = 'Blanco')
    p13                     = models.CharField(choices = res,default = 'Blanco')
    p14                     = models.CharField(choices = res,default = 'Blanco')
    p15                     = models.CharField(choices = res,default = 'Blanco')
    p16                     = models.CharField(choices = res,default = 'Blanco')
    p17                     = models.CharField(choices = res,default = 'Blanco')
    p18                     = models.CharField(choices = res,default = 'Blanco')
    p19                     = models.CharField(choices = res,default = 'Blanco')
    p20                     = models.CharField(choices = res,default = 'Blanco')
    p21                     = models.CharField(choices = res,default = 'Blanco')
    p22                     = models.CharField(choices = res,default = 'Blanco')
    p23                     = models.CharField(choices = res,default = 'Blanco')
    p24                     = models.CharField(choices = res,default = 'Blanco')
    p25                     = models.CharField(choices = res,default = 'Blanco')
    p26                     = models.CharField(choices = res,default = 'Blanco')
    p27                     = models.CharField(choices = res,default = 'Blanco')
    p28                     = models.CharField(choices = res,default = 'Blanco')
    p29                     = models.CharField(choices = res,default = 'Blanco')
    p30                     = models.CharField(choices = res,default = 'Blanco')
    p31                     = models.CharField(choices = res,default = 'Blanco')
    p32                     = models.CharField(choices = res,default = 'Blanco')
    p34                     = models.CharField(choices = res,default = 'Blanco')
    p35                     = models.CharField(choices = res,default = 'Blanco')
    p33                     = models.CharField(choices = res,default = 'Blanco')
    p36                     = models.CharField(choices = res,default = 'Blanco')
    p37                     = models.CharField(choices = res,default = 'Blanco')
    p38                     = models.CharField(choices = res,default = 'Blanco')
    p39                     = models.CharField(choices = res,default = 'Blanco')
    p40                     = models.CharField(choices = res,default = 'Blanco')
    p41                     = models.CharField(choices = res,default = 'Blanco')
    p42                     = models.CharField(choices = res,default = 'Blanco')
    p43                     = models.CharField(choices = res,default = 'Blanco')
    p44                     = models.CharField(choices = res,default = 'Blanco')
    p45                     = models.CharField(choices = res,default = 'Blanco')
    p46                     = models.CharField(choices = res,default = 'Blanco')
    p47                     = models.CharField(choices = res,default = 'Blanco')
    p48                     = models.CharField(choices = res,default = 'Blanco')
    p49                     = models.CharField(choices = res,default = 'Blanco')
    p50                     = models.CharField(choices = res,default = 'Blanco')

    def __str__(self):
        return str(self.nombre) + ' | ' + str(self.fecha)
        print(self)

    def get_absolute_url(self):
           self.save()
           return reverse('respuesta-detalle',args=(self.pk,))

views.py

from django.shortcuts import render
from django.views.generic import ListView,DetailView,CreateView
from .models import Pregunta
from .forms import PreguntaForm
from django.http import HttpResponse

import sys; sys.path


# Create your views here.

class HomeView(ListView):
    model = Pregunta
    template_name ='home.html'

class BusquedaView(ListView):
    model = Pregunta
    template_name ='busqueda.html'

class RespuestaDetalle(DetailView):
    model = Pregunta
    template_name = 'respuesta-detalle.html'

class RespuestaDiagnostico(DetailView):
    model = Pregunta
    template_name = 'diagnostico.html'

class AddRespuesta(CreateView):
    model = Pregunta
    form_class = PreguntaForm
    template_name = 'responder.html'

urls.py

from django.urls import path
#from . import views
from .views import HomeView,RespuestaDetalle,AddRespuesta,RespuestaDiagnostico,BusquedaView

urlpatterns = [
    #path('',views.home,name="home"),path('',HomeView.as_view(),name='home'),path('busqueda/',BusquedaView.as_view(),name= 'busqueda'),path('respuesta/<int:pk>',RespuestaDetalle.as_view(),name= 'respuesta-detalle'),path('responder/',AddRespuesta.as_view(),name= 'add_respuesta'),path('diagnostico/<int:pk>',RespuestaDiagnostico.as_view(),name= 'diagnostico')
    ]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。