Merge pull request #4086 from alphagov/small-spreadsheet-refactor-177535141

Small refactoring to the Spreadsheet class
This commit is contained in:
Ben Thorner
2021-12-07 16:59:46 +00:00
committed by GitHub
3 changed files with 45 additions and 61 deletions

View File

@@ -1,9 +1,8 @@
import csv
from io import BytesIO, StringIO
from io import StringIO
from os import path
import pyexcel
import pyexcel_xlsx
class Spreadsheet():
@@ -87,19 +86,3 @@ class Spreadsheet():
form.file.data,
filename=form.file.data.filename,
)
@property
def as_rows(self):
if not self._rows:
self._rows = list(csv.reader(
StringIO(self._csv_data),
quoting=csv.QUOTE_MINIMAL,
skipinitialspace=True,
))
return self._rows
@property
def as_excel_file(self):
io = BytesIO()
pyexcel_xlsx.save_data(io, {'Sheet 1': self.as_rows})
return io.getvalue()