Skip to content

This is a python package for exporting Django data to Excel file with included admin integration.

License

Notifications You must be signed in to change notification settings

AzikDeveloper/django-export-excel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-export-excel

Django package for exporting data to Excel file with included admin integration. Note that this is not a django app.

This package uses xlwt. Which means max 65535 rows in a file 😌.

Usage

Creating Table class

class UserTable(Table):
    id = Column(header_name="ID", width=20)
    name = Column(header_name="Name", width=20)
    birth_date = Column(width=20)
    favorite_songs = Column(width=50, attr="get_favorite_songs")

    class Meta(TableMeta):
        model = User
        columns = [
            "id",
            "name",
            "birth_date",
            "favorite_songs"
        ]
        header_style = Style(bold=True, font_size=20, height=50, background_color=colors.SEA_GREEN,
                             font_color=colors.WHITE)
        row_style = Style(bold=False, font_size=20, height=20)
        none_text = "-"

Creating Exporter class

class UserExcelExporter(ModelExcelExporter):
    table_class = UserTable
    file_name = "users"
    sheet_name = "main"
    style_compression = 2
    include_row_number = True

Generating excel

exporter = UserExcelExporter()
exporter.generate(queryset=User.objects.all())
exporter.save()

Result

alt text

Django Admin integration

  1. Subclass from ExportActionMixin and django admin's ModelAdmin.
  2. Define your exporter class with excel_exporter_class attribute in your model admin

About

This is a python package for exporting Django data to Excel file with included admin integration.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages