Skip to content

depaolim/django-xlsx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Xlsx

Xlsx is a simple Django app to import/export xlsx files to models

Detailed documentation is in the "docs" directory.

Quick start

Suppose you have an xlsx:

CUSTOMER FIRST NAME CUSTOMER SURNAME
John Black
Jack Red
Tom Green

and want to load the data into MyModel

MyModel should have an XLSX_2_FIELDS attribute to remap column-names to field-names

class MyModel(models.Model):
    name = models.CharField(max_length=50)
    surname = models.CharField(max_length=50)

    XLSX_2_FIELDS = {
        "CUSTOMER FIRST NAME": name,
        "CUSTOMER SURNAME": surname,
    }

now you can load...

import openpyxl as pyx
import xlsx

wb = pyx.load_workbook("sample.xslsx")
xlsx.load(MyModel, wb.active.rows)

You can specify an optional preprocessor as 3rd parameter to the "load" function This can be usefull to adjust some fields before inserting to db

About

Django: import/export of Excel xlsx files

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages