Example
# -*- coding: utf-8 -*-
import logging
from flask import render_template, Flask, Response
from google.cloud import storage
import openpyxl
from openpyxl.writer.excel import save_virtual_workbook
import io
app = Flask(__name__)
logging.getLogger().setLevel(logging.INFO)
@app.route('/applicationform/a0026', methods=['GET', 'POST'])
def a0026():
client = storage.Client()
bucket = client.get_bucket('★ Projektname ★.appspot.com')
blob = bucket.blob('a0025.xlsx')
blob_io = io.BytesIO(blob.download_as_string())
wb = openpyxl.load_workbook(blob_io, keep_vba=False)
sheet = wb.get_sheet_by_name('★ Blattname ★')
sheet['K5'] = 'Test Test'
save_data = save_virtual_workbook(wb)
new_blob = bucket.blob('a0025_new.xlsx')
new_blob.upload_from_string(save_data, content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
res = Response(save_data, content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
res.headers['Content-Disposition'] = 'attachment; filename="a0025_new.xlsx"'
return res
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)
** Setzen Sie keep_vba auf True. ** **.
wb = openpyxl.load_workbook(blob_io, keep_vba=True)
** Der Inhaltstyp wurde in "application / vnd.ms-excel.sheet.macroEnabled.12" geändert. **
new_blob.upload_from_string(save_data, content_type='application/vnd.ms-excel.sheet.macroEnabled.12')
res = Response(save_data, content_type='application/vnd.ms-excel.sheet.macroEnabled.12')
** Erweiterung ändern **
new_blob = bucket.blob('a0025_new.xlsm')
res.headers['Content-Disposition'] = 'attachment; filename="a0025_new.xlsm"'
memo
Recommended Posts