turicas / rows

A common, beautiful interface to tabular data, no matter the format
GNU Lesser General Public License v3.0
869 stars 134 forks source link

[XLS] support file object #347

Open turicas opened 4 years ago

turicas commented 4 years ago

In Brasil.IO we needed to create the following function to open a XLS file from fobj:

import os
from pathlib import Path
from tempfile import NamedTemporaryFile
import rows

def import_xls(f_obj):
    content = f_obj.read()
    f_obj.seek(0)

    temp_xls = NamedTemporaryFile(suffix='.xls', delete=False)
    temp_xls.write(content)
    temp_xls.close()

    data = rows.import_from_xls(temp_xls)
    temp_file = Path(temp_xls.name)
    os.remove(temp_file)

    return data

We may support it automatically in rows too, so the plugin will have the same interface as the others.