def csv(args):
    """
    %prog csv excelfile

    Convert EXCEL to csv file.
    """
    from xlrd import open_workbook

    p = OptionParser(csv.__doc__)
    p.set_sep(sep=',')
    opts, args = p.parse_args(args)

    if len(args) != 1:
        sys.exit(not p.print_help())

    excelfile, = args
    sep = opts.sep
    csvfile = excelfile.rsplit(".", 1)[0] + ".csv"
    wb = open_workbook(excelfile)
    fw = open(csvfile, "w")
    for s in wb.sheets():
        print('Sheet:',s.name, file=sys.stderr)
        for row in range(s.nrows):
            values = []
            for col in range(s.ncols):
                values.append(s.cell(row, col).value)
            print(sep.join(str(x) for x in values), file=fw)
def csv ( args ) : from xlrd import open_workbook p = OptionParser ( csv . __doc__ ) p . set_sep ( sep = ',' ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) excelfile , = args sep = opts . sep csvfile = excelfile . rsplit ( "." , 1 ) [ 0 ] + ".csv" wb = open_workbook ( excelfile ) fw = open ( csvfile , "w" ) for s in wb . sheets ( ) : print ( 'Sheet:' , s . name , file = sys . stderr ) for row in range ( s . nrows ) : values = [ ] for col in range ( s . ncols ) : values . append ( s . cell ( row , col ) . value ) print ( sep . join ( str ( x ) for x in values ) , file = fw )
%prog csv excelfile

    Convert EXCEL to csv file.