如何使用 Excel 文件列
我陷入了一个问题..我正在尝试将我在应用程序中所做的事情写入Excel文件。
studium = unt_stelle.objects.all().order_by("stand__nick")
formatter = ExcelFormatter()
simpleStyle = ExcelStyle(vert=2,wrap=1)
formatter.addBodyStyle(simpleStyle)
formatter.setWidth('name,clicks,stand.nick,berufsfelder,bereich',3000)
formatter.setWidth('erfahrung',1000)
formatter.setWidth('studiengaenge',1000)
formatter.setWidth('status',1000)
formatter.setWidth('id',500)
simple_report = ExcelReport()
simple_report.addSheet("TestSimple")
filter = ExcelFilter(order='id,name,clicks,status,stand.nick,erfahrung,studiengaenge,berufsfelder,bereich')
simple_report.addQuerySet(studium,REPORT_HORZ,formatter,filter)
response = HttpResponse(simple_report.writeReport(),mimetype='application/ms-excel')
response['Content-Disposition'] = 'attachment; filename=stellen_dump.xls'
return response
我的问题是,如果我将“studiengaenge”作为一列,我会在该列中得到奇怪的查询集,而不是正常的字符串,studiengaenge是一个ManyToManyField。我如何管理这个,以便我只有“studiengaenge”字段中的 3 个项目,并带有一些小设计,例如每个项目之间有“-”...?
谢谢
i am stuck in one problem.. i am trying to write to excel file what i do in my app.
studium = unt_stelle.objects.all().order_by("stand__nick")
formatter = ExcelFormatter()
simpleStyle = ExcelStyle(vert=2,wrap=1)
formatter.addBodyStyle(simpleStyle)
formatter.setWidth('name,clicks,stand.nick,berufsfelder,bereich',3000)
formatter.setWidth('erfahrung',1000)
formatter.setWidth('studiengaenge',1000)
formatter.setWidth('status',1000)
formatter.setWidth('id',500)
simple_report = ExcelReport()
simple_report.addSheet("TestSimple")
filter = ExcelFilter(order='id,name,clicks,status,stand.nick,erfahrung,studiengaenge,berufsfelder,bereich')
simple_report.addQuerySet(studium,REPORT_HORZ,formatter,filter)
response = HttpResponse(simple_report.writeReport(),mimetype='application/ms-excel')
response['Content-Disposition'] = 'attachment; filename=stellen_dump.xls'
return response
my problem is that if i give 'studiengaenge' as a column, i get weird queryset in this column, not a normal string, studiengaenge is a ManyToManyField. how can i manage this so that i have only 3 items from 'studiengaenge' field with some small design like with "-" in between of each items...?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,从多对多中获得的“奇怪的查询集”可以作为数组进行访问。您可以迭代它并构建一个字符串。
From what I remember, the "weird queryset" you get from the many-to-many can be accessed as an array. You can iterate through it and build a string.