vividvilla / csvtotable

Simple command-line utility to convert CSV files to searchable and sortable HTML table.
MIT License
1.12k stars 116 forks source link

Added support for excel #30

Open Aderlx opened 6 years ago

Aderlx commented 6 years ago

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?

chfw commented 6 years ago

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

chfw commented 5 years ago

excel2table 2.3.0 is out.