Re: How to get data from django model to excel sheet using openpyxl including images.

2020-07-10 Thread VenkataSivaRamiReddy
Hi man,

Have you tried *xlsxwditer* package.

If not please check

On Fri, Jul 10, 2020, 19:23 Ashutosh Mishra 
wrote:

> I am doing that using openpyxl
> But not getting the image in excel sheet
>
>
> https://stackoverflow.com/questions/62695531/cannot-convert-fieldfile-jpg-to-excel-django
>
> See this
>
> On Fri, Jul 10, 2020, 7:15 PM Vishesh Mangla 
> wrote:
>
>> Api’s are better suited for Django rest framework.
>>
>>
>>
>> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for
>> Windows 10
>>
>>
>>
>> *From: *Ashutosh Mishra 
>> *Sent: *10 July 2020 18:30
>> *To: *Django users 
>> *Subject: *Re: How to get data from django model to excel sheet using
>> openpyxl including images.
>>
>>
>>
>> i have created an api through which i can download the excel file with
>> all fields except images.I am posting my models and views
>>
>>
>>
>> models.py
>>
>>
>>
>> class Task(models.Model):
>>
>>
>>
>> Id=models.IntegerField()
>>
>> Name=models.CharField(max_length=50,null=False,blank=True)
>>
>> Image1=models.FileField(blank=True, default="",
>>
>> upload_to="media/images",null=True)
>>
>> Image2=models.FileField(blank=True, default="",
>>
>> upload_to="media/images",null=True)
>>
>> Date=models.DateField(null=True,blank=True)
>>
>> def __str__(self):
>>
>> return str(self.Name)
>>
>>
>>
>> views.py
>>
>> class TaskViewSet(viewsets.ViewSet):
>>
>>
>>
>> def list(self,request):
>>
>> try:
>>
>> queryset=Task.objects.all()
>>
>> response = HttpResponse(content_type='application/ms-excel')
>>
>> #response=HttpResponse(content_type='application/ms-excel')
>>
>>
>>
>> #response['Content-Disposition'] = 'attachment; filename="users.xls'
>>
>> response['Content-Disposition']='attachment; filename="users.xls"'
>>
>>
>>
>> wb=openpyxl.Workbook()
>>
>> ws=wb.active
>>
>>
>>
>> row_num=0
>>
>> columns=['Id','Name','Image1','Image2','Date']
>>
>>
>>
>> for col_num in range(len(columns)):
>>
>> c = ws.cell(row=row_num + 1, column=col_num + 1)
>>
>> c.value = columns[col_num]
>>
>> for obj in queryset:
>>
>> row_num+=1
>>
>> row = [
>>
>> obj.Id,
>>
>> obj.Name,
>>
>> obj.Image1.url,
>>
>> obj.Image2.url,
>>
>> str(obj.Date),
>>
>> ]
>>
>> print(type(row))
>>
>>
>>
>> for col_num in range(len(row)):
>>
>> c = ws.cell(row=row_num + 1, column=col_num + 1)
>>
>> c.value = row[col_num]
>>
>>
>>
>> wb.save(response)
>>
>> return response
>>
>> except Exception as error:
>>
>> traceback.print_exc()
>>
>> return Response({"message": str(error), "success": False},
>> status=status.HTTP_200_OK)
>>
>>
>>
>>
>>
>> On Friday, July 10, 2020 at 5:48:36 PM UTC+5:30 ajoeiam wrote:
>>
>> On Thu, Jul 9, 2020 at 10:02 PM Ashutosh Mishra 
>> wrote:
>>
>> I am creating an api to get data and images from django model to excel
>> sheet ,how can i do that,someone please help me.
>>
>>
>>
>> What have you tried so far?
>>
>>
>>
>> Regards
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/c1092b58-9d91-4d9c-8654-54df883c5172n%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/c1092b58-9d91-4d9c-8654-54df883c5172n%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/80F9CD37-925E-4CB1-A03D-743C8F10EDB4%40hxcore.ol
>> <https://groups.google.com/d/msgid/django-users/80F9CD37-925E-4CB1-A03D-743C8F10EDB4%40hxcore.ol?utm_medium=email_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAGDmY67kWhDN1bn%2BWtTcLxCj-QfmzG2F77b-2Hpbo9ouths1Gg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAGDmY67kWhDN1bn%2BWtTcLxCj-QfmzG2F77b-2Hpbo9ouths1Gg%40mail.gmail.com?utm_medium=email_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGiJVX0HsA0tKenVKbAaTDwb5TxR0umHPogUUnAH%3DU94GUumjA%40mail.gmail.com.


Re: How to get data from django model to excel sheet using openpyxl including images.

2020-07-10 Thread Ashutosh Mishra
I am doing that using openpyxl
But not getting the image in excel sheet

https://stackoverflow.com/questions/62695531/cannot-convert-fieldfile-jpg-to-excel-django

See this

On Fri, Jul 10, 2020, 7:15 PM Vishesh Mangla 
wrote:

> Api’s are better suited for Django rest framework.
>
>
>
> Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for
> Windows 10
>
>
>
> *From: *Ashutosh Mishra 
> *Sent: *10 July 2020 18:30
> *To: *Django users 
> *Subject: *Re: How to get data from django model to excel sheet using
> openpyxl including images.
>
>
>
> i have created an api through which i can download the excel file with all
> fields except images.I am posting my models and views
>
>
>
> models.py
>
>
>
> class Task(models.Model):
>
>
>
> Id=models.IntegerField()
>
> Name=models.CharField(max_length=50,null=False,blank=True)
>
> Image1=models.FileField(blank=True, default="",
>
> upload_to="media/images",null=True)
>
> Image2=models.FileField(blank=True, default="",
>
> upload_to="media/images",null=True)
>
> Date=models.DateField(null=True,blank=True)
>
> def __str__(self):
>
> return str(self.Name)
>
>
>
> views.py
>
> class TaskViewSet(viewsets.ViewSet):
>
>
>
> def list(self,request):
>
> try:
>
> queryset=Task.objects.all()
>
> response = HttpResponse(content_type='application/ms-excel')
>
> #response=HttpResponse(content_type='application/ms-excel')
>
>
>
> #response['Content-Disposition'] = 'attachment; filename="users.xls'
>
> response['Content-Disposition']='attachment; filename="users.xls"'
>
>
>
> wb=openpyxl.Workbook()
>
> ws=wb.active
>
>
>
> row_num=0
>
> columns=['Id','Name','Image1','Image2','Date']
>
>
>
> for col_num in range(len(columns)):
>
> c = ws.cell(row=row_num + 1, column=col_num + 1)
>
> c.value = columns[col_num]
>
> for obj in queryset:
>
> row_num+=1
>
> row = [
>
> obj.Id,
>
> obj.Name,
>
> obj.Image1.url,
>
> obj.Image2.url,
>
> str(obj.Date),
>
> ]
>
> print(type(row))
>
>
>
> for col_num in range(len(row)):
>
> c = ws.cell(row=row_num + 1, column=col_num + 1)
>
> c.value = row[col_num]
>
>
>
> wb.save(response)
>
> return response
>
> except Exception as error:
>
> traceback.print_exc()
>
> return Response({"message": str(error), "success": False},
> status=status.HTTP_200_OK)
>
>
>
>
>
> On Friday, July 10, 2020 at 5:48:36 PM UTC+5:30 ajoeiam wrote:
>
> On Thu, Jul 9, 2020 at 10:02 PM Ashutosh Mishra 
> wrote:
>
> I am creating an api to get data and images from django model to excel
> sheet ,how can i do that,someone please help me.
>
>
>
> What have you tried so far?
>
>
>
> Regards
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c1092b58-9d91-4d9c-8654-54df883c5172n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/c1092b58-9d91-4d9c-8654-54df883c5172n%40googlegroups.com?utm_medium=email_source=footer>
> .
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/80F9CD37-925E-4CB1-A03D-743C8F10EDB4%40hxcore.ol
> <https://groups.google.com/d/msgid/django-users/80F9CD37-925E-4CB1-A03D-743C8F10EDB4%40hxcore.ol?utm_medium=email_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGDmY67kWhDN1bn%2BWtTcLxCj-QfmzG2F77b-2Hpbo9ouths1Gg%40mail.gmail.com.


RE: How to get data from django model to excel sheet using openpyxl including images.

2020-07-10 Thread Vishesh Mangla
Api’s are better suited for Django rest framework. Sent from Mail for Windows 10 From: Ashutosh MishraSent: 10 July 2020 18:30To: Django usersSubject: Re: How to get data from django model to excel sheet using openpyxl including images. i have created an api through which i can download the excel file with all fields except images.I am posting my models and views models.py class Task(models.Model): Id=models.IntegerField()Name=models.CharField(max_length=50,null=False,blank=True)Image1=models.FileField(blank=True, default="",upload_to="media/images",null=True)Image2=models.FileField(blank=True, default="",upload_to="media/images",null=True)Date=models.DateField(null=True,blank=True)def __str__(self):return str(self.Name) views.pyclass TaskViewSet(viewsets.ViewSet): def list(self,request):try:queryset=Task.objects.all()response = HttpResponse(content_type='application/ms-excel')#response=HttpResponse(content_type='application/ms-excel') #response['Content-Disposition'] = 'attachment; filename="users.xls'response['Content-Disposition']='attachment; filename="users.xls"' wb=openpyxl.Workbook()ws=wb.active row_num=0columns=['Id','Name','Image1','Image2','Date'] for col_num in range(len(columns)):c = ws.cell(row=row_num + 1, column=col_num + 1)c.value = columns[col_num]for obj in queryset:row_num+=1row = [obj.Id,obj.Name,obj.Image1.url,obj.Image2.url,str(obj.Date),]print(type(row)) for col_num in range(len(row)):c = ws.cell(row=row_num + 1, column=col_num + 1)c.value = row[col_num] wb.save(response)return responseexcept Exception as error:traceback.print_exc()return Response({"message": str(error), "success": False}, status=status.HTTP_200_OK)  On Friday, July 10, 2020 at 5:48:36 PM UTC+5:30 ajoeiam wrote:On Thu, Jul 9, 2020 at 10:02 PM Ashutosh Mishra  wrote:I am creating an api to get data and images from django model to excel sheet ,how can i do that,someone please help me.   What have you tried so far? Regards -- You received this message because you are subscribed to the Google Groups "Django users" group.To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com.To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c1092b58-9d91-4d9c-8654-54df883c5172n%40googlegroups.com. 



-- 
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/80F9CD37-925E-4CB1-A03D-743C8F10EDB4%40hxcore.ol.


Re: How to get data from django model to excel sheet using openpyxl including images.

2020-07-10 Thread Ashutosh Mishra
i have created an api through which i can download the excel file with all 
fields except images.I am posting my models and views

models.py

class Task(models.Model):

Id=models.IntegerField()
Name=models.CharField(max_length=50,null=False,blank=True)
Image1=models.FileField(blank=True, default="",
upload_to="media/images",null=True)
Image2=models.FileField(blank=True, default="",
upload_to="media/images",null=True)
Date=models.DateField(null=True,blank=True)
def __str__(self):
return str(self.Name)

views.py
class TaskViewSet(viewsets.ViewSet):

def list(self,request):
try:
queryset=Task.objects.all()
response = HttpResponse(content_type='application/ms-excel')
#response=HttpResponse(content_type='application/ms-excel')

#response['Content-Disposition'] = 'attachment; filename="users.xls'
response['Content-Disposition']='attachment; filename="users.xls"'

wb=openpyxl.Workbook()
ws=wb.active

row_num=0
columns=['Id','Name','Image1','Image2','Date']

for col_num in range(len(columns)):
c = ws.cell(row=row_num + 1, column=col_num + 1)
c.value = columns[col_num]
for obj in queryset:
row_num+=1
row = [
obj.Id,
obj.Name,
obj.Image1.url,
obj.Image2.url,
str(obj.Date),
]
print(type(row))

for col_num in range(len(row)):
c = ws.cell(row=row_num + 1, column=col_num + 1)
c.value = row[col_num]

wb.save(response)
return response
except Exception as error:
traceback.print_exc()
return Response({"message": str(error), "success": False}, 
status=status.HTTP_200_OK)


On Friday, July 10, 2020 at 5:48:36 PM UTC+5:30 ajoeiam wrote:

> On Thu, Jul 9, 2020 at 10:02 PM Ashutosh Mishra  
> wrote:
>
>> I am creating an api to get data and images from django model to excel 
>> sheet ,how can i do that,someone please help me.  
>>
>>
>> What have you tried so far?
>
> Regards 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c1092b58-9d91-4d9c-8654-54df883c5172n%40googlegroups.com.


Re: How to get data from django model to excel sheet using openpyxl including images.

2020-07-10 Thread o1bigtenor
On Thu, Jul 9, 2020 at 10:02 PM Ashutosh Mishra 
wrote:

> I am creating an api to get data and images from django model to excel
> sheet ,how can i do that,someone please help me.
>
>
> What have you tried so far?

Regards

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPpdf58f0qp7xEEYCBu694TNyXFXpLiLU1tcDKNFYQgp7jOM1w%40mail.gmail.com.


How to get data from django model to excel sheet using openpyxl including images.

2020-07-09 Thread Ashutosh Mishra
I am creating an api to get data and images from django model to excel 
sheet ,how can i do that,someone please help me.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fff2b0b5-e4d9-423c-ac8d-b1ccc26c2109n%40googlegroups.com.