def parse_store(cls, storefile): # try to load the given file via openpyxl # catch at least the BadZipFile exception if an unsupported # file has been given try: workbook = load_workbook(filename=storefile) worksheet = workbook.active except BadZipFile: return None, None output = StringIO() writer = csv.writer(output, dialect='unix') for row in worksheet.rows: writer.writerow([cell.value for cell in row]) if isinstance(storefile, str): name = os.path.basename(storefile) + ".csv" else: name = os.path.basename(storefile.name) + ".csv" # return the new csv as bytes content = output.getvalue().encode() # Load the file as CSV return super().parse_store(BytesIOMode(name, content))
def parse_store(cls, storefile): # try to load the given file via openpyxl # catch at least the BadZipFile exception if an unsupported # file has been given try: workbook = load_workbook(filename=storefile) worksheet = workbook.active except BadZipFile: return None, None output = six.StringIO() writer = csv.writer(output, dialect='unix') for row in worksheet.rows: writer.writerow([cell.value for cell in row]) if isinstance(storefile, six.string_types): name = os.path.basename(storefile) + ".csv" else: name = os.path.basename(storefile.name) + ".csv" # return the new csv as bytes content = output.getvalue().encode("utf-8") # Load the file as CSV return super(XlsxFormat, cls).parse_store(BytesIOMode(name, content))