Skip to content

Commit f8245db

Browse files
1 parent d30e7f6 commit f8245db

File tree

6 files changed

+51
-51
lines changed

6 files changed

+51
-51
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export-*
2+
install_*

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
language: groovy
2+
jdk:
3+
- oraclejdk8
4+
- openjdk8
5+
- oraclejdk7
6+
- openjdk7
7+
script:
8+
- jdk_switcher use oraclejdk8
9+
- jdk_switcher use openjdk8
10+
- jdk_switcher use oraclejdk7
11+
- jdk_switcher use openjdk7

ExportGrailsPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import org.apache.commons.logging.LogFactory
22

33
class ExportGrailsPlugin {
44
// the plugin version
5-
def version = "1.7-2.0.0-4"
5+
def version = "1.7-2.0.0-5"
66
// the version or versions of Grails the plugin is designed for
77
def grailsVersion = "1.3 > *"
88
// the other plugins this plugin depends on (use /grails-app/conf/BuildConfig.groovy instead!)

README.md

Lines changed: 34 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,55 +18,41 @@ A new branch will be spawned for every upgrade of base line (if it ever happens
1818

1919
What are the new features?
2020
-----------
21-
1.7-2.0.0-4:
22-
- All existing ExcelFormat constructors now handle formatters as well:
21+
1.7-2.0.0-5:
22+
- Back compatibility with original v1.6 in general but...
23+
- I see no reason why column autosizing is not turned-on by default: it perfectly resizes small columns, and doesn't resize large columns too much. So it's turned-on by default now.
24+
- multiple sheets (only Excel implemented for now):
2325
```groovy
24-
new ExcelFormat(..., { domain, value -> ... })
25-
```
26-
1.7-2.0.0-3:
27-
- Chained header and column formatting, like
28-
```groovy
29-
def cellFormat = (new ExcelFormat()).TAHOMA().bold().noBold().struckout().VIOLET().italic().pointSize(10).wrapText().CENTRE().TOP().MINUS_45().backColor(Colour.AQUA).MIDDLE()
30-
```
31-
It is possible to set that format for all headers ``"header.format":format`` and/or individually ``"header.formats": [1:column1headerFormat,5:column5headerFormat]``
32-
- Change column size individually ``"column.widths": [null, 40]`` - here we set it only for second one, the rest will be autosized.
33-
- format can handle cell value type (currency bundles text formatter as well!):
34-
```groovy
35-
def textFormat = new ExcelFormat()
36-
def currencyFormat = new ExcelFormat(NumberFormats.ACCOUNTING_FLOAT)
37-
def dateTimeFormat = new ExcelFormat(DateFormats.FORMAT9)
38-
dateTimeFormat.setFormatter { domain, value -> ... }
39-
```
40-
- new interface to handle multiple sheets (only Excel implemented for now):
41-
```groovy
42-
Map sheets = ['first sheet title': [fields: fields, labels: labels, rows: rows1,
26+
Map labels = ['someFieldName':'Some Field Name']
27+
List fields = ['someFieldName']
28+
Map sheets = ['first sheet title': [fields: fields, labels: labels, rows: listWithYourData,
4329
"column.formats": [ someFieldName: (new ExcelFormat()).TIMES() ]]
44-
'another sheet': [rows:rows2]]
30+
'another sheet': [rows: listWithOtherPageData]]
4531
4632
exportService.export(mimeType, response, sheets)
4733
// OR
4834
//setupResponse(type, response, filename, extension)
4935
//exportService.export(mimeType, response.outputStream, sheets)
36+
// Old style still works fine, if someone still uses it:
37+
// response.contentType = Holders.config.grails.mime.types[params.exportFormat]
38+
// response.setHeader("Content-disposition", "attachment; filename=test.xls")
39+
// exportService.export('excel', response.outputStream, myRows, fields, labels, formatters, parameters)
5040
```
51-
- added ```import groovy.util.logging.Log4j``` annotation
5241

53-
2.1.7-2.0.0-2:
54-
- I see no reason why column autosizing is not turned-on by default: it perfectly resizes small columns, and doesn't resize large columns too much. So it's on by default now. To disable it set ``Map parameters=['column.width.autoSize':false]``
55-
- supports column formating. Here is a quick example how to assign "currency" type to a column:
42+
- Columns can be fancy and handle native formating. Here are some more examples:
5643
```groovy
57-
Map labels = ['paymentAmt':'Payment Amount']
58-
List fields = ['paymentAmt']
59-
Map parameters = ['column.formats': ['paymentAmt': new WritableCellFormat(NumberFormats.ACCOUNTING_FLOAT)]]
60-
def formatters = ['paymentAmt' : { domain, value ->
61-
String strVal = "${value}".replace('fr.','').replaceAll(/[^\d.]/,'')
62-
return new BigDecimal(strVal?:'0')
63-
}
64-
]
65-
List myRows = [['paymentAmt':'$9,876.5432'], ['paymentAmt':'$1,234.5678']]
66-
response.contentType = Holders.config.grails.mime.types[params.exportFormat]
67-
response.setHeader("Content-disposition", "attachment; filename=test.xls")
68-
exportService.export('excel', response.outputStream, myRows, fields, labels, formatters, parameters)
44+
def textFormat = new ExcelFormat()
45+
def currencyFormat = new ExcelFormat(NumberFormats.ACCOUNTING_FLOAT)
46+
def dateTimeFormat = new ExcelFormat(DateFormats.FORMAT9)
47+
dateTimeFormat.setFormatter { domain, value -> ... }
48+
def sameInOneLine = new ExcelFormat(DateFormats.FORMAT9, { domain, value -> ... })
49+
def fancyFormat = (new ExcelFormat()).TAHOMA().bold().noBold().struckout().VIOLET().italic().pointSize(10).wrapText().CENTRE().TOP().MINUS_45().backColor(Colour.AQUA).MIDDLE()
6950
```
51+
It is possible to set that format for all headers ``"header.format":format`` and/or individually ``"header.formats": [1:column1headerFormat,5:column5headerFormat]``
52+
- Change column size individually ``"column.widths": [null, 40]`` - here we set it only for second one, the rest will be autosized.
53+
- To disable autosizing set ``'column.width.autoSize':false``
54+
- Using Log4j
55+
7056
1.7-2.0.0-1:
7157
- initial merge of 1.7 and 2.0.0
7258
- bug: Column autosize applies on size() of rows instead of columns [#28](https://github.com/gpc/export/pull/28)
@@ -85,47 +71,47 @@ cancel once you see it... or wait for build to fail due to missing plugin.
8571
- Stop grails;
8672
- Add new plugin to your BuildConfig.groovy normally:
8773
```groovy
88-
compile (':export:1.7-2.0.0-4') {
74+
compile (':export:1.7-2.0.0-5') {
8975
excludes 'bcprov-jdk14', 'bcmail-jdk14' // to support birt-report:4.3 dependency hell
9076
}
9177
```
92-
- Download and run "install_plugin_export.bat" [from latest release](https://github.com/SquareGearsLogic/export/releases/tag/1.7-2.0.0-4);
78+
- Download and run "install_plugin_export.bat" [from latest release](https://github.com/SquareGearsLogic/export/releases/tag/1.7-2.0.0-5);
9379
- Run grails. It may prompt you for plugin upgrade - say yes.
9480

9581
**Option 2)** manually install zip into local maven repository and install plugin from there, like you normally do:
9682

97-
- Get .zip and .pom files [from latest release](https://github.com/SquareGearsLogic/export/releases/tag/1.7-2.0.0-4)
83+
- Get .zip and .pom files [from latest release](https://github.com/SquareGearsLogic/export/releases/tag/1.7-2.0.0-5)
9884
- If you running Grails < v2.3 you can use
9985
```
10086
grails install-plugin
10187
```
10288

10389
If you running Grails between v2.3 and 3.0, you should use maven itself:
10490
```
105-
mvn install:install-file -Dfile=export-1.7-2.0.0-4.zip -DgroupId=org.grails.plugins -DartifactId=export -Dversion=1.7-2.0.0-4 -Dpackaging=zip
91+
mvn install:install-file -Dfile=export-1.7-2.0.0-5.zip -DgroupId=org.grails.plugins -DartifactId=export -Dversion=1.7-2.0.0-5 -Dpackaging=zip
10692
```
10793
- Go to folder
10894
```
109-
Linux: ~/.m2/repository/org/grails/plugins/export/1.7-2.0.0-4/
110-
Windows: %HOMEPATH%\.m2\repository\org\grails\plugins\export\1.7-2.0.0-4\
95+
Linux: ~/.m2/repository/org/grails/plugins/export/1.7-2.0.0-5/
96+
Windows: %HOMEPATH%\.m2\repository\org\grails\plugins\export\1.7-2.0.0-5\
11197
```
11298
and replace pom file with the one from release (If anyone knows how to integrate pom into zip - please let me know).
11399

114100
- Add new plugin to your BuildConfig.groovy normally:
115101
```groovy
116-
compile (':export:1.7-2.0.0-4') {
102+
compile (':export:1.7-2.0.0-5') {
117103
excludes 'bcprov-jdk14', 'bcmail-jdk14' // to support birt-report:4.3 dependency hell
118104
}
119105
```
120106
- Run grails. It may prompt you for plugin upgrade - say yes.
121107

122108
**Option 3)** manual local/dev installation without maven:
123109

124-
- Get only .zip file [from latest release](https://github.com/SquareGearsLogic/export/releases/tag/1.7-2.0.0-4)
125-
and simply unzip to ```PROJECT_DIR/.grails/projects/cwa/plugins/export-1.7-2.0.0-4/```
110+
- Get only .zip file [from latest release](https://github.com/SquareGearsLogic/export/releases/tag/1.7-2.0.0-5)
111+
and simply unzip to ```PROJECT_DIR/.grails/projects/cwa/plugins/export-1.7-2.0.0-5/```
126112
- add line somewhere at the top of your BuildConfig.groovy, outside of plugins scope:
127113
```
128-
grails.plugin.location.export="PROJECT_DIR/.grails/projects/cwa/plugins/export-1.7-2.0.0-4"
114+
grails.plugin.location.export="PROJECT_DIR/.grails/projects/cwa/plugins/export-1.7-2.0.0-5"
129115
```
130116
- Run grails.
131117
- For any dependency issues see BuildConfig.groovy in plugin directory.

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<plugin name='export' version='1.7-2.0.0-4' grailsVersion='1.3 &gt; *'>
1+
<plugin name='export' version='1.7-2.0.0-5' grailsVersion='1.3 &gt; *'>
22
<author>Grails Plugin Collective</author>
33
<authorEmail>[email protected]</authorEmail>
44
<title>Export Plugin</title>

src/groovy/de/andreasschmitt/export/exporter/DefaultExcelExporter.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ class DefaultExcelExporter extends AbstractExporter {
4646
}
4747

4848
String title = getParameters().get("title")
49+
Map labels = fields.collectEntries{[it,getLabel(it)]}
4950
builder {
5051
workbook(outputStream: outputStream) {
51-
processSheet(getDelegate() as ExcelBuilder, title, data, fields,
52+
processSheet(getDelegate() as ExcelBuilder, title, data, fields, labels,
5253
isHeaderEnabled, useZebraStyle, widthAutoSize, maxPerSheet, getParameters())
5354
}
5455
}

0 commit comments

Comments
 (0)