コード例 #1
0
ファイル: xls2json_old.py プロジェクト: kobotoolbox/pyxform
 def _parse_input(self):
     if self.filetype == None:
         raise PyXFormError("File was not recognized")
     elif self.filetype == "xls":
         self._dict = xls_to_dict(self._file_object if self._file_object is not None else self._path)
     elif self.filetype == "csv":
         self._dict = csv_to_dict(self._file_object if self._file_object is not None else self._path)
     self._sheet_names = self._dict.keys()
     self._set_choices_and_columns_sheet_name()
     self._strip_unicode_values()
     self._fix_int_values()
     group_dictionaries(self._dict)
コード例 #2
0
 def _parse_input(self):
     if self.filetype == None:
         raise PyXFormError("File was not recognized")
     elif self.filetype == "xls":
         self._dict = xls_to_dict(self._file_object if self.
                                  _file_object is not None else self._path)
     elif self.filetype == "csv":
         self._dict = csv_to_dict(self._file_object if self.
                                  _file_object is not None else self._path)
     self._sheet_names = self._dict.keys()
     self._set_choices_and_columns_sheet_name()
     self._strip_unicode_values()
     self._fix_int_values()
     group_dictionaries(self._dict)
コード例 #3
0
ファイル: xls2json.py プロジェクト: bderenzi/pyxform
def parse_file_to_workbook_dict(path, file_object=None):
    """
    Given a xls or csv workbook file use xls2json_backends to create a python workbook_dict.
    workbook_dicts are organized as follows:
    {sheetname : [{column_header : column_value_in_array_indexed_row}]}
    """
    (filepath, filename) = os.path.split(path)
    if not filename:
        raise PyXFormError("No filename.")
    (shortname, extension) = os.path.splitext(filename)
    if not extension:
        raise PyXFormError("No extension.")

    if extension == ".xls" or extension == ".xlsx":
        return xls_to_dict(file_object if file_object is not None else path)
    elif extension == ".csv":
        return csv_to_dict(file_object if file_object is not None else path)
    else:
        raise PyXFormError("File was not recognized")
コード例 #4
0
def parse_file_to_workbook_dict(path, file_object=None):
    """
    Given a xls or csv workbook file use xls2json_backends to create
    a python workbook_dict.
    workbook_dicts are organized as follows:
    {sheetname : [{column_header : column_value_in_array_indexed_row}]}
    """
    (filepath, filename) = os.path.split(path)
    if not filename:
        raise PyXFormError("No filename.")
    (shortname, extension) = os.path.splitext(filename)
    if not extension:
        raise PyXFormError("No extension.")

    if extension == ".xls" or extension == ".xlsx":
        return xls_to_dict(file_object if file_object is not None else path)
    elif extension == ".csv":
        return csv_to_dict(file_object if file_object is not None else path)
    else:
        raise PyXFormError("File was not recognized")