def _parse_survey(workbook: xlrd.Book) -> Survey: """Parse the survey for the ODK form. Args: workbook: The xlrd book object Returns: A Survey object """ try: sheet = workbook.sheet_by_name('survey') return Survey(sheet, workbook.datemode) except xlrd.biffh.XLRDError: msg = 'XlsForm file does not have required "survey" tab!' raise OdkFormError(msg)
def _parse_settings(path: str, workbook: xlrd.Book) -> Settings: """Parse the settings for the ODK form. Args: path: The path to where the XlsForm is stored workbook: The xlrd book object Returns: A Settings object """ sheet = None try: sheet = workbook.sheet_by_name('settings') except xlrd.biffh.XLRDError: pass return Settings(path, sheet, workbook.datemode)
def parse_choices_from_sheet(workbook: xlrd.Book, sheet_name: str) -> ChoiceListTab: """Parse choices from a choice sheet. Args: workbook: The xlrd book object sheet_name: The sheet name to parse as a choice sheet Returns: A ChoiceListTab representing the specified sheet """ sheet = None try: sheet = workbook.sheet_by_name(sheet_name) except xlrd.biffh.XLRDError: pass return ChoiceListTab(sheet, workbook.datemode)
def get_sheet_by_index_or_name(workbook: xlrd.Book, sheet_name_or_index): if type(sheet_name_or_index) == int: sheet = workbook.sheet_by_index(sheet_name_or_index) else: sheet = workbook.sheet_by_name(sheet_name_or_index) return sheet
def get_sheet_by_name(workbook: xlrd.Book, sheet_name: str): sheets = ExcelHandler.get_sheet_by_index_or_name(workbook, sheet_name) sheet = workbook.sheet_by_name(sheet_name) return sheet