2014-03-26 1 views
1

Google App Engine에서 xlsxwriter를 사용하려고하지만 오류가 계속 발생합니다. '응답'객체에는 '알 수있는'속성이 없습니다. 이전 질문을 보았습니다. Using xlsxwriter in Google App Engine for Python & XlsxWriter object save as http response to create download in Django 그러나이 오류가 계속 발생합니다. 나는 그들이 문서에서주는 예제를 수정하려고 시도했다. https://github.com/jmcnamara/XlsxWriter/blob/master/examples/http_server_py2.pyGoogle App Engine의 Xlsxwriter 오류

현재 GAE에서 아무런 문제없이 xlwt를 사용하고있다.

output = StringIO.StringIO() 

    # Even though the final file will be in memory the module uses temp 
    # files during assembly for efficiency. To avoid this on servers that 
    # don't allow temp files, for example the Google APP Engine, set the 
    # 'in_memory' constructor option to True: 
    workbook = xlsxwriter.Workbook(self.response.out,{'in_memory': True}) 
    worksheet = workbook.add_worksheet() 

    # Write some test data. 
    worksheet.write(0, 0, 'Hello, world!') 

    # Close the workbook before streaming the data. 
    workbook.close() 

    # Rewind the buffer. 
    output.seek(0) 

    # Construct a server response. 

    self.response.headers['Content-disposition'] = 'attachment; filename=test.xls' 
    self.response.headers['Content-Transfer-Encoding'] = 'Binary' 
    self.response.headers['Content-Type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' 

답변

1

몇 가지 문제가 있습니다.

StringIO를 만들지 만 사용하지는 않습니다. 왜 통합 문서 닫은 후 output.seek(0)

을하고 귀하의 xlsxwriter.Workbook(은 둘째하지 self.response.out

output를 사용해야합니다, 당신은 output에서 문자열을 받고 self.response

해당을 작성되어야한다 마지막으로 당신이있는 경우 오류가 발생하면 질문에 스택 추적을 추가 할 때 항상 유용합니다. 그렇게하면 코드에서 실제로 예외가 발생하는 문을 확인할 수 있습니다.

+0

감사합니다. self.response.out.write (output.getvalue())를 삽입하여 작동 시켰습니다. – nallad1985