JimboSlice
JimboSlice

Reputation: 692

Writing Excel to CSV file, how can I use another delimiter?

So im using the following script to export a excel file to csv.

import csv
import xlrd

workbook = xlrd.open_workbook('excel.xlsm')
for sheet in workbook.sheets():
    if sheet.name == "Database":
        with open('{}.csv'.format(sheet.name), 'wb') as f:
            writer = csv.writer(f)
            for row in range(sheet.nrows):
                out = []
                for cell in sheet.row_values(row):
                    if isinstance(cell, float):
                        out.append(cell)
                    else:
                        out.append(unicode(cell).encode('utf8'))
                writer.writerow(out)

So far everything it's working good. but I would like the csv file to be created with ; as a delimiter for each cell instead of the , How can I acheive this?

instead of cell1,cell2, I want the output to become cell1;cell2;

(Edit) Solution

set the delimiter when initiating csv.writer writer = csv.writer(f, delimiter=";")

Upvotes: 0

Views: 1250

Answers (1)

JimboSlice
JimboSlice

Reputation: 692

Found the answer, you can assign delimiter when initiating csv.writer

writer = csv.writer(f, delimiter=";")

Upvotes: 1

Related Questions