0

I have a CSV that has bold text on all of the first columns. I wanted to sanitize it first since now it failed to get the row I wanted to get.

I tried printing the row in before_import_row and this is how it looks like.

('\ufeffaccount_number', '000-152-1808')

n0minal
  • 3,195
  • 9
  • 46
  • 71

1 Answers1

0

It is possible using dynamic columns in tablib. Add a callable which returns the unsanitized column value, and then add it to a new column.

def accno_cleaned(row):
    return '\ufeffaccount_number'

def before_import(self, dataset, using_transactions, dry_run, **kwargs):
    dataset.append_col(accno_cleaned, header='account_number')

However I think it might be better to sanitize the data before it gets imported into django-import-export if you can because this will be easier to maintain in the long run.

Matthew Hegarty
  • 3,791
  • 2
  • 27
  • 42
  • I'll accept this thank you, but I fixed my issue by following this https://stackoverflow.com/questions/17912307/u-ufeff-in-python-string/17912811#17912811, basically changing the decode from UTF-8 to utf-8-sig – n0minal Jul 14 '21 at 08:14