Skip to content

Commit

Permalink
Merge pull request #147 from kobotoolbox/146-fix-xlsform-import
Browse files Browse the repository at this point in the history
Update pandas syntax for importing XLS
  • Loading branch information
jnm authored Sep 29, 2021
2 parents c9fe2bf + 9ef5948 commit ab8288b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies:
- djangorestframework==3.12.4
- gunicorn==20.1.0
- huey==2.3.2
- openpyxl==3.0.9
- psycopg2==2.8.6
- sentry-sdk==1.0.0
- requests==2.25.1
Expand Down
23 changes: 19 additions & 4 deletions equitytool/xls2csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,27 @@
class Converter(object):

def set_excel(self, io):
self.sheets = pd.read_excel(io, sheetname=None)
# "Specify None to get all sheets"
# https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_excel.html
self.sheets = pd.read_excel(io, sheet_name=None)

def set_settings(self, **kwargs):
settings = self.sheets['settings']
for k, v in kwargs.items():
settings[k][0] = v
"""
Add settings from kwargs to the XLSForm settings sheet, overwriting
any existing settings with the same names
"""

try:
settings = self.sheets['settings']
except KeyError:
# No settings sheet exists yet; make a new one
self.sheets['settings'] = pd.DataFrame.from_dict(
{k: [v] for k, v in kwargs.items()}
)
else:
# Update existing settings sheet
for k, v in kwargs.items():
settings[k][0] = v

def get_csv(self):
result = ''
Expand Down

0 comments on commit ab8288b

Please sign in to comment.