Skip to content

Commit 3242088

Browse files
committed
Added ability to specify font size and name
1 parent e1f34d5 commit 3242088

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

docs/styles.adoc

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ You can also specify the font color:
2929

3030
[source,groovy]
3131
----
32-
import com.jameskleeh.excel.Font
3332
import java.awt.Color
3433
3534
...
@@ -39,6 +38,24 @@ cell("A", [font: [bold: true, color: Color.RED])
3938

4039
TIP: Any option that expects a color supports colors specified by an instance of java.awt.Color or the string hex value ("#FFFFFF")
4140

41+
The font size can also be specified:
42+
43+
[source,groovy]
44+
----
45+
...
46+
cell("A", [font: [size: 12.5])
47+
...
48+
----
49+
50+
The font name can be set as well:
51+
52+
[source,groovy]
53+
----
54+
...
55+
cell("A", [font: [name: "Arial"])
56+
...
57+
----
58+
4259
=== Hidden
4360

4461
Cells can be hidden by passing the `hidden` argument:
@@ -250,10 +267,10 @@ If you have a fill pattern set, the `foregroundColor` attribute will set the for
250267

251268
[source,groovy]
252269
----
270+
import java.awt.Color
271+
253272
...
254273
cell("A", [foregroundColor: "#000000"])
255-
256-
// or as a java.awt.Color
257274
cell("B", [foregroundColor: Color.BLACK])
258275
...
259276
----
@@ -264,10 +281,10 @@ To set the background color of a cell, use the `backgroundColor` argument:
264281

265282
[source,groovy]
266283
----
284+
import java.awt.Color
285+
267286
...
268287
cell("A", [backgroundColor: "#000000"])
269-
270-
// or as a java.awt.Color
271288
cell("B", [backgroundColor: Color.BLACK])
272289
...
273290
----

src/main/groovy/com/jameskleeh/excel/CellStyleBuilder.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class CellStyleBuilder {
6868
protected static final String FONT_STRIKEOUT = 'strikeout'
6969
protected static final String FONT_UNDERLINE = 'underline'
7070
protected static final String FONT_COLOR = 'color'
71+
protected static final String FONT_NAME = 'name'
72+
protected static final String FONT_SIZE = 'size'
7173
protected static final String FILL = 'fill'
7274
protected static final String BACKGROUND_COLOR = 'backgroundColor'
7375
protected static final String FOREGROUND_COLOR = 'foregroundColor'
@@ -182,6 +184,12 @@ class CellStyleBuilder {
182184
if (fontMap.containsKey(FONT_COLOR)) {
183185
font.setColor(getColor(fontMap[FONT_COLOR]))
184186
}
187+
if (fontMap.containsKey(FONT_SIZE)) {
188+
font.setFontHeight((Double)fontMap[FONT_SIZE])
189+
}
190+
if (fontMap.containsKey(FONT_NAME)) {
191+
font.setFontName((String)fontMap[FONT_NAME])
192+
}
185193
} else {
186194
throw new IllegalArgumentException('The font option must be an instance of a Map')
187195
}

0 commit comments

Comments
 (0)