def setUp(self): r = Reader("fods") r.reader_class = ODSBook r.open(os.path.join("tests", "fixtures", "ods_formats.ods")) self.data = r.read_all() for key in self.data.keys(): self.data[key] = list(self.data[key]) r.close()
def setUp(self): with open(os.path.join("tests", "fixtures", "ods_formats.fods"), "rb") as f: r = Reader("fods") r.reader_class = FODSBook r.open_stream(f) self.data = r.read_all() for key in self.data.keys(): self.data[key] = list(self.data[key]) r.close()
def setUp(self): r = Reader("fods") r.reader_class = ODSBook r.open(os.path.join("tests", "fixtures", "ods_formats.ods")) self.data1 = r.read_all() r.close() self.testfile = "odswriter.ods" w = Writer("ods") w.writer_class = ODSWriter w.open(self.testfile) w.write(self.data1) w.close() r.open(self.testfile) self.data = r.read_all() for key in self.data.keys(): self.data[key] = list(self.data[key]) r.close()
def setUp(self): r = Reader("ods") r.open( os.path.join("tests", "fixtures", "ods_formats.ods"), skip_empty_rows=True, ) self.data1 = r.read_all() r.close() self.testfile = "odswriter.ods" w = ODSWriter(self.testfile, "ods") w.write(self.data1) w.close() r.open(self.testfile) self.data = r.read_all() for key in self.data.keys(): self.data[key] = list(self.data[key]) r.close()
def load_data(file_name=None, file_content=None, file_stream=None, file_type=None, force_file_type=None, sheet_name=None, sheet_index=None, sheets=None, library=None, streaming=False, **keywords): """Load data from any supported excel formats :param filename: actual file name, a file stream or actual content :param file_type: used only when filename is not a physial file name :param force_file_type: used only when filename refers to a physical file and it is intended to open it as forced file type. :param sheet_name: the name of the sheet to be loaded :param sheet_index: the index of the sheet to be loaded :param keywords: any other parameters """ result = {} inputs = [file_name, file_content, file_stream] number_of_none_inputs = [x for x in inputs if x is not None] if len(number_of_none_inputs) != 1: raise IOError(constants.MESSAGE_ERROR_02) if file_type is None: if force_file_type: file_type = force_file_type else: try: file_type = file_name.split(".")[-1] except AttributeError: raise Exception(constants.MESSAGE_FILE_NAME_SHOULD_BE_STRING) try: reader = OLD_READERS.get_a_plugin(file_type, library) except (NoSupportingPluginFound, SupportingPluginAvailableButNotInstalled): reader = Reader(file_type, library) try: if file_name: reader.open(file_name, **keywords) elif file_content: reader.open_content(file_content, **keywords) elif file_stream: reader.open_stream(file_stream, **keywords) else: raise IOError("Unrecognized options") if sheet_name: result = reader.read_sheet_by_name(sheet_name) elif sheet_index is not None: result = reader.read_sheet_by_index(sheet_index) elif sheets is not None: result = reader.read_many(sheets) else: result = reader.read_all() if streaming is False: for key in result.keys(): result[key] = list(result[key]) reader.close() reader = None return result, reader except NoSupportingPluginFound: if file_name: if os.path.exists(file_name): if os.path.isfile(file_name): raise else: raise IOError(constants.MESSAGE_NOT_FILE_FORMATTER % file_name) else: raise IOError(constants.MESSAGE_FILE_DOES_NOT_EXIST % file_name) else: raise