mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 10:53:28 -05:00
Force xlsm files to open with pyexcel-xlsx
`.xlsm` files are like `.xlxs` files but with macros enabled. They store data in the same XML-based format as `.xlsx` files. Pyexcel will try to use the xlrd package to parse `.xlsm` files. This used to work because xlrd used to support reading `.xlsx` files. xlrd has dropped support for `.xlsx` files in version 2 because of security concerns. This means that when pyexcel asks xlrd to parse a `.xlsm` file it causes an error. This commit adds some branching to force `.xlsm` files to be opened with pyexcel-xlsx instead, which does support `.xlsx` files.
This commit is contained in:
@@ -3,6 +3,7 @@ from io import StringIO
|
||||
from os import path
|
||||
|
||||
import pyexcel
|
||||
import pyexcel_xlsx
|
||||
|
||||
|
||||
class Spreadsheet():
|
||||
@@ -72,6 +73,15 @@ class Spreadsheet():
|
||||
file_content = StringIO(
|
||||
Spreadsheet.normalise_newlines(file_content))
|
||||
|
||||
if extension == 'xlsm':
|
||||
file_data = pyexcel_xlsx.get_data(file_content)
|
||||
instance = cls.from_rows(
|
||||
# Get the first sheet from the workbook
|
||||
list(file_data.values())[0],
|
||||
filename,
|
||||
)
|
||||
return instance
|
||||
|
||||
instance = cls.from_rows(
|
||||
pyexcel.iget_array(
|
||||
file_type=extension,
|
||||
|
||||
Reference in New Issue
Block a user