Skip to content

Commit 79a7c1b

Browse files
committed
rich text styles formatting, fixes #5
1 parent ca12eb0 commit 79a7c1b

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

docs/index.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,12 @@ _Result_
674674

675675
image:rich_text.png[]
676676

677+
[WARNING]
678+
====
679+
Some older versions that 3.13 of Apache POI does not handle rich texts well. Please, make sure
680+
you are using at least version 3.13.
681+
====
682+
677683
=== Data formats
678684
You can assing a data format using the `format` method. Detailed guide how the format works can be found in
679685
link:https://support.microsoft.com/en-us/kb/298368[How to control and understand settings in the Excel for Format Cells

spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/builder/spreadsheet/poi/PoiCell.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ class PoiCell extends AbstractCell implements Resolvable {
165165

166166
@Override
167167
void text(String run, @DelegatesTo(Font.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.builder.spreadsheet.api.Font") Closure fontConfiguration) {
168+
if (!run) {
169+
return
170+
}
168171
int start = 0
169172
if (richTextParts) {
170173
start = richTextParts.last().end

spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/builder/spreadsheet/poi/PoiFont.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class PoiFont extends AbstractHTMLColorProvider implements Font {
3333

3434
@Override
3535
void size(int size) {
36-
font.fontHeightInPoints = (short) size
36+
font.setFontHeightInPoints(size.shortValue())
3737
}
3838

3939
@Override

spreadsheet-builder-poi/src/test/groovy/org/modelcatalogue/builder/spreadsheet/poi/PoiExcelBuilderSpec.groovy

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,59 @@ class PoiExcelBuilderSpec extends Specification {
6868

6969
}
7070
}
71+
row {
72+
cell {
73+
style {
74+
wrap text
75+
}
76+
text 'First Line'
77+
text '\n'
78+
text 'Second Line', {
79+
bold
80+
size 12
81+
}
82+
text '\n'
83+
for (Map.Entry<String, String> entry in [foo: 'bar', boo: 'cow', empty: '', '':'nothing']) {
84+
text entry.key, {
85+
bold
86+
}
87+
text ': '
88+
text entry.value
89+
text '\n'
90+
}
91+
text '\n\n'
92+
text 'Next line after two spaces'
93+
text '\n'
94+
text 'Last line', {
95+
italic
96+
}
97+
text '\n'
98+
}
99+
}
100+
101+
row {
102+
cell {
103+
text 'Genomics England Consent Withdrawal Options'
104+
text '\n\n'
105+
text 'Enumerations', {
106+
size 12
107+
bold
108+
}
109+
text '\n'
110+
111+
for (Map.Entry<String, String> entry in [
112+
FULL_WITHDRAWAL: 'OPTION 2: FULL WITHDRAWAL: No further use',
113+
PARTIAL_WITHDRAWAL: 'OPTION 1: PARTIAL WITHDRAWAL: No further contact'
114+
]) {
115+
text entry.key, {
116+
bold
117+
}
118+
text ': '
119+
text entry.value
120+
text '\n'
121+
}
122+
}
123+
}
71124
}
72125

73126
sheet('Cell Adressing') {

0 commit comments

Comments
 (0)