django-excel-response icon indicating copy to clipboard operation
django-excel-response copied to clipboard

Upgrading the output formatting?

Open gamesbook opened this issue 8 years ago • 3 comments

Any plans to upgrade the formatting options for the output? As a minimum, we would need row- or column-based options for formatting; width/height; colors (fore & back); fonts etc.

It would also be helpful to define sheet sections; header, body & footer into which data can be written (e.g. to handle column totals).

gamesbook avatar Jun 13 '17 06:06 gamesbook

I didn't have any solid plans at the moment, but that does sound like a solid idea. Do you have any kind of proposal for how this would work, perhaps what the API would look like?

This library started out to handle a very simple use case, so I didn't really have any of that in mind when I originally designed it. I would love to be able to produce more complex output though.

tarkatronic avatar Jun 13 '17 16:06 tarkatronic

I know your tool is based on openpyxl - I see there is good support for different formats: https://openpyxl.readthedocs.io/en/default/styles.html - but it might be possible to provide wrappers around this e.g. pass in a dictionary with styles to format single, or ranges of rows or columns for a given sheet e.g. as crude JSON:

{
	"styles": [{
		"sheet_name": "One",
		"formats": {
			"rows": [{
				"start": 0,
				"end": 2,
				"height": 2.0,
				"foreground": "red",
				"background": "blue",
				"pattern": "diagonal"
				},
				{
				"start": 3,
				"height": 3.0,
				"foreground": "blue",
				"pattern": "vertical",
				"font-weight": "italics"
			}],
			"cols": [{
				"start": 3,
				"width": 3.0,
				"font-color": "red",
				"font-weight": "bold",
				"font-size": 16
			}]
		}
	}]
}

(end is optional; if omitted, just apply to a single row/column)

One could get even fancier and allow formatting of individual cells (for example; it might be the one containing the Grand Total).

May also be useful to define a base style that applies to the whole sheet e.g. the default font name and size, or default row height.

Footnote: My primary tool is xlsxwriter (http://xlsxwriter.readthedocs.io/), so I am working with that now to set up a similar approach; would be useful to have a tool that can support both libraries!

gamesbook avatar Jun 14 '17 08:06 gamesbook

@gamesbook I'll try to put some thought into this. That looks like a good start for a proposal. I may not be able to get to implementing it immediately, but I'm always open to pull requests!

tarkatronic avatar Jun 16 '17 17:06 tarkatronic