Skip to main content

Installation

Package installed as usually, with command

pip install xlsimport

package requires xlrd and dateutils.

Usage

Xlsimport provide only API for now, no demo nor default setup. But it’s simple to start using it.

First, you need to create descendant of xlsimport.models.Format class, for example:

class SubjectFormat(Format):
    cells = (
        {'name': 'Name', 'parsers': (TextCellToStringParser,)},
        {'name': 'Hours', 'parsers': (TextCellToIntParser, NumberCellToIntParser,)},
        {'name': 'Short name', 'parsers': (TextCellToStringParser,)},
    )

    def to_python(self, data_row):
        return {
            'name': data_row[0],
            'short_name': re.sub(r'[0-9-]+', '', data_row[2]),
            'hours': data_row[1],
        }

In this code Name column may contains only text cells and they are represented as strings. Second column Hours may contains text cells or number cells. They are represented as integers. Note that parsers applied with respect to order.

If you want to skip column, give parsers the value xlsimport.models.dummy_parsers. If cell must be empty there is blank_parsers value for that case.

Next you should make class that knows how to handle data (craate or update records). You also might want to place it into class like Django command.

Here’s my example:

...

class Command(BaseCommand):

    ...

    def handle(self, *args, **options):
        source_filename = args[0]
        source_file = open(source_filename, 'r')
        descriptor, name = tempfile.mkstemp()
        os.fdopen(descriptor, 'wb').write(source_file.read())
        doc = xlrd.open_workbook(name, formatting_info=True)
        format_doc = SubjectFormat(doc)

        for index, parsed_row in enumerate(format_doc):
            process_row(index, parsed_row)

process_row here is a function that takes dictionary from to_python method above.

Tip. I created a gist with nice example of linux dialog usage.

Metadata

Release files for xlsimport 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xlsimport 0.1
File Size Uploaded Provenance
xlsimport-0.1.tar.gz 4.6 kB Without provenance Details

Release files / xlsimport-0.1.tar.gz

Download URL xlsimport-0.1.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b61afc42f31b0c667f640fff92dcbd7119af2e255bfe3fa0a4e2f1085da1be5f
BLAKE2b-256 checksum
How to use checksums
4a08a1733df16b3ecae690a72eae02d4cb0fb31a6c14fbabb373861b8a1a0e48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for xlsimport 0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page