2014-04-04 1 views
0

Excel에서 추가 기능에 대한 링크가있어서 사용자가 다운로드 할 수 있습니다. flask + mod_wsgi를 사용하고 있습니다.내 엑셀 추가 기능이 손상된 이유는 무엇입니까?

@app.route('/link/') 
def download_addin(): 
    parent_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + '/static/' 

    response = make_response() 
    response.headers['Cache-Control'] = 'no-cache' 
    response.headers['Content-Type'] = 'application/vnd.ms-excel.addin.macroEnabled.12' 
    response.headers['Content-Disposition'] = 'attachment; filename=my_addin.xlam' 
    return response 

나는 파일을 다운로드하지만 Excel에서 사용할 때 경고 파일 형식 또는 파일 확장자가 유효하지 않기 때문에 "엑셀 파일 'my_addin.xlam'를 열 수 없습니다를 얻을 ... '

감사합니다!

답변

1

당신은 응답의 한 부분으로 파일을 반환해야합니다.이 당신이 빈 파일을 다운로드 할 수 있습니다를하지 않고

@app.route('/link/') 
def download_addin(): 
    parent_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) + '/static/' 

    with open(os.path.join(parent_dir, 'my_addin.xlam')) as f: 
     response = make_response(f.read()) 
    response.headers['Cache-Control'] = 'no-cache' 
    response.headers['Content-Type'] = 'application/vnd.ms-excel.addin.macroEnabled.12' 
    response.headers['Content-Disposition'] = 'attachment; filename=my_addin.xlam' 
    return response 

같은 것을보십시오. 엑셀하지 않는 이유는 아마 형식과 같습니다.

관련 문제