Skip to content
Permalink
Browse files

Merge pull request #2314 from dvbridges/xlsmRead

BF: Allow .xlsm files to be read using importConditions()
  • Loading branch information...
peircej committed Feb 27, 2019
2 parents 38412bf + d4fa018 commit 9e11bfd614867763d8c1213e1165ef054ddf76cf
Showing with 12 additions and 4 deletions.
  1. +12 −4 psychopy/data/utils.py
@@ -270,7 +270,7 @@ def pandasToDictList(dataframe):
trialList.append(thisTrial)
return trialList, fieldNames

if fileName.endswith('.csv') or (fileName.endswith(('.xlsx','.xls'))
if fileName.endswith('.csv') or (fileName.endswith(('.xlsx','.xls','.xlsm'))
and haveXlrd):
if fileName.endswith('.csv'):
trialsArr = pd.read_csv(fileName, encoding='utf-8-sig')
@@ -284,7 +284,7 @@ def pandasToDictList(dataframe):
logging.debug(u"Clearing unnamed columns from {}".format(fileName))
trialList, fieldNames = pandasToDictList(trialsArr)

elif fileName.endswith('.xlsx'):
elif fileName.endswith(('.xlsx','.xlsm')):
if not haveOpenpyxl:
raise ImportError('openpyxl or xlrd is required for loading excel '
'files, but neither was found.')
@@ -309,7 +309,11 @@ def pandasToDictList(dataframe):
# get parameter names from the first row header
fieldNames = []
for colN in range(nCols):
fieldName = ws.cell(_getExcelCellName(col=colN, row=0)).value
if parse_version(openpyxl.__version__) < parse_version('2.0'):
fieldName = ws.cell(_getExcelCellName(col=colN, row=0)).value
else:
# From 2.0, cells are referenced with 1-indexing: A1 == cell(row=1, column=1)
fieldName = ws.cell(row=1, column=colN + 1).value
fieldNames.append(fieldName)
_assertValidVarNames(fieldNames, fileName)

@@ -318,7 +322,11 @@ def pandasToDictList(dataframe):
for rowN in range(1, nRows): # skip header first row
thisTrial = {}
for colN in range(nCols):
val = ws.cell(_getExcelCellName(col=colN, row=rowN)).value
if parse_version(openpyxl.__version__) < parse_version('2.0'):
val = ws.cell(_getExcelCellName(col=colN, row=0)).value
else:
# From 2.0, cells are referenced with 1-indexing: A1 == cell(row=1, column=1)
val = ws.cell(row=rowN + 1, column=colN + 1).value
# if it looks like a list or tuple, convert it
if (isinstance(val, basestring) and
(val.startswith('[') and val.endswith(']') or

0 comments on commit 9e11bfd

Please sign in to comment.
You can’t perform that action at this time.