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
Copy file name to clipboardExpand all lines: docs/cells.adoc
+117-2Lines changed: 117 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,11 +8,29 @@ This module supports setting basic and custom types to cell values. The followin
8
8
* String
9
9
* Calendar
10
10
* Date
11
-
* Double
11
+
* Number
12
12
* Boolean
13
13
14
14
Support for additional types can be easily added without the need to convert your custom objects each time.
15
15
16
+
=== Underlying API
17
+
18
+
To get access to the Apache POI API for a given cell, simply store the return value of the `cell` method:
19
+
20
+
[source,groovy]
21
+
----
22
+
import org.apache.poi.xssf.usermodel.XSSFCell
23
+
24
+
ExcelBuilder.build {
25
+
sheet {
26
+
row {
27
+
XSSFCell customCell = cell("Foo")
28
+
//Modify customCell as needed
29
+
}
30
+
}
31
+
}
32
+
----
33
+
16
34
=== Custom Renderers
17
35
18
36
You can register a custom cell renderer to marshal your custom type into a type that is supported by Excel.
@@ -48,9 +66,27 @@ ExcelBuilder.build {
48
66
}
49
67
----
50
68
69
+
IMPORTANT: If a renderer is registered for a superclass, it will resolve for subclasses. If you wish to provide customized functionality for a subclass you can register a renderer for that class with a higher priority. The default is `-1`.
70
+
71
+
[source,groovy]
72
+
----
73
+
class Foo {
74
+
String name
75
+
}
76
+
class Bar extends Foo {
77
+
String title
78
+
}
79
+
80
+
Excel.registerCellRenderer(Foo) { it.name }
81
+
82
+
// With the current behavior, all values of type "Foo" or any subclass of "Foo" will be rendered with the "name" property. If you wish to override the rendering for a given type, you can specify another renderer with a higher priority.
83
+
84
+
Excel.registerCellRenderer(Bar, 0) { it.title }
85
+
----
86
+
51
87
=== Cell Styling
52
88
53
-
All calls to `cell` can be accompanied with a map of arguments to style the cell. The arguments passed will be merged with the default styles of the row and sheet, if provided
89
+
All calls to `cell` can be accompanied with a map of arguments to style the cell. The arguments passed will be merged with the default styles of the row and sheet, if provided.
54
90
55
91
[source,groovy]
56
92
----
@@ -67,4 +103,83 @@ ExcelBuilder.build {
67
103
68
104
See the section in this guide on link:#styles[styling cells] to learn what options are available.
69
105
106
+
=== Cell Formatting
107
+
108
+
It is not necessary for you to pre format your data before creating cells. You can apply a format to any given class and that format will be used when data of that type is written to a cell. There are several data types that are already configured. You can override that configuration and add your own.
109
+
110
+
The following classes to format mappings are created by default.
There are a list of built in formats you can reference by their index. The list is documented in a comment in the Apache POI {poiApiUrl}org/apache/poi/ss/usermodel/BuiltinFormats.html[BuiltinFormats] class.
141
+
142
+
To register one of the built in formats, simply use the `Integer` representation.
143
+
144
+
[source,groovy]
145
+
----
146
+
import com.jameskleeh.excel.Excel
147
+
148
+
Excel.registerCellFormat(Float, 10) // "0.00%"
149
+
----
150
+
151
+
In addition to providing global formats by class, you can also override the format for any given cell.
152
+
153
+
[source,groovy]
154
+
----
155
+
ExcelBuilder.build {
156
+
sheet {
157
+
row {
158
+
cell(0.105F, [format: 10])
159
+
}
160
+
}
161
+
}
162
+
----
163
+
164
+
The following result will be produced.
165
+
166
+
[width="15%"]
167
+
|=======
168
+
| |A
169
+
170
+
|*1* |10.50%
171
+
|=======
172
+
173
+
IMPORTANT: If a format is registered for a superclass, it will resolve for subclasses. If you wish to provide customized functionality for a subclass you can register a format for that class with a higher priority. The default is `-1`.
// With the current behavior, all Java 8 date types will be rendered with the supplied format. If you wish to override the format for a given type, you can specify another format with a higher priority.
Copy file name to clipboardExpand all lines: docs/formulas.adoc
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
1
[[formuals]]
2
2
== Formulas
3
3
4
-
The Groovy Excel Builder supports formulas in excel documents by providing an easy way to create formulas with support for helper methods to get cell references
4
+
The Groovy Excel Builder supports formulas in excel documents by providing an easy way to create formulas with support for helper methods to get cell references.
5
5
6
6
=== Simple String
7
7
8
-
You can specify the exact text of your formula using the example below
8
+
You can specify the exact text of your formula using the example below.
9
9
10
10
[source,groovy]
11
11
----
@@ -20,7 +20,7 @@ ExcelBuilder.build {
20
20
21
21
=== Closure Customization
22
22
23
-
An additional way to create a formula is to supply a closure to the `formula` method. The provided closure will have access to a few methods to make referencing cells easier. Whatever gets returned from the closure will be set as the formula
23
+
An additional way to create a formula is to supply a closure to the `formula` method. The provided closure will have access to a few methods to make referencing cells easier. Whatever gets returned from the closure will be set as the formula.
24
24
25
25
[source,groovy]
26
26
----
@@ -37,7 +37,7 @@ ExcelBuilder.build {
37
37
38
38
==== Exact Cell Reference
39
39
40
-
Inside of the forumla closure you can get a reference to an exact cell by providing the index of the row and column
40
+
Inside of the formula closure you can get a reference to an exact cell by providing the index of the row and column.
41
41
42
42
[source,groovy]
43
43
----
@@ -72,7 +72,7 @@ The first call to exact cell will return "A1" because the `foo` column is in col
72
72
73
73
==== Relative Cell References
74
74
75
-
In addition to retrieving exact cell references, you can also retrieve references relative to the formula
75
+
In addition to retrieving exact cell references, you can also retrieve references relative to the formula.
76
76
77
77
[source,groovy]
78
78
----
@@ -91,9 +91,9 @@ ExcelBuilder.build {
91
91
92
92
The first call to `relativeCell` will reference the cell in the previous column in the same row. In that example that would be "A2". The second call to `relativeCell` will resolve to "A1" because the first argument indicates to go back 1 column and the second argument says to go back one row. The formula will be put in cell "B2", so minus one column and minus one row would be "A1".
93
93
94
-
==== Anchoring Cells
94
+
=== Anchoring Cells
95
95
96
-
Once you have a reference to any cell, you can anchor the column or row or both
96
+
Once you have a reference to any cell, you can anchor the column or row or both.
Copy file name to clipboardExpand all lines: docs/gettingStarted.adoc
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,9 +21,11 @@ To get started using this great module, include it into your build:
21
21
compile '{groupId}:{artifactId}:{version}'
22
22
----
23
23
24
+
TIP: If you want to use a snapshot version, add the jfrog snapshot repository to your build: http://oss.jfrog.org/oss-snapshot-local. Normal releases are available in maven central and jcenter.
25
+
24
26
=== Creating your first Excel document
25
27
26
-
Here is the simplest example to create an Excel document
28
+
Here is the simplest example to create an Excel document:
Copy file name to clipboardExpand all lines: docs/rows.adoc
+20-3Lines changed: 20 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,24 @@
1
1
[[rows]]
2
2
== Rows
3
3
4
-
In addition to creating cells, there are also a few other methods available to you to make documents easier
4
+
In addition to creating cells, there are also a few other methods available to you to make documents easier.
5
+
6
+
=== Underlying API
7
+
8
+
To get access to the Apache POI API for a given row, simply receive an argument to the `row` closure:
9
+
10
+
[source,groovy]
11
+
----
12
+
import org.apache.poi.xssf.usermodel.XSSFRow
13
+
14
+
ExcelBuilder.build {
15
+
sheet {
16
+
row { XSSFRow myRow ->
17
+
//Modify myRow as needed
18
+
}
19
+
}
20
+
}
21
+
----
5
22
6
23
=== Defaults
7
24
@@ -34,7 +51,7 @@ ExcelBuilder.build {
34
51
}
35
52
----
36
53
37
-
The previous example will produce a document with "foo" in cell A1 and "bar" in D1
54
+
The previous example will produce a document with "foo" in cell A1 and "bar" in D1.
38
55
39
56
==== Skipping to a column
40
57
@@ -58,7 +75,7 @@ ExcelBuilder.build {
58
75
59
76
The example above will put the text "C2" in cell C2.
60
77
61
-
WARNING: The `skipTo` method will set the cell index so the next cell call will output data into the desired cell. Subsequent cells will start from that index. View the example below
78
+
WARNING: The `skipTo` method will set the cell index so the next cell call will output data into the desired cell. Subsequent cells will start from that index. View the example below:
Copy file name to clipboardExpand all lines: docs/sheets.adoc
+25-10Lines changed: 25 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,26 @@
1
1
[[sheets]]
2
2
== Sheets
3
3
4
-
With the Groovy Excel Builder, you can create documents with as many sheets as you like. In addition, there are several options you have at the sheet level for configuring your document
4
+
With the Groovy Excel Builder, you can create documents with as many sheets as you like. In addition, there are several options you have at the sheet level for configuring your document.
5
+
6
+
=== Underlying API
7
+
8
+
To get access to the Apache POI API for a given sheet, simply receive an argument to the `sheet` closure:
9
+
10
+
[source,groovy]
11
+
----
12
+
import org.apache.poi.xssf.usermodel.XSSFSheet
13
+
14
+
ExcelBuilder.build {
15
+
sheet { XSSFSheet mySheet ->
16
+
//Modify mySheet as needed
17
+
}
18
+
}
19
+
----
5
20
6
21
=== Sheet Name
7
22
8
-
You can configure what name you would like to give each sheet by executing the `sheet` method with a `String` argument
23
+
You can configure what name you would like to give each sheet by executing the `sheet` method with a `String` argument.
9
24
10
25
[source,groovy]
11
26
----
@@ -17,7 +32,7 @@ ExcelBuilder.build {
17
32
18
33
=== Defaults
19
34
20
-
You can configure defaults for column width and row height in a given sheet by passing a `Map` to the `sheet` method
35
+
You can configure defaults for column width and row height in a given sheet by passing a `Map` to the `sheet` method.
21
36
22
37
[source,groovy]
23
38
----
@@ -35,7 +50,7 @@ The width must be an `Integer` and the height can be a `Float` if you want to se
35
50
36
51
=== Styling
37
52
38
-
You can set default styles for a sheet by passing a map of options into the `defaultStyle` method. To see what options are available, visit the link:#styles[Styles] section of this document
53
+
You can set default styles for a sheet by passing a map of options into the `defaultStyle` method. To see what options are available, visit the link:#styles[Styles] section of this document.
39
54
40
55
[source,groovy]
41
56
----
@@ -48,7 +63,7 @@ ExcelBuilder.build {
48
63
49
64
=== Header Row
50
65
51
-
It is possible to define a header row and assign an identifier to each cell for later use
66
+
It is possible to define a header row and assign an identifier to each cell for later use.
52
67
53
68
[source,groovy]
54
69
----
@@ -62,11 +77,11 @@ ExcelBuilder.build {
62
77
}
63
78
----
64
79
65
-
In future rows, you can do things like skip to a given column or reference that column in a formula. The first argument is assigned to the cell value and the second argument is the unique identifier
80
+
In future rows, you can do things like skip to a given column or reference that column in a formula. The first argument is assigned to the cell value and the second argument is the unique identifier.
66
81
67
82
=== Creating Rows
68
83
69
-
You can easily create rows with the following syntax
84
+
You can easily create rows with the following syntax:
70
85
71
86
[source,groovy]
72
87
----
@@ -90,11 +105,11 @@ ExcelBuilder.build {
90
105
}
91
106
----
92
107
93
-
To reference everything you can do in a row, see the section in the documentation on link:#rows[Rows]
108
+
To reference everything you can do in a row, see the section in the documentation on link:#rows[Rows].
94
109
95
110
=== Skipping Rows
96
111
97
-
It is very easy to skip any number of rows. See the following example
112
+
It is very easy to skip any number of rows. See the following example:
98
113
99
114
[source,groovy]
100
115
----
@@ -107,7 +122,7 @@ ExcelBuilder.build {
107
122
}
108
123
----
109
124
110
-
The above example will produce a sheet that looks something like this
125
+
The above example will produce a sheet that looks something like this:
0 commit comments