Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pandas syntax for importing XLS #147

Merged
merged 2 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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