csvtotable icon indicating copy to clipboard operation
csvtotable copied to clipboard

Added support for excel

Open Aderlx opened this issue 6 years ago • 2 comments

Hello @vividvilla ,Your project is perfect!,but,I think added support excel maybe better. so, I use pandas and numpy to read file,As you can see.

def read_file(input_file_name):
    import pandas as pd
    import numpy as np
    suffix = os.path.splitext(input_file_name)[1]
    if not suffix:
        if six.PY2:
            suffix = raw_input('please enter file type.(csv、excel):\t')
        else:
            suffix = input('please enter file type.(csv、excel):\t')
    if 'csv' in suffix:
        df = pd.read_csv(input_file_name)
    else:
        df = pd.read_excel(input_file_name)
    headers = [i for i in df.columns]
    rows = np.array(df).tolist()
    if not headers and len(rows) > 0:
        end = len(headers) + 1
        headers = ["Column {}".format(n) for n in range(1, end)]
    return headers, rows

what are you think?

Aderlx avatar Aug 10 '18 07:08 Aderlx

an excel variant exists already: https://github.com/pyexcel/excel2table.

chfw avatar Aug 19 '18 07:08 chfw

excel2table 2.3.0 is out.

chfw avatar Mar 16 '19 11:03 chfw