0

I'm am converting .csv's to .xlsx. Everything is going well except I keep getting this enter image description here

This is my code:

def create_workbook(my_csv):
    wb = Workbook()
    ws = wb.active
    with open(my_csv, 'r') as f:
        for row in csv.reader(f):
            ws.append(row)
    wb.save(my_csv[:-4] + '.xlsx')
    f.close()

I am wondering if anyone has ran into something similar, and how they went about fixing it. I am looking for something more robust than just renaming the column if possible.

Mwspencer
  • 1,142
  • 3
  • 18
  • 35
  • Looks like a BOM. I'd try @Steve Lassop's suggestions: https://stackoverflow.com/questions/20899939/removing-bom-from-gziped-csv-in-python – DoDoSmarts Aug 24 '17 at 15:49
  • Thank you, the csv is from a SQL output, where I manually named the Headers. Are headers not always UTF-8 type with SQL output? – Mwspencer Aug 24 '17 at 15:58

1 Answers1

1

This is more appropriate as comment -- in re: "Are headers not always UTF-8 type with SQL output?"

The csvs from "SQL" are really specific to the interface defaults you're using to generate the file. Some scenarios:

  1. If you're using an IDE that has a 'output to csv' functionality then you'll want to see how to set the properties so that the output will be encoded in the form you want (i.e. utf-8).
  2. If you're using a command line in say MySQL you'll want try adding CHARACTER SET utf8 to force the output encoding. Might be a good idea to look at the SQL flavor docs for this one :)
DoDoSmarts
  • 306
  • 1
  • 6