comparison Sphinx/source/plugins/python/excel.py @ 976:600da1bb6acd

fix Excel Python sample
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 30 Aug 2023 14:25:45 +0200
parents ba2403ebd4b7
children
comparison
equal deleted inserted replaced
975:eb49a4ad8fbc 976:600da1bb6acd
1 import StringIO 1 import io
2 import json 2 import json
3 import orthanc 3 import orthanc
4 import xlwt 4 import xlwt
5 5
6 def CreateExcelReport(output, uri, **request): 6 def CreateExcelReport(output, uri, **request):
18 sheet.write(row, 0, study['PatientMainDicomTags'].get('PatientID')) 18 sheet.write(row, 0, study['PatientMainDicomTags'].get('PatientID'))
19 sheet.write(row, 1, study['PatientMainDicomTags'].get('PatientName')) 19 sheet.write(row, 1, study['PatientMainDicomTags'].get('PatientName'))
20 sheet.write(row, 2, study['MainDicomTags'].get('StudyDescription')) 20 sheet.write(row, 2, study['MainDicomTags'].get('StudyDescription'))
21 row += 1 21 row += 1
22 22
23 # Serialize the Excel workbook to a string, and return it to the caller 23 # Serialize the Excel workbook to bytes, and return it to the caller
24 # https://stackoverflow.com/a/15649139/881731 24 b = io.BytesIO()
25 b = StringIO.StringIO()
26 excel.save(b) 25 excel.save(b)
27 output.AnswerBuffer(b.getvalue(), 'application/vnd.ms-excel') 26 output.AnswerBuffer(b.getvalue(), 'application/vnd.ms-excel')
28 27
29 orthanc.RegisterRestCallback('/report.xls', CreateExcelReport) 28 orthanc.RegisterRestCallback('/report.xls', CreateExcelReport)