You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`drf-excel` provides an Excel spreadsheet (xlsx) renderer for Django REST Framework. It uses OpenPyXL to create the spreadsheet and provide the file to the end user.
4
6
5
7
## Requirements
@@ -56,7 +58,7 @@ To upgrade to `drf_excel` 2.0.0 from `drf_renderer_xlsx`, update your import pat
*`xlsx_date_format_mappings` has been removed in favor of `column_data_styles` which provides more flexibility
58
60
59
-
## Configuring Styles
61
+
## Configuring Styles
60
62
61
63
Styles can be added to your worksheet header, column header row, body and column data from view attributes `header`, `column_header`, `body`, `column_data_styles`. Any arguments from [the OpenPyXL package](https://openpyxl.readthedocs.io/en/stable/styles.html) can be used for font, alignment, fill and border_side (border will always be all side of cell).
62
64
@@ -148,7 +150,7 @@ def get_header(self):
148
150
datetime_format ="%H:%M:%S %d.%m.%Y"
149
151
return {
150
152
'tab_title': 'MyReport', # title of tab/workbook
151
-
'use_header': True, # show the header_title
153
+
'use_header': True, # show the header_title
152
154
'header_title': 'Report from {} to {}'.format(
153
155
start_time.strftime(datetime_format),
154
156
end_time.strftime(datetime_format),
@@ -200,7 +202,7 @@ They can be set in the view as a property `sheet_view_options`:
200
202
```python
201
203
classMyExampleViewSet(serializers.Serializer):
202
204
sheet_view_options = {
203
-
'rightToLeft': True,
205
+
'rightToLeft': True,
204
206
'showGridLines': False
205
207
}
206
208
```
@@ -209,18 +211,18 @@ or using method `get_sheet_view_options`:
209
211
210
212
```python
211
213
classMyExampleViewSet(serializers.Serializer):
212
-
214
+
213
215
defget_sheet_view_options(self):
214
216
return {
215
-
'rightToLeft': True,
217
+
'rightToLeft': True,
216
218
'showGridLines': False
217
219
}
218
220
```
219
221
## Controlling XLSX headers and values
220
222
221
223
### Use Serializer Field labels as header names
222
224
223
-
By default, headers will use the same 'names' as they are returned by the API. This can be changed by setting `xlsx_use_labels = True` inside your API View.
225
+
By default, headers will use the same 'names' as they are returned by the API. This can be changed by setting `xlsx_use_labels = True` inside your API View.
224
226
225
227
Instead of using the field names, the export will use the labels as they are defined inside your Serializer. A serializer field defined as `title = serializers.CharField(label=_("Some title"))` would return `Some title` instead of `title`, also supporting translations. If no label is set, it will fall back to using `title`.
This package was created by the staff of [Wharton Research Data Services](https://wrds.wharton.upenn.edu/). We are thrilled that [The Wharton School](https://www.wharton.upenn.edu/) allows us a certain amount of time to contribute to open-source projects. We add features as they are necessary for our projects, and try to keep up with Issues and Pull Requests as best we can. Due to constraints of time (our full time jobs!), Feature Requests without a Pull Request may not be implemented, but we are always open to new ideas and grateful for contributions and our users.
341
+
This package is a member of [Django Commons](https://github.com/django-commons/) and adheres to the community's [Code of Conduct](https://github.com/django-commons/membership/blob/main/CODE_OF_CONDUCT.md). This package was created by the staff of [Wharton Research Data Services](https://wrds.wharton.upenn.edu/). We are thrilled that [The Wharton School](https://www.wharton.upenn.edu/) allows us a certain amount of time to contribute to open-source projects. We add features as they are necessary for our projects, and try to keep up with Issues and Pull Requests as best we can. Due to constraints of time (our full time jobs!), Feature Requests without a Pull Request may not be implemented, but we are always open to new ideas and grateful for contributions and our users.
0 commit comments