I am guessing that your csv writer is outputting something that your 
spreadsheet is reading incorrectly.  Try opening the csv with a text editer 
(a good one, like Notepad++) so that you can really see what is going on. 
Embedded commas or quotes inside a field are invitations for disaster, and 
you have both.  You may need to change the settings on the csv writer -- it 
has lots of them, and different spreadsheet programs interpret different 
csv files differently.  The default settings are usually good for Excel, 
but you don't mention which spreadsheet you are trying to do the reading 
with, nor what settings you are using at import time.  You must find a 
combination that works for your situation (and it will not be easy.)  It 
may actually be easier to re-design the target system than to meet its 
existing requirements.
  Another option would be to use a tool like xlwt and send out a real 
spreadsheet rather than a .csv.  That way, all interpretation is under your 
control.  


On Monday, June 17, 2013 4:44:39 PM UTC+1, roopas...@gmail.com wrote:
>
> views.py
>
> @login_requireddef export_csv(request):
>     user = request.user
>     # heading columns
>     headerrow = ['Filename', 'Description','Notes other','Reporter Name']
>     allrows = []
>     today = datetime.datetime.today() # default to show today
>     reports = Report.objects.filter(user=user)
>     reports = reports.filter(created_date_time__year=today.year)
>     for report in reports:
>         row = []
>         row.append(report.report_number);
>         row.append(report.report_description);
>         row.append(report.notes_other);
>         row.append(report.reporter_name);
>         allrows.append(row)
>     # setup CSV export
>     response = HttpResponse(mimetype='text/csv')
>     filename = "%s-%s.csv" % ('Daily-reports', 
> datetime.datetime.now().strftime('%Y-%m-%d'))
>     response['Content-Disposition'] = 'attachment; filename=%s' % filename
>     writer = UnicodeWriter(response, encoding='utf-8')
>     writer.writerow(headerrow)
>     for writerow in allrows:
>         writer.writerow(writerow)
>     return response
>
> csv_unicode.py
>
> import csv, codecs, cStringIOclass UnicodeWriter:
>    def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
>         # Redirect output to a queue
>         self.queue = cStringIO.StringIO()
>         self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
>         self.stream = f
>         self.encoder = codecs.getincrementalencoder(encoding)()
>
>     def writerow(self, row):
>         self.writer.writerow([unicode(s).encode("utf-8") for s in row])
>         # Fetch UTF-8 output from the queue ...
>         data = self.queue.getvalue()
>         data = data.decode("utf-8")
>         # ... and reencode it into the target encoding
>         data = self.encoder.encode(data)
>         # write to the target stream
>         self.stream.write(data)
>         # empty queue
>         self.queue.truncate(0)
>
>     def writerows(self, rows):
>         for row in rows:
>             self.writerow(row)
>
> The above code is exporting the database data into .csv file.
>
> Problem i am facing is,the exported data like Filename,Description,Notes 
> Others,Reporter Name are exported in separate cell.Will show the output
>  i am getting and required output.
>
> You can see my existing and required format. 
>
> I had attached two format,file name existing_csv is the output file i ma 
> getting,required_csv is the .csv file i am expecting.
>
> Need some ones help.
>
>
>
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to