Provide Performance Platform report as Excel file

This is the format we need to upload it in, so this means not having to
manually re-save it as Excel.
This commit is contained in:
Chris Hill-Scott
2019-05-03 14:32:02 +01:00
parent 0508d4a1fc
commit 3c38a7be05
5 changed files with 38 additions and 20 deletions

View File

@@ -4,7 +4,7 @@ import re
import unicodedata
from datetime import datetime, time, timedelta, timezone
from functools import wraps
from io import StringIO
from io import BytesIO, StringIO
from itertools import chain
from os import path
from urllib.parse import urlparse
@@ -12,6 +12,7 @@ from urllib.parse import urlparse
import ago
import dateutil
import pyexcel
import pyexcel_xlsx
import yaml
from flask import abort, current_app, redirect, request, session, url_for
from flask_login import current_user
@@ -278,6 +279,20 @@ class Spreadsheet():
pyexcel.free_resources()
return instance
@property
def as_rows(self):
return list(csv.reader(
self.as_csv_data.strip().splitlines(),
quoting=csv.QUOTE_MINIMAL,
skipinitialspace=True,
))
@property
def as_excel_file(self):
io = BytesIO()
pyexcel_xlsx.save_data(io, {'Sheet 1': self.as_rows})
return io.getvalue()
def get_help_argument():
return request.args.get('help') if request.args.get('help') in ('1', '2', '3') else None