目前我正在生成 pdf 格式的报告。但现在我想生成 ms word 或 docx 格式的报告。
我的 api.py 文件
def export_pdf(request,id):
report = Report.objects.get(id=id)
options1 = ReportPropertyOption.objects.filter(report=report,is_active=True)
locations = []
out_string = ""
map = None
for option in options1:
option.property = get_property_name(option.property)
option.exterior_images = ReportExteriorImages.objects.filter(report = option)
option.interior_images = ReportInteriorImages.objects.filter(report = option)
option.floorplan_images = ReportFloorPlanImages.objects.filter(report = option)
option.fitouts = ReportFitOut.objects.filter(propertyoption = option)
if (option.gps_longitude):
locations.append("&markers=color:red|label:S|"+""+str(option.gps_longitude)+","+str(option.gps_latidtude)+"")
for loc in locations:
out_string+=loc
if locations:
map = "http://maps.google.com/maps/api/staticmap?center=Bangalore&zoom=12&size=512x512&maptype=roadmap"+out_string+"&sensor=true"
#map = "http://maps.google.com/maps/api/staticmap?zoom=12&size=400x400&maptype=roadmap&sensor=false¢er=\\"
html = render_to_string('report/export.html', { 'pagesize' : 'A4', }, context_instance=RequestContext(request,{'options1':options1,'meta':report.meta,'map':map}))
result = StringIO.StringIO()
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")), dest=result, link_callback=fetch_resources )
#pdf = Docx(StringIO.StringIO(html.encode("UTF-8")), dest=result, link_callback=fetch_resources )
if not pdf.err:
return result
else:
return None
我正在获取结果中的所有数据,然后将该数据导出为 pdf。但现在我想将数据导出为 docx 或 MS word 格式。我想导出为 docx 格式的相同结果。因为我正在获取 pdf 格式的数据,所以我不想将导出的 pdf 转换为 docx。我想直接在docx中导出。我尝试使用 python-docx,但无法弄清楚如何以 docx 格式导出。谁能指导我如何做到这一点。我应该在 django 中使用哪个模块。请帮我