├── .gitignore
├── .travis.yml
├── LICENSE
├── README.adoc
├── build.gradle
├── config
├── checkstyle
│ └── checkstyle.xml
└── codenarc.xml
├── docs
├── css
│ └── spreadsheet-builder.css
├── docinfo.html
├── images
│ ├── alignment.png
│ ├── basic_cells.png
│ ├── basic_sample.png
│ ├── borders.png
│ ├── colors.png
│ ├── comments.png
│ ├── dimensions.png
│ ├── fills.png
│ ├── filtered.png
│ ├── fonts.png
│ ├── frozen_cells.gif
│ ├── image.png
│ ├── indent.png
│ ├── locked.png
│ ├── names.png
│ ├── outline_for_rows.png
│ ├── ribbon.png
│ ├── rich_text.png
│ ├── rotation.png
│ ├── spans.png
│ ├── specific_row.png
│ ├── styles.png
│ ├── stylesheets.png
│ └── wrap.png
└── index.adoc
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
├── spreadsheet-builder-api
├── build.gradle
└── src
│ ├── main
│ └── java
│ │ └── org
│ │ └── modelcatalogue
│ │ └── spreadsheet
│ │ ├── api
│ │ ├── AbstractBorderProvider.java
│ │ ├── AbstractPageSettingsProvider.java
│ │ ├── Border.java
│ │ ├── BorderStyle.java
│ │ ├── BorderStyleProvider.java
│ │ ├── Cell.java
│ │ ├── CellStyle.java
│ │ ├── Color.java
│ │ ├── Comment.java
│ │ ├── DataRow.java
│ │ ├── Font.java
│ │ ├── FontStyle.java
│ │ ├── FontStylesProvider.java
│ │ ├── ForegroundFill.java
│ │ ├── ForegroundFillProvider.java
│ │ ├── HTMLColorProvider.java
│ │ ├── HorizontalAlignmentConfigurer.java
│ │ ├── Keywords.java
│ │ ├── Page.java
│ │ ├── PageSettingsProvider.java
│ │ ├── Row.java
│ │ ├── Sheet.java
│ │ └── Workbook.java
│ │ ├── builder
│ │ └── api
│ │ │ ├── AbstractCellDefinition.java
│ │ │ ├── AbstractCellStyleDefinition.java
│ │ │ ├── BorderDefinition.java
│ │ │ ├── CanDefineStyle.java
│ │ │ ├── CellDefinition.java
│ │ │ ├── CellStyleDefinition.java
│ │ │ ├── CommentDefinition.java
│ │ │ ├── DimensionModifier.java
│ │ │ ├── FitDimension.java
│ │ │ ├── FontDefinition.java
│ │ │ ├── HasStyle.java
│ │ │ ├── ImageCreator.java
│ │ │ ├── LinkDefinition.java
│ │ │ ├── PageDefinition.java
│ │ │ ├── RowDefinition.java
│ │ │ ├── SheetDefinition.java
│ │ │ ├── SpreadsheetBuilder.java
│ │ │ ├── SpreadsheetDefinition.java
│ │ │ ├── Stylesheet.java
│ │ │ └── WorkbookDefinition.java
│ │ └── query
│ │ ├── api
│ │ ├── AbstractSpreadsheetCriteriaResult.java
│ │ ├── BorderCriterion.java
│ │ ├── CellCriterion.java
│ │ ├── CellStyleCriterion.java
│ │ ├── FontCriterion.java
│ │ ├── PageCriterion.java
│ │ ├── Predicate.java
│ │ ├── RowCriterion.java
│ │ ├── SheetCriterion.java
│ │ ├── SpreadsheetCriteria.java
│ │ ├── SpreadsheetCriteriaFactory.java
│ │ ├── SpreadsheetCriteriaResult.java
│ │ ├── Transformation.java
│ │ └── WorkbookCriterion.java
│ │ └── simple
│ │ ├── AbstractCriterion.java
│ │ ├── SimpleBorderCriterion.java
│ │ ├── SimpleCellCriterion.java
│ │ ├── SimpleCellStyleCriterion.java
│ │ ├── SimpleFontCriterion.java
│ │ ├── SimplePageCriterion.java
│ │ ├── SimpleRowCriterion.java
│ │ ├── SimpleSheetCriterion.java
│ │ ├── SimpleSpreadsheetCriteria.java
│ │ ├── SimpleSpreadsheetCriteriaResult.java
│ │ └── SimpleWorkbookCriterion.java
│ └── test
│ └── groovy
│ └── org
│ └── modelcatalogue
│ └── spreadsheet
│ └── api
│ └── CellUtilSpec.groovy
└── spreadsheet-builder-poi
├── build.gradle
└── src
├── main
└── groovy
│ └── org
│ └── modelcatalogue
│ └── spreadsheet
│ ├── builder
│ └── poi
│ │ ├── PendingFormula.groovy
│ │ ├── PendingLink.groovy
│ │ ├── PoiBorder.groovy
│ │ ├── PoiBorderDefinition.groovy
│ │ ├── PoiCellDefinition.groovy
│ │ ├── PoiCellStyle.groovy
│ │ ├── PoiCellStyleDefinition.groovy
│ │ ├── PoiCommentDefinition.groovy
│ │ ├── PoiFitDimension.groovy
│ │ ├── PoiFont.groovy
│ │ ├── PoiFontDefinition.groovy
│ │ ├── PoiHeightModifier.groovy
│ │ ├── PoiHorizontalAlignmentConfigurer.groovy
│ │ ├── PoiImageCreator.groovy
│ │ ├── PoiLinkDefinition.groovy
│ │ ├── PoiPageSettingsProvider.groovy
│ │ ├── PoiRowDefinition.groovy
│ │ ├── PoiSheetDefinition.groovy
│ │ ├── PoiSpreadsheetBuilder.groovy
│ │ ├── PoiWidthModifier.groovy
│ │ ├── PoiWorkbookDefinition.groovy
│ │ ├── Resolvable.groovy
│ │ └── RichTextPart.groovy
│ └── query
│ └── poi
│ └── PoiSpreadsheetCriteria.groovy
└── test
└── groovy
└── org
└── modelcatalogue
└── spreadsheet
└── builder
└── poi
├── MyStyles.groovy
├── PoiCellSpec.groovy
├── PoiCellStyleSpec.groovy
└── PoiExcelBuilderSpec.groovy
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | **/build/
3 | **/.idea/
4 | **/*.iml
5 | # Ignore Gradle GUI config
6 | gradle-app.setting
7 |
8 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
9 | !gradle-wrapper.jar
10 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: groovy
2 | jdk:
3 | - oraclejdk7
4 | script:
5 | #- "./gradlew check"
6 | - "./gradlew test"
--------------------------------------------------------------------------------
/README.adoc:
--------------------------------------------------------------------------------
1 | = Groovy Spreadsheet Builder
2 |
3 | Spreadsheet builder provides convenient way how to create MS Excel OfficeOpenXML
4 | Documents (XSLX) focus not only on content side but also on easy styling.
5 |
6 | See the link:http://metadataconsulting.github.io/spreadsheet-builder/[Full Documentation]
7 |
8 | [NOTE]
9 | Newer version including Java 8 support available under new coordinates: http://spreadsheet.dsl.builders
10 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | }
5 | dependencies {
6 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
7 | }
8 | }
9 |
10 | plugins {
11 | id 'org.ajoberstar.github-pages' version '1.3.1'
12 | id 'org.asciidoctor.gradle.asciidoctor' version '1.5.1'
13 | }
14 |
15 | String currentVersion = '0.4.1'
16 |
17 | version = currentVersion
18 |
19 | subprojects {
20 | apply plugin: 'groovy'
21 | apply plugin: 'checkstyle'
22 | apply plugin: 'codenarc'
23 | apply plugin: 'maven-publish'
24 | apply plugin: 'com.jfrog.bintray'
25 |
26 | group = 'org.modelcatalogue'
27 |
28 | sourceCompatibility = 1.6
29 | targetCompatibility = 1.6
30 |
31 | repositories {
32 | jcenter()
33 | }
34 |
35 | dependencies {
36 | testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
37 | }
38 |
39 | // don't forget to update version in CaseReportFormSerializer
40 | version = currentVersion
41 |
42 | jar {
43 | manifest.attributes provider: 'gradle'
44 | }
45 |
46 | checkstyle {
47 | configFile = rootProject.file('config/checkstyle/checkstyle.xml')
48 | }
49 |
50 | codenarc {
51 | configFile = rootProject.file('config/codenarc.xml')
52 | }
53 |
54 | test {
55 | reports {
56 | junitXml.enabled = true
57 | html.enabled = true
58 | }
59 | }
60 |
61 |
62 |
63 | // publishing
64 | publishing {
65 | publications {
66 | groovyMaven(MavenPublication) {
67 | from components.java
68 |
69 | artifact sourcesJar {
70 | classifier "sources"
71 | }
72 |
73 | artifact javadocJar {
74 | classifier "javadoc"
75 | }
76 | }
77 | }
78 | }
79 |
80 | // set bintrayUser & bintrayKey in gradle.properties
81 | bintray {
82 |
83 | user = getPropertyOrUseDefault('bintrayUser', 'fake_user')
84 | key = getPropertyOrUseDefault('bintrayKey', 'fake_key')
85 | publications = ['groovyMaven']
86 |
87 | def projectName = project.name
88 | def projectDescription = project.description
89 |
90 | pkg {
91 | websiteUrl = 'http://metadataregistry.github.io/spreadsheet-builder/'
92 | issueTrackerUrl = 'https://github.com/MetadataRegistry/spreadsheet-builder/issues'
93 | vcsUrl = 'https://github.com/MetadataRegistry/spreadsheet-builder.git'
94 |
95 | repo = 'model-catalogue' // or your repo name
96 | userOrg = 'metadata'
97 | name = projectName // somehow project.* doesn't work in this closure
98 | desc = projectDescription
99 | licenses = ['Apache-2.0']
100 | }
101 | // dryRun = true // whether to run this as dry-run, without deploying
102 | }
103 |
104 | // custom tasks for creating source/javadoc jars
105 | task sourcesJar(type: Jar, dependsOn: classes) {
106 | classifier = 'sources'
107 | from sourceSets.main.allSource
108 | }
109 |
110 | task javadocJar(type: Jar, dependsOn: javadoc) {
111 | classifier = 'javadoc'
112 | from javadoc.destinationDir
113 | }
114 |
115 | artifacts {
116 | archives sourcesJar, javadocJar
117 | }
118 |
119 | }
120 |
121 | // asciidoctor publishing
122 | asciidoctor {
123 |
124 | sourceDir = file('docs')
125 |
126 | resources {
127 | from(sourceDir) {
128 | include 'css/**', 'images/**'
129 | }
130 | }
131 |
132 | attributes 'docinfo1': ['version': currentVersion],
133 | 'imagesdir': 'images',
134 | 'source-highlighter': 'highlight.js',
135 | 'stylesdir': 'css',
136 | icons: 'font',
137 | 'toc': 'left',
138 | version: project.version,
139 | 'projectUrl': 'https://github.com/MetadataRegistry/spreadsheet-builder'
140 | }
141 |
142 | githubPages {
143 | repoUri = 'https://github.com/MetadataRegistry/spreadsheet-builder.git'
144 |
145 | credentials {
146 | username = getPropertyOrUseDefault('githubToken', '')
147 | password = ''
148 | }
149 |
150 | pages {
151 | from file(asciidoctor.outputDir.path + '/html5')
152 | }
153 | }
154 |
155 | publishGhPages.dependsOn asciidoctor
156 |
157 |
158 |
159 |
160 | String getPropertyOrUseDefault(String propertyName, String defaultValue) {
161 | hasProperty(propertyName) ? getProperty(propertyName) : defaultValue
162 | }
163 |
--------------------------------------------------------------------------------
/config/checkstyle/checkstyle.xml:
--------------------------------------------------------------------------------
1 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
--------------------------------------------------------------------------------
/config/codenarc.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 | Sample rule set
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/docs/css/spreadsheet-builder.css:
--------------------------------------------------------------------------------
1 | .ribbon {
2 | position: fixed;
3 | top: 0;
4 | right: 0;
5 | z-index: 9999;
6 | }
--------------------------------------------------------------------------------
/docs/docinfo.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/docs/images/alignment.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/alignment.png
--------------------------------------------------------------------------------
/docs/images/basic_cells.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/basic_cells.png
--------------------------------------------------------------------------------
/docs/images/basic_sample.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/basic_sample.png
--------------------------------------------------------------------------------
/docs/images/borders.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/borders.png
--------------------------------------------------------------------------------
/docs/images/colors.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/colors.png
--------------------------------------------------------------------------------
/docs/images/comments.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/comments.png
--------------------------------------------------------------------------------
/docs/images/dimensions.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/dimensions.png
--------------------------------------------------------------------------------
/docs/images/fills.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/fills.png
--------------------------------------------------------------------------------
/docs/images/filtered.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/filtered.png
--------------------------------------------------------------------------------
/docs/images/fonts.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/fonts.png
--------------------------------------------------------------------------------
/docs/images/frozen_cells.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/frozen_cells.gif
--------------------------------------------------------------------------------
/docs/images/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/image.png
--------------------------------------------------------------------------------
/docs/images/indent.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/indent.png
--------------------------------------------------------------------------------
/docs/images/locked.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/locked.png
--------------------------------------------------------------------------------
/docs/images/names.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/names.png
--------------------------------------------------------------------------------
/docs/images/outline_for_rows.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/outline_for_rows.png
--------------------------------------------------------------------------------
/docs/images/ribbon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/ribbon.png
--------------------------------------------------------------------------------
/docs/images/rich_text.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/rich_text.png
--------------------------------------------------------------------------------
/docs/images/rotation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/rotation.png
--------------------------------------------------------------------------------
/docs/images/spans.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/spans.png
--------------------------------------------------------------------------------
/docs/images/specific_row.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/specific_row.png
--------------------------------------------------------------------------------
/docs/images/styles.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/styles.png
--------------------------------------------------------------------------------
/docs/images/stylesheets.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/stylesheets.png
--------------------------------------------------------------------------------
/docs/images/wrap.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/docs/images/wrap.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetadataConsulting/spreadsheet-builder/b51d3ddd08a5968a60cb1bfb1966822beadc77b1/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Oct 08 09:03:22 CEST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >&-
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >&-
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include 'spreadsheet-builder-api', 'spreadsheet-builder-poi'
2 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/build.gradle:
--------------------------------------------------------------------------------
1 | dependencies {
2 | compile 'org.codehaus.groovy:groovy-all:2.4.7'
3 | }
4 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/AbstractBorderProvider.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | import org.modelcatalogue.spreadsheet.builder.api.BorderDefinition;
4 |
5 | public abstract class AbstractBorderProvider implements BorderDefinition {
6 |
7 | @Override
8 | public BorderStyle getNone() {
9 | return BorderStyle.NONE;
10 | }
11 |
12 | @Override
13 | public BorderStyle getThin() {
14 | return BorderStyle.THIN;
15 | }
16 |
17 | @Override
18 | public BorderStyle getMedium() {
19 | return BorderStyle.MEDIUM;
20 | }
21 |
22 | @Override
23 | public BorderStyle getDashed() {
24 | return BorderStyle.DASHED;
25 | }
26 |
27 | @Override
28 | public BorderStyle getDotted() {
29 | return BorderStyle.DOTTED;
30 | }
31 |
32 | @Override
33 | public BorderStyle getThick() {
34 | return BorderStyle.THICK;
35 | }
36 |
37 | @Override
38 | public BorderStyle getDouble() {
39 | return BorderStyle.DOUBLE;
40 | }
41 |
42 | @Override
43 | public BorderStyle getHair() {
44 | return BorderStyle.HAIR;
45 | }
46 |
47 | @Override
48 | public BorderStyle getMediumDashed() {
49 | return BorderStyle.MEDIUM_DASHED;
50 | }
51 |
52 | @Override
53 | public BorderStyle getDashDot() {
54 | return BorderStyle.DASH_DOT;
55 | }
56 |
57 | @Override
58 | public BorderStyle getMediumDashDot() {
59 | return BorderStyle.MEDIUM_DASH_DOT;
60 | }
61 |
62 | @Override
63 | public BorderStyle getDashDotDot() {
64 | return BorderStyle.DASH_DOT_DOT;
65 | }
66 |
67 | @Override
68 | public BorderStyle getMediumDashDotDot() {
69 | return BorderStyle.MEDIUM_DASH_DOT_DOT;
70 | }
71 |
72 | @Override
73 | public BorderStyle getSlantedDashDot() {
74 | return BorderStyle.SLANTED_DASH_DOT;
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/AbstractPageSettingsProvider.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | public abstract class AbstractPageSettingsProvider implements PageSettingsProvider {
4 |
5 | @Override
6 | public Keywords.Orientation getPortrait() {
7 | return Keywords.Orientation.PORTRAIT;
8 | }
9 |
10 | @Override
11 | public Keywords.Orientation getLandscape() {
12 | return Keywords.Orientation.LANDSCAPE;
13 | }
14 |
15 | @Override
16 | public Keywords.Fit getWidth() {
17 | return Keywords.Fit.WIDTH;
18 | }
19 |
20 | @Override
21 | public Keywords.Fit getHeight() {
22 | return Keywords.Fit.HEIGHT;
23 | }
24 |
25 | @Override
26 | public Keywords.To getTo() {
27 | return Keywords.To.TO;
28 | }
29 |
30 | @Override
31 | public Keywords.Paper getLetter() {
32 | return Keywords.Paper.LETTER;
33 | }
34 |
35 | @Override
36 | public Keywords.Paper getLetterSmall() {
37 | return Keywords.Paper.LETTER_SMALL;
38 | }
39 |
40 | @Override
41 | public Keywords.Paper getTabloid() {
42 | return Keywords.Paper.TABLOID;
43 | }
44 |
45 | @Override
46 | public Keywords.Paper getLedger() {
47 | return Keywords.Paper.LEDGER;
48 | }
49 |
50 | @Override
51 | public Keywords.Paper getLegal() {
52 | return Keywords.Paper.LEGAL;
53 | }
54 |
55 | @Override
56 | public Keywords.Paper getStatement() {
57 | return Keywords.Paper.STATEMENT;
58 | }
59 |
60 | @Override
61 | public Keywords.Paper getExecutive() {
62 | return Keywords.Paper.EXECUTIVE;
63 | }
64 |
65 | @Override
66 | public Keywords.Paper getA3() {
67 | return Keywords.Paper.A3;
68 | }
69 |
70 | @Override
71 | public Keywords.Paper getA4() {
72 | return Keywords.Paper.A4;
73 | }
74 |
75 | @Override
76 | public Keywords.Paper getA4Small() {
77 | return Keywords.Paper.A4_SMALL;
78 | }
79 |
80 | @Override
81 | public Keywords.Paper getA5() {
82 | return Keywords.Paper.A5;
83 | }
84 |
85 | @Override
86 | public Keywords.Paper getB4() {
87 | return Keywords.Paper.B4;
88 | }
89 |
90 | @Override
91 | public Keywords.Paper getB5() {
92 | return Keywords.Paper.B5;
93 | }
94 |
95 | @Override
96 | public Keywords.Paper getFolio() {
97 | return Keywords.Paper.FOLIO;
98 | }
99 |
100 | @Override
101 | public Keywords.Paper getQuarto() {
102 | return Keywords.Paper.QUARTO;
103 | }
104 |
105 | @Override
106 | public Keywords.Paper getStandard10x14() {
107 | return Keywords.Paper.STANDARD_10_14;
108 | }
109 |
110 | @Override
111 | public Keywords.Paper getStandard11x17() {
112 | return Keywords.Paper.STANDARD_11_17;
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/Border.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | public interface Border {
4 |
5 | Color getColor();
6 | BorderStyle getStyle();
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/BorderStyle.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | public enum BorderStyle {
4 | NONE,
5 | THIN,
6 | MEDIUM,
7 | DASHED,
8 | DOTTED,
9 | THICK,
10 | DOUBLE,
11 | HAIR,
12 | MEDIUM_DASHED,
13 | DASH_DOT,
14 | MEDIUM_DASH_DOT,
15 | DASH_DOT_DOT,
16 | MEDIUM_DASH_DOT_DOT,
17 | SLANTED_DASH_DOT
18 | }
19 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/BorderStyleProvider.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | public interface BorderStyleProvider {
4 | // keywords
5 | BorderStyle getNone();
6 |
7 | BorderStyle getThin();
8 |
9 | BorderStyle getMedium();
10 |
11 | BorderStyle getDashed();
12 |
13 | BorderStyle getDotted();
14 |
15 | BorderStyle getThick();
16 |
17 | BorderStyle getDouble();
18 |
19 | BorderStyle getHair();
20 |
21 | BorderStyle getMediumDashed();
22 |
23 | BorderStyle getDashDot();
24 |
25 | BorderStyle getMediumDashDot();
26 |
27 | BorderStyle getDashDotDot();
28 |
29 | BorderStyle getMediumDashDotDot();
30 |
31 | BorderStyle getSlantedDashDot();
32 | }
33 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/Cell.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | import java.util.List;
4 |
5 | import static org.codehaus.groovy.runtime.DefaultGroovyMethods.reverse;
6 | import static org.codehaus.groovy.runtime.DefaultGroovyMethods.toList;
7 |
8 | public interface Cell {
9 |
10 | int getColumn();
11 | Object getValue();
12 | String getColumnAsString();
13 | T read(Class type);
14 | Row getRow();
15 |
16 | int getRowspan();
17 | int getColspan();
18 |
19 | String getName();
20 | Comment getComment();
21 | CellStyle getStyle();
22 |
23 | Cell getAbove();
24 | Cell getBellow();
25 | Cell getLeft();
26 | Cell getRight();
27 | Cell getAboveLeft();
28 | Cell getAboveRight();
29 | Cell getBellowLeft();
30 | Cell getBellowRight();
31 |
32 | class Util {
33 |
34 | private Util() {}
35 |
36 | public static int parseColumn(String column) {
37 | char a = 'A';
38 | List chars = reverse(toList(column.toUpperCase().toCharArray()));
39 | int acc = 0;
40 | for (int i = chars.size() - 1; i >= 0; i--) {
41 | if (i == 0) {
42 | acc += (int) chars.get(i) - (int) a + 1;
43 | } else {
44 | acc += 26 * i * ((int) chars.get(i) - (int) a + 1);
45 | }
46 | }
47 | return acc;
48 | }
49 |
50 | public static String toColumn(int number) {
51 | char a = 'A';
52 |
53 | int rest = number % 26;
54 | int times = number / 26;
55 |
56 | if (rest == 0 && times == 1) {
57 | return "Z";
58 | }
59 |
60 | if (times > 0) {
61 | return toColumn(times) + (char) (rest + a - 1);
62 | }
63 |
64 | return "" + (char) (rest + a - 1);
65 | }
66 |
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/CellStyle.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | public interface CellStyle {
4 |
5 | Color getForeground();
6 | Color getBackground();
7 | ForegroundFill getFill();
8 | int getIndent();
9 | int getRotation();
10 | String getFormat();
11 | Font getFont();
12 | Border getBorder(Keywords.BorderSide borderSide);
13 | }
14 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/Color.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | import java.util.Arrays;
4 |
5 | public final class Color {
6 |
7 | private final String hex;
8 |
9 | public Color(String hex) {
10 | if (!hex.matches("#[\\dA-Fa-f]{6}")) {
11 | throw new IllegalArgumentException("Wrong format for color: " + hex);
12 | }
13 | this.hex = hex.toUpperCase();
14 | }
15 |
16 | public Color(byte[] rgb) {
17 | if (rgb.length != 3) {
18 | throw new IllegalArgumentException("Wrong number of parts in: " + Arrays.toString(rgb));
19 | }
20 | this.hex = String.format("#%02X%02X%02X", rgb[0], rgb[1], rgb[2]);
21 | }
22 |
23 | @Override
24 | public boolean equals(Object o) {
25 | if (this == o) {
26 | return true;
27 | }
28 | if (o == null || getClass() != o.getClass()) {
29 | return false;
30 | }
31 |
32 | Color color = (Color) o;
33 |
34 | return !(hex != null ? !hex.equals(color.hex) : color.hex != null);
35 |
36 | }
37 |
38 | @Override
39 | public int hashCode() {
40 | return hex != null ? hex.hashCode() : 0;
41 | }
42 |
43 | public String getHex() {
44 | return hex;
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return "Color[" + getHex() + "]";
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/Comment.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | public interface Comment {
4 |
5 | String getAuthor();
6 | String getText();
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/DataRow.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | import java.util.Collection;
4 | import java.util.HashMap;
5 | import java.util.Map;
6 |
7 | /**
8 | * Wraps row so it can be accessible using the names from headers.
9 | */
10 | public final class DataRow implements Row {
11 |
12 | public static DataRow create(Row row, Row headersRow) {
13 | Collection extends Cell> cells = headersRow.getCells();
14 | Map mapping = new HashMap(cells.size());
15 | for (Cell cell : cells) {
16 | mapping.put(String.valueOf(cell.getValue()), cell.getColumn());
17 | }
18 | return new DataRow(row, mapping);
19 | }
20 |
21 | public static DataRow create(Map mapping, Row row) {
22 | return new DataRow(row, new HashMap(mapping));
23 | }
24 |
25 | private final Row row;
26 | private final Map cells;
27 |
28 | private DataRow(Row row, Map mapping) {
29 | this.row = row;
30 |
31 | Map cells = new HashMap(row.getCells().size());
32 |
33 | for (Map.Entry entry : mapping.entrySet()) {
34 | for (Cell cell : row.getCells()) {
35 | if (cell.getColumn() == entry.getValue()) {
36 | cells.put(entry.getKey(), cell);
37 | }
38 | }
39 | }
40 |
41 | this.cells = cells;
42 | }
43 |
44 | /**
45 | * Returns the cell by the label given from headers or mapping.
46 | * @param name label from header or mapping
47 | * @return the cell by the label given from headers or mapping
48 | */
49 | public Cell getAt(String name) {
50 | return cells.get(name);
51 | }
52 |
53 | @Override
54 | public int getNumber() {
55 | return row.getNumber();
56 | }
57 |
58 | @Override
59 | public Sheet getSheet() {
60 | return row.getSheet();
61 | }
62 |
63 | @Override
64 | public Collection extends Cell> getCells() {
65 | return row.getCells();
66 | }
67 |
68 | @Override
69 | public Row getAbove() {
70 | return row.getAbove();
71 | }
72 |
73 | @Override
74 | public Row getAbove(int howMany) {
75 | return row.getAbove(howMany);
76 | }
77 |
78 | @Override
79 | public Row getBellow() {
80 | return row.getBellow();
81 | }
82 |
83 | @Override
84 | public Row getBellow(int howMany) {
85 | return row.getBellow(howMany);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/Font.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | import java.util.EnumSet;
4 |
5 | public interface Font {
6 |
7 | Color getColor();
8 | int getSize();
9 | String getName();
10 | EnumSet getStyles();
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/FontStyle.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | public enum FontStyle {
4 |
5 | BOLD,
6 | ITALIC,
7 | STRIKEOUT,
8 | UNDERLINE
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/FontStylesProvider.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | public interface FontStylesProvider {
4 |
5 | FontStyle getItalic();
6 | FontStyle getBold();
7 | FontStyle getStrikeout();
8 | FontStyle getUnderline();
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/ForegroundFill.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | public enum ForegroundFill {
4 |
5 | NO_FILL,
6 | SOLID_FOREGROUND,
7 | FINE_DOTS,
8 | ALT_BARS,
9 | SPARSE_DOTS,
10 | THICK_HORZ_BANDS,
11 | THICK_VERT_BANDS,
12 | THICK_BACKWARD_DIAG,
13 | THICK_FORWARD_DIAG,
14 | BIG_SPOTS,
15 | BRICKS,
16 | THIN_HORZ_BANDS,
17 | THIN_VERT_BANDS,
18 | THIN_BACKWARD_DIAG,
19 | THIN_FORWARD_DIAG,
20 | SQUARES,
21 | DIAMONDS
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/ForegroundFillProvider.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | public interface ForegroundFillProvider {
4 | ForegroundFill getNoFill();
5 |
6 | ForegroundFill getSolidForeground();
7 |
8 | ForegroundFill getFineDots();
9 |
10 | ForegroundFill getAltBars();
11 |
12 | ForegroundFill getSparseDots();
13 |
14 | ForegroundFill getThickHorizontalBands();
15 |
16 | ForegroundFill getThickVerticalBands();
17 |
18 | ForegroundFill getThickBackwardDiagonals();
19 |
20 | ForegroundFill getThickForwardDiagonals();
21 |
22 | ForegroundFill getBigSpots();
23 |
24 | ForegroundFill getBricks();
25 |
26 | ForegroundFill getThinHorizontalBands();
27 |
28 | ForegroundFill getThinVerticalBands();
29 |
30 | ForegroundFill getThinBackwardDiagonals();
31 |
32 | ForegroundFill getThinForwardDiagonals();
33 |
34 | ForegroundFill getSquares();
35 |
36 | ForegroundFill getDiamonds();
37 | }
38 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/HTMLColorProvider.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | //CHECKSTYLE:OFF
4 | public interface HTMLColorProvider {
5 |
6 | Color aliceBlue = new Color("#F0F8FF");
7 | Color antiqueWhite = new Color("#FAEBD7");
8 | Color aqua = new Color("#00FFFF");
9 | Color aquamarine = new Color("#7FFFD4");
10 | Color azure = new Color("#F0FFFF");
11 | Color beige = new Color("#F5F5DC");
12 | Color bisque = new Color("#FFE4C4");
13 | Color black = new Color("#000000");
14 | Color blanchedAlmond = new Color("#FFEBCD");
15 | Color blue = new Color("#0000FF");
16 | Color blueViolet = new Color("#8A2BE2");
17 | Color brown = new Color("#A52A2A");
18 | Color burlyWood = new Color("#DEB887");
19 | Color cadetBlue = new Color("#5F9EA0");
20 | Color chartreuse = new Color("#7FFF00");
21 | Color chocolate = new Color("#D2691E");
22 | Color coral = new Color("#FF7F50");
23 | Color cornflowerBlue = new Color("#6495ED");
24 | Color cornsilk = new Color("#FFF8DC");
25 | Color crimson = new Color("#DC143C");
26 | Color cyan = new Color("#00FFFF");
27 | Color darkBlue = new Color("#00008B");
28 | Color darkCyan = new Color("#008B8B");
29 | Color darkGoldenRod = new Color("#B8860B");
30 | Color darkGray = new Color("#A9A9A9");
31 | Color darkGreen = new Color("#006400");
32 | Color darkKhaki = new Color("#BDB76B");
33 | Color darkMagenta = new Color("#8B008B");
34 | Color darkOliveGreen = new Color("#556B2F");
35 | Color darkOrange = new Color("#FF8C00");
36 | Color darkOrchid = new Color("#9932CC");
37 | Color darkRed = new Color("#8B0000");
38 | Color darkSalmon = new Color("#E9967A");
39 | Color darkSeaGreen = new Color("#8FBC8F");
40 | Color darkSlateBlue = new Color("#483D8B");
41 | Color darkSlateGray = new Color("#2F4F4F");
42 | Color darkTurquoise = new Color("#00CED1");
43 | Color darkViolet = new Color("#9400D3");
44 | Color deepPink = new Color("#FF1493");
45 | Color deepSkyBlue = new Color("#00BFFF");
46 | Color dimGray = new Color("#696969");
47 | Color dodgerBlue = new Color("#1E90FF");
48 | Color fireBrick = new Color("#B22222");
49 | Color floralWhite = new Color("#FFFAF0");
50 | Color forestGreen = new Color("#228B22");
51 | Color fuchsia = new Color("#FF00FF");
52 | Color gainsboro = new Color("#DCDCDC");
53 | Color ghostWhite = new Color("#F8F8FF");
54 | Color gold = new Color("#FFD700");
55 | Color goldenRod = new Color("#DAA520");
56 | Color gray = new Color("#808080");
57 | Color green = new Color("#008000");
58 | Color greenYellow = new Color("#ADFF2F");
59 | Color honeyDew = new Color("#F0FFF0");
60 | Color hotPink = new Color("#FF69B4");
61 | Color indianRed = new Color("#CD5C5C");
62 | Color indigo = new Color("#4B0082");
63 | Color ivory = new Color("#FFFFF0");
64 | Color khaki = new Color("#F0E68C");
65 | Color lavender = new Color("#E6E6FA");
66 | Color lavenderBlush = new Color("#FFF0F5");
67 | Color lawnGreen = new Color("#7CFC00");
68 | Color lemonChiffon = new Color("#FFFACD");
69 | Color lightBlue = new Color("#ADD8E6");
70 | Color lightCoral = new Color("#F08080");
71 | Color lightCyan = new Color("#E0FFFF");
72 | Color lightGoldenRodYellow = new Color("#FAFAD2");
73 | Color lightGray = new Color("#D3D3D3");
74 | Color lightGreen = new Color("#90EE90");
75 | Color lightPink = new Color("#FFB6C1");
76 | Color lightSalmon = new Color("#FFA07A");
77 | Color lightSeaGreen = new Color("#20B2AA");
78 | Color lightSkyBlue = new Color("#87CEFA");
79 | Color lightSlateGray = new Color("#778899");
80 | Color lightSteelBlue = new Color("#B0C4DE");
81 | Color lightYellow = new Color("#FFFFE0");
82 | Color lime = new Color("#00FF00");
83 | Color limeGreen = new Color("#32CD32");
84 | Color linen = new Color("#FAF0E6");
85 | Color magenta = new Color("#FF00FF");
86 | Color maroon = new Color("#800000");
87 | Color mediumAquaMarine = new Color("#66CDAA");
88 | Color mediumBlue = new Color("#0000CD");
89 | Color mediumOrchid = new Color("#BA55D3");
90 | Color mediumPurple = new Color("#9370DB");
91 | Color mediumSeaGreen = new Color("#3CB371");
92 | Color mediumSlateBlue = new Color("#7B68EE");
93 | Color mediumSpringGreen = new Color("#00FA9A");
94 | Color mediumTurquoise = new Color("#48D1CC");
95 | Color mediumVioletRed = new Color("#C71585");
96 | Color midnightBlue = new Color("#191970");
97 | Color mintCream = new Color("#F5FFFA");
98 | Color mistyRose = new Color("#FFE4E1");
99 | Color moccasin = new Color("#FFE4B5");
100 | Color navajoWhite = new Color("#FFDEAD");
101 | Color navy = new Color("#000080");
102 | Color oldLace = new Color("#FDF5E6");
103 | Color olive = new Color("#808000");
104 | Color oliveDrab = new Color("#6B8E23");
105 | Color orange = new Color("#FFA500");
106 | Color orangeRed = new Color("#FF4500");
107 | Color orchid = new Color("#DA70D6");
108 | Color paleGoldenRod = new Color("#EEE8AA");
109 | Color paleGreen = new Color("#98FB98");
110 | Color paleTurquoise = new Color("#AFEEEE");
111 | Color paleVioletRed = new Color("#DB7093");
112 | Color papayaWhip = new Color("#FFEFD5");
113 | Color peachPuff = new Color("#FFDAB9");
114 | Color peru = new Color("#CD853F");
115 | Color pink = new Color("#FFC0CB");
116 | Color plum = new Color("#DDA0DD");
117 | Color powderBlue = new Color("#B0E0E6");
118 | Color purple = new Color("#800080");
119 | Color rebeccaPurple = new Color("#663399");
120 | Color red = new Color("#FF0000");
121 | Color rosyBrown = new Color("#BC8F8F");
122 | Color royalBlue = new Color("#4169E1");
123 | Color saddleBrown = new Color("#8B4513");
124 | Color salmon = new Color("#FA8072");
125 | Color sandyBrown = new Color("#F4A460");
126 | Color seaGreen = new Color("#2E8B57");
127 | Color seaShell = new Color("#FFF5EE");
128 | Color sienna = new Color("#A0522D");
129 | Color silver = new Color("#C0C0C0");
130 | Color skyBlue = new Color("#87CEEB");
131 | Color slateBlue = new Color("#6A5ACD");
132 | Color slateGray = new Color("#708090");
133 | Color snow = new Color("#FFFAFA");
134 | Color springGreen = new Color("#00FF7F");
135 | Color steelBlue = new Color("#4682B4");
136 | Color tan = new Color("#D2B48C");
137 | Color teal = new Color("#008080");
138 | Color thistle = new Color("#D8BFD8");
139 | Color tomato = new Color("#FF6347");
140 | Color turquoise = new Color("#40E0D0");
141 | Color violet = new Color("#EE82EE");
142 | Color wheat = new Color("#F5DEB3");
143 | Color white = new Color("#FFFFFF");
144 | Color whiteSmoke = new Color("#F5F5F5");
145 | Color yellow = new Color("#FFFF00");
146 | Color yellowGreen = new Color("#9ACD32");
147 | }
148 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/HorizontalAlignmentConfigurer.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 |
4 | public interface HorizontalAlignmentConfigurer {
5 |
6 | // following methods must return something otherwise they are not considered to be getters
7 |
8 | Object getRight();
9 | Object getLeft();
10 |
11 | Object getGeneral();
12 | Object getCenter();
13 | Object getFill();
14 | Object getJustify();
15 | Object getCenterSelection();
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/Keywords.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | public final class Keywords {
4 |
5 | private Keywords() {}
6 |
7 | public enum Text {
8 | WRAP
9 | }
10 |
11 | public enum To {
12 | TO
13 | }
14 |
15 | public enum Image {
16 | IMAGE
17 | }
18 |
19 | public enum Auto {
20 | AUTO
21 | }
22 |
23 | public enum BorderSideAndVerticalAlignment implements BorderSide, VerticalAlignment {
24 | TOP,
25 | BOTTOM
26 | }
27 |
28 | public enum PureBorderSide implements BorderSide {
29 | LEFT,
30 | RIGHT
31 | }
32 |
33 | public enum PureVerticalAlignment implements VerticalAlignment {
34 | CENTER,
35 | JUSTIFY,
36 | DISTRIBUTED
37 | }
38 |
39 | public enum Orientation {
40 | LANDSCAPE,
41 | PORTRAIT
42 | }
43 |
44 | public enum Fit {
45 | HEIGHT,
46 | WIDTH
47 | }
48 |
49 | public enum Paper {
50 | LETTER,
51 | LETTER_SMALL,
52 | TABLOID,
53 | LEDGER,
54 | LEGAL,
55 | STATEMENT,
56 | EXECUTIVE,
57 | A3,
58 | A4,
59 | A4_SMALL,
60 | A5,
61 | B4,
62 | B5,
63 | FOLIO,
64 | QUARTO,
65 | STANDARD_10_14,
66 | STANDARD_11_17
67 | }
68 |
69 | //CHECKSTYLE:OFF
70 | public interface BorderSide {
71 | BorderSide LEFT = PureBorderSide.LEFT;
72 | BorderSide RIGHT = PureBorderSide.RIGHT;
73 | BorderSide TOP = BorderSideAndVerticalAlignment.TOP;
74 | BorderSide BOTTOM = BorderSideAndVerticalAlignment.BOTTOM;
75 |
76 | BorderSide[] BORDER_SIDES = {TOP, BOTTOM, LEFT, RIGHT};
77 | }
78 |
79 | public interface VerticalAlignment {
80 |
81 | VerticalAlignment TOP = BorderSideAndVerticalAlignment.TOP;
82 | VerticalAlignment CENTER = PureVerticalAlignment.CENTER;
83 | VerticalAlignment BOTTOM = BorderSideAndVerticalAlignment.BOTTOM;
84 | VerticalAlignment JUSTIFY = PureVerticalAlignment.JUSTIFY;
85 | VerticalAlignment DISTRIBUTED = PureVerticalAlignment.DISTRIBUTED;
86 |
87 | VerticalAlignment[] VERTICAL_ALIGNMENTS = {TOP, CENTER, BOTTOM, JUSTIFY, DISTRIBUTED};
88 |
89 | }
90 | //CHECKSTYLE:ON
91 | }
92 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/Page.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | public interface Page {
4 | Keywords.Orientation getOrientation();
5 | Keywords.Paper getPaper();
6 | }
7 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/PageSettingsProvider.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | /**
4 | * Created by ladin on 03.03.17.
5 | */
6 | public interface PageSettingsProvider {
7 |
8 | Keywords.Orientation getPortrait();
9 | Keywords.Orientation getLandscape();
10 |
11 | Keywords.Fit getWidth();
12 | Keywords.Fit getHeight();
13 |
14 | Keywords.To getTo();
15 |
16 | Keywords.Paper getLetter();
17 | Keywords.Paper getLetterSmall();
18 | Keywords.Paper getTabloid();
19 | Keywords.Paper getLedger();
20 | Keywords.Paper getLegal();
21 | Keywords.Paper getStatement();
22 | Keywords.Paper getExecutive();
23 | Keywords.Paper getA3();
24 | Keywords.Paper getA4();
25 | Keywords.Paper getA4Small();
26 | Keywords.Paper getA5();
27 | Keywords.Paper getB4();
28 | Keywords.Paper getB5();
29 | Keywords.Paper getFolio();
30 | Keywords.Paper getQuarto();
31 | Keywords.Paper getStandard10x14();
32 | Keywords.Paper getStandard11x17();
33 | }
34 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/Row.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | import java.util.Collection;
4 |
5 | public interface Row {
6 |
7 | int getNumber();
8 | Sheet getSheet();
9 |
10 | Collection extends Cell> getCells();
11 |
12 | Row getAbove();
13 | Row getAbove(int howMany);
14 | Row getBellow();
15 | Row getBellow(int howMany);
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/Sheet.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | import java.util.Collection;
4 |
5 | public interface Sheet {
6 |
7 | String getName();
8 | Workbook getWorkbook();
9 |
10 | Collection extends Row> getRows();
11 |
12 | Page getPage();
13 |
14 | Sheet getNext();
15 | Sheet getPrevious();
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/api/Workbook.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api;
2 |
3 | import java.util.Collection;
4 |
5 | public interface Workbook {
6 |
7 | Collection extends Sheet> getSheets();
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/AbstractCellDefinition.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 |
4 | import org.modelcatalogue.spreadsheet.api.Keywords;
5 |
6 | public abstract class AbstractCellDefinition implements CellDefinition {
7 |
8 | public Keywords.Auto getAuto() {
9 | return Keywords.Auto.AUTO;
10 | }
11 |
12 | public Keywords.To getTo() {
13 | return Keywords.To.TO;
14 | }
15 |
16 | public Keywords.Image getImage() {
17 | return Keywords.Image.IMAGE;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/AbstractCellStyleDefinition.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 | import org.modelcatalogue.spreadsheet.api.*;
4 |
5 | public abstract class AbstractCellStyleDefinition implements CellStyleDefinition, HTMLColorProvider {
6 |
7 | @Override
8 | public ForegroundFill getNoFill() {
9 | return ForegroundFill.NO_FILL;
10 | }
11 |
12 | @Override
13 | public ForegroundFill getSolidForeground() {
14 | return ForegroundFill.SOLID_FOREGROUND;
15 | }
16 |
17 | @Override
18 | public ForegroundFill getFineDots() {
19 | return ForegroundFill.FINE_DOTS;
20 | }
21 |
22 | @Override
23 | public ForegroundFill getAltBars() {
24 | return ForegroundFill.ALT_BARS;
25 | }
26 |
27 | @Override
28 | public ForegroundFill getSparseDots() {
29 | return ForegroundFill.SPARSE_DOTS;
30 | }
31 |
32 | @Override
33 | public ForegroundFill getThickHorizontalBands() {
34 | return ForegroundFill.THICK_HORZ_BANDS;
35 | }
36 |
37 | @Override
38 | public ForegroundFill getThickVerticalBands() {
39 | return ForegroundFill.THICK_VERT_BANDS;
40 | }
41 |
42 | @Override
43 | public ForegroundFill getThickBackwardDiagonals() {
44 | return ForegroundFill.THICK_BACKWARD_DIAG;
45 | }
46 |
47 | @Override
48 | public ForegroundFill getThickForwardDiagonals() {
49 | return ForegroundFill.THICK_FORWARD_DIAG;
50 | }
51 |
52 | @Override
53 | public ForegroundFill getBigSpots() {
54 | return ForegroundFill.BIG_SPOTS;
55 | }
56 |
57 | @Override
58 | public ForegroundFill getBricks() {
59 | return ForegroundFill.BRICKS;
60 | }
61 |
62 | @Override
63 | public ForegroundFill getThinHorizontalBands() {
64 | return ForegroundFill.THIN_HORZ_BANDS;
65 | }
66 |
67 | @Override
68 | public ForegroundFill getThinVerticalBands() {
69 | return ForegroundFill.THIN_VERT_BANDS;
70 | }
71 |
72 | @Override
73 | public ForegroundFill getThinBackwardDiagonals() {
74 | return ForegroundFill.THIN_BACKWARD_DIAG;
75 | }
76 |
77 | @Override
78 | public ForegroundFill getThinForwardDiagonals() {
79 | return ForegroundFill.THICK_FORWARD_DIAG;
80 | }
81 |
82 | @Override
83 | public ForegroundFill getSquares() {
84 | return ForegroundFill.SQUARES;
85 | }
86 |
87 | @Override
88 | public ForegroundFill getDiamonds() {
89 | return ForegroundFill.DIAMONDS;
90 | }
91 |
92 | @Override
93 | public Keywords.PureBorderSide getLeft() {
94 | return Keywords.PureBorderSide.LEFT;
95 | }
96 |
97 | @Override
98 | public Keywords.PureBorderSide getRight() {
99 | return Keywords.PureBorderSide.RIGHT;
100 | }
101 |
102 | @Override
103 | public Keywords.BorderSideAndVerticalAlignment getTop() {
104 | return Keywords.BorderSideAndVerticalAlignment.TOP;
105 | }
106 |
107 | @Override
108 | public Keywords.BorderSideAndVerticalAlignment getBottom() {
109 | return Keywords.BorderSideAndVerticalAlignment.BOTTOM;
110 | }
111 |
112 | @Override
113 | public Keywords.PureVerticalAlignment getCenter() {
114 | return Keywords.PureVerticalAlignment.CENTER;
115 | }
116 |
117 | @Override
118 | public Keywords.PureVerticalAlignment getJustify() {
119 | return Keywords.PureVerticalAlignment.JUSTIFY;
120 | }
121 |
122 | @Override
123 | public Keywords.PureVerticalAlignment getDistributed() {
124 | return Keywords.PureVerticalAlignment.DISTRIBUTED;
125 | }
126 |
127 | @Override
128 | public Keywords.Text getText() {
129 | return Keywords.Text.WRAP;
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/BorderDefinition.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 | import org.modelcatalogue.spreadsheet.api.BorderStyle;
4 | import org.modelcatalogue.spreadsheet.api.BorderStyleProvider;
5 | import org.modelcatalogue.spreadsheet.api.Color;
6 |
7 | public interface BorderDefinition extends BorderStyleProvider {
8 |
9 | void style(BorderStyle style);
10 | void color(String hexColor);
11 | void color(Color color);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/CanDefineStyle.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 | import groovy.lang.Closure;
4 | import groovy.lang.DelegatesTo;
5 | import groovy.transform.stc.ClosureParams;
6 | import groovy.transform.stc.FromString;
7 |
8 | public interface CanDefineStyle {
9 | /**
10 | * Declare a named style.
11 | * @param name name of the style
12 | * @param styleDefinition definition of the style
13 | */
14 | void style(String name, @DelegatesTo(CellStyleDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.CellStyleDefinition") Closure styleDefinition);
15 |
16 | void apply(Class extends Stylesheet> stylesheet);
17 | void apply(Stylesheet stylesheet);
18 | }
19 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/CellDefinition.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 | import groovy.lang.Closure;
4 | import groovy.lang.DelegatesTo;
5 | import groovy.transform.stc.ClosureParams;
6 | import groovy.transform.stc.FromString;
7 | import org.modelcatalogue.spreadsheet.api.Keywords;
8 |
9 | public interface CellDefinition extends HasStyle {
10 |
11 | /**
12 | * Sets the value.
13 | * @param value new value
14 | */
15 | void value(Object value);
16 | void name(String name);
17 | void formula(String formula);
18 | void comment(String comment);
19 | void comment(@DelegatesTo(CommentDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.CommentDefinition") Closure commentDefinition);
20 |
21 | LinkDefinition link(Keywords.To to);
22 |
23 | void colspan(int span);
24 | void rowspan(int span);
25 |
26 | /**
27 | * Sets the width as multiplier of standard character width.
28 | *
29 | * The width applies on the whole column.
30 | *
31 | * @param width the width as multiplier of standard character width
32 | * @return dimension modifier which allows to recalculate the number set to cm or inches
33 | */
34 | DimensionModifier width(double width);
35 |
36 | /**
37 | * Sets the height of the cell in points (multiples of 20 twips).
38 | *
39 | * The height applies on the whole row.
40 | *
41 | * @param height the height of the cell in points (multiples of 20 twips)
42 | * @return dimension modifier which allows to recalculate the number set to cm or inches
43 | */
44 | DimensionModifier height(double height);
45 |
46 | /**
47 | * Sets that the current column should have automatic width.
48 | * @param auto keyword
49 | */
50 | void width(Keywords.Auto auto);
51 |
52 | Keywords.Auto getAuto();
53 | Keywords.To getTo();
54 |
55 | /**
56 | * Add a new text run to the cell.
57 | *
58 | * This method can be called multiple times. The value of the cell will be result of appending all the text
59 | * values supplied.
60 | *
61 | * @param text new text run
62 | */
63 | void text(String text);
64 |
65 | /**
66 | * Add a new text run to the cell.
67 | *
68 | * This method can be called multiple times. The value of the cell will be result of appending all the text
69 | * values supplied.
70 | *
71 | * @param text new text run
72 | */
73 | void text(String text, @DelegatesTo(FontDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.FontDefinition") Closure fontConfiguration);
74 |
75 | ImageCreator png(Keywords.Image image);
76 | ImageCreator jpeg(Keywords.Image image);
77 | ImageCreator pict(Keywords.Image image);
78 | ImageCreator emf(Keywords.Image image);
79 | ImageCreator wmf(Keywords.Image image);
80 | ImageCreator dib(Keywords.Image image);
81 |
82 | Keywords.Image getImage();
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/CellStyleDefinition.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 | import groovy.lang.Closure;
4 | import groovy.lang.DelegatesTo;
5 | import groovy.transform.stc.ClosureParams;
6 | import groovy.transform.stc.FromString;
7 | import org.modelcatalogue.spreadsheet.api.*;
8 |
9 | public interface CellStyleDefinition extends HTMLColorProvider, ForegroundFillProvider {
10 |
11 | void base(String stylename);
12 |
13 | void background(String hexColor);
14 | void background(Color color);
15 |
16 | void foreground(String hexColor);
17 | void foreground(Color color);
18 |
19 | void fill(ForegroundFill fill);
20 |
21 | void font(@DelegatesTo(FontDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.FontDefinition") Closure fontConfiguration);
22 |
23 | /**
24 | * Sets the indent of the cell in spaces.
25 | * @param indent the indent of the cell in spaces
26 | */
27 | void indent(int indent);
28 |
29 | /**
30 | * Enables word wrapping
31 | *
32 | * @param text keyword
33 | */
34 | void wrap(Keywords.Text text);
35 |
36 | Keywords.Text getText();
37 |
38 | /**
39 | * Sets the rotation from 0 to 180 (flipped).
40 | * @param rotation the rotation from 0 to 180 (flipped)
41 | */
42 | void rotation(int rotation);
43 |
44 | void format(String format);
45 |
46 | HorizontalAlignmentConfigurer align(Keywords.VerticalAlignment alignment);
47 |
48 | /**
49 | * Configures all the borders of the cell.
50 | * @param borderConfiguration border configuration closure
51 | */
52 | void border(@DelegatesTo(BorderDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.BorderDefinition") Closure borderConfiguration);
53 |
54 | /**
55 | * Configures one border of the cell.
56 | * @param location border to be configured
57 | * @param borderConfiguration border configuration closure
58 | */
59 | void border(Keywords.BorderSide location, @DelegatesTo(BorderDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.BorderDefinition") Closure borderConfiguration);
60 |
61 | /**
62 | * Configures two borders of the cell.
63 | * @param first first border to be configured
64 | * @param second second border to be configured
65 | * @param borderConfiguration border configuration closure
66 | */
67 | void border(Keywords.BorderSide first, Keywords.BorderSide second, @DelegatesTo(BorderDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.BorderDefinition") Closure borderConfiguration);
68 |
69 | /**
70 | * Configures three borders of the cell.
71 | * @param first first border to be configured
72 | * @param second second border to be configured
73 | * @param third third border to be configured
74 | * @param borderConfiguration border configuration closure
75 | */
76 | void border(Keywords.BorderSide first, Keywords.BorderSide second, Keywords.BorderSide third, @DelegatesTo(BorderDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.BorderDefinition") Closure borderConfiguration);
77 |
78 | Keywords.PureVerticalAlignment getCenter();
79 | Keywords.PureVerticalAlignment getJustify();
80 | Keywords.PureVerticalAlignment getDistributed();
81 |
82 | // keywords
83 | Keywords.PureBorderSide getLeft();
84 | Keywords.PureBorderSide getRight();
85 |
86 | Keywords.BorderSideAndVerticalAlignment getTop();
87 | Keywords.BorderSideAndVerticalAlignment getBottom();
88 | }
89 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/CommentDefinition.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 | public interface CommentDefinition {
4 |
5 | int DEFAULT_WIDTH = 3;
6 | int DEFAULT_HEIGHT = 3;
7 |
8 | void author(String author);
9 | void text(String text);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/DimensionModifier.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 | /**
4 | * Allows to alter the height of the row in centimeters or
5 | */
6 | public interface DimensionModifier {
7 |
8 | /**
9 | * Converts the dimension to centimeters.
10 | *
11 | * This feature is currently experimental.
12 | * @return null to comply with getter signatures
13 | */
14 | Object getCm();
15 |
16 | /**
17 | * Converts the dimension to inches.
18 | *
19 | * This feature is currently experimental.
20 | * @return null to comply with getter signatures
21 | */
22 | Object getInch();
23 |
24 | /**
25 | * Converts the dimension to inches.
26 | *
27 | * This feature is currently experimental.
28 | * @return null to comply with getter signatures
29 | */
30 | Object getInches();
31 | }
32 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/FitDimension.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 | public interface FitDimension {
4 |
5 | void to(int numberOfPages);
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/FontDefinition.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 | import org.modelcatalogue.spreadsheet.api.Color;
4 | import org.modelcatalogue.spreadsheet.api.FontStyle;
5 | import org.modelcatalogue.spreadsheet.api.FontStylesProvider;
6 | import org.modelcatalogue.spreadsheet.api.HTMLColorProvider;
7 |
8 | public interface FontDefinition extends HTMLColorProvider, FontStylesProvider {
9 |
10 | void color(String hexColor);
11 | void color(Color color);
12 |
13 | void size(int size);
14 | void name(String name);
15 |
16 | void make(FontStyle first, FontStyle... other);
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/HasStyle.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 | import groovy.lang.Closure;
4 | import groovy.lang.DelegatesTo;
5 | import groovy.transform.stc.ClosureParams;
6 | import groovy.transform.stc.FromString;
7 |
8 | public interface HasStyle {
9 |
10 | /**
11 | * Applies a customized named style to the current element.
12 | *
13 | * @param name the name of the style
14 | * @param styleDefinition the definition of the style customizing the predefined style
15 | */
16 | void style(String name, @DelegatesTo(CellStyleDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.CellStyleDefinition") Closure styleDefinition);
17 |
18 | /**
19 | * Applies a customized named style to the current element.
20 | *
21 | * @param names the names of the styles
22 | * @param styleDefinition the definition of the style customizing the predefined style
23 | */
24 | void styles(Iterable names, @DelegatesTo(CellStyleDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.CellStyleDefinition") Closure styleDefinition);
25 |
26 | /**
27 | * Applies the style defined by the closure to the current element.
28 | * @param styleDefinition the definition of the style
29 | */
30 | void style(@DelegatesTo(CellStyleDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.CellStyleDefinition") Closure styleDefinition);
31 |
32 | /**
33 | * Applies the named style to the current element.
34 | *
35 | * The style can be changed no longer.
36 | *
37 | * @param name the name of the style
38 | */
39 | void style(String name);
40 |
41 | /**
42 | * Applies the named style to the current element.
43 | *
44 | * The style can be changed no longer.
45 | *
46 | * @param names style names to be applied
47 | */
48 | void styles(String... names);
49 | /**
50 | * Applies the named style to the current element.
51 | *
52 | * The style can be changed no longer.
53 | *
54 | * @param names style names to be applied
55 | */
56 | void styles(Iterable names);
57 | }
58 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/ImageCreator.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 | import java.io.InputStream;
4 |
5 | public interface ImageCreator {
6 |
7 | void from(String fileOrUrl);
8 | void from(InputStream stream);
9 | void from(byte[] imageData);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/LinkDefinition.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 | import java.util.Map;
4 |
5 | public interface LinkDefinition {
6 |
7 | void name(String name);
8 |
9 | void email(String email);
10 | void email(Map parameters, String email);
11 |
12 | void url(String url);
13 |
14 | void file(String path);
15 | }
16 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/PageDefinition.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 | import org.modelcatalogue.spreadsheet.api.Keywords;
4 | import org.modelcatalogue.spreadsheet.api.PageSettingsProvider;
5 |
6 | public interface PageDefinition extends PageSettingsProvider {
7 |
8 | void orientation(Keywords.Orientation orientation);
9 | void paper(Keywords.Paper paper);
10 | FitDimension fit(Keywords.Fit widthOrHeight);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/RowDefinition.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 |
4 | import groovy.lang.Closure;
5 | import groovy.lang.DelegatesTo;
6 | import groovy.transform.stc.ClosureParams;
7 | import groovy.transform.stc.FromString;
8 |
9 | public interface RowDefinition extends HasStyle {
10 |
11 | void cell();
12 | void cell(Object value);
13 | void cell(@DelegatesTo(CellDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.CellDefinition") Closure cellDefinition);
14 | void cell(int column, @DelegatesTo(CellDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.CellDefinition") Closure cellDefinition);
15 | void cell(String column, @DelegatesTo(CellDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.CellDefinition") Closure cellDefinition);
16 |
17 | void group(@DelegatesTo(RowDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.RowDefinition") Closure insideGroupDefinition);
18 | void collapse(@DelegatesTo(RowDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.RowDefinition") Closure insideGroupDefinition);
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/SheetDefinition.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 |
4 | import groovy.lang.Closure;
5 | import groovy.lang.DelegatesTo;
6 | import groovy.transform.stc.ClosureParams;
7 | import groovy.transform.stc.FromString;
8 | import org.modelcatalogue.spreadsheet.api.Keywords;
9 |
10 | public interface SheetDefinition {
11 |
12 | /**
13 | * Crates new empty row.
14 | */
15 | void row();
16 |
17 | /**
18 | * Creates new row in the spreadsheet.
19 | * @param rowDefinition closure defining the content of the row
20 | */
21 | void row(@DelegatesTo(RowDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.RowDefinition") Closure rowDefinition);
22 |
23 | /**
24 | * Creates new row in the spreadsheet.
25 | * @param row row number (1 based - the same as is shown in the file)
26 | * @param rowDefinition closure defining the content of the row
27 | */
28 | void row(int row, @DelegatesTo(RowDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.RowDefinition") Closure rowDefinition);
29 |
30 | /**
31 | * Freeze some column or row or both.
32 | * @param column last freeze column
33 | * @param row last freeze row
34 | */
35 | void freeze(int column, int row);
36 |
37 | /**
38 | * Freeze some column or row or both.
39 | * @param column last freeze column
40 | * @param row last freeze row
41 | */
42 | void freeze(String column, int row);
43 |
44 | void group(@DelegatesTo(SheetDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.SheetDefinition") Closure insideGroupDefinition);
45 | void collapse(@DelegatesTo(SheetDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.SheetDefinition") Closure insideGroupDefinition);
46 |
47 | Object getLocked();
48 |
49 | void password(String password);
50 |
51 | void filter(Keywords.Auto auto);
52 | Keywords.Auto getAuto();
53 |
54 | /**
55 | * Configures the basic page settings.
56 | * @param pageDefinition closure defining the page settings
57 | */
58 | void page(@DelegatesTo(PageDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.PageDefinition") Closure pageDefinition);
59 |
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/SpreadsheetBuilder.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 | import groovy.lang.Closure;
4 | import groovy.lang.DelegatesTo;
5 | import groovy.transform.stc.ClosureParams;
6 | import groovy.transform.stc.FromString;
7 |
8 | import java.io.File;
9 | import java.io.InputStream;
10 |
11 | public interface SpreadsheetBuilder {
12 |
13 | SpreadsheetDefinition build(@DelegatesTo(WorkbookDefinition.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.WorkbookDefinition") Closure workbookDefinition);
14 | SpreadsheetDefinition build(InputStream template, @DelegatesTo(WorkbookDefinition.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.WorkbookDefinition") Closure workbookDefinition);
15 | SpreadsheetDefinition build(File template, @DelegatesTo(WorkbookDefinition.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.WorkbookDefinition") Closure workbookDefinition);
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/SpreadsheetDefinition.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 | import java.io.File;
4 | import java.io.OutputStream;
5 |
6 | public interface SpreadsheetDefinition {
7 |
8 | void writeTo(OutputStream outputStream);
9 | void writeTo(File file);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/Stylesheet.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 | public interface Stylesheet {
4 |
5 | void declareStyles(CanDefineStyle stylable);
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/builder/api/WorkbookDefinition.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.api;
2 |
3 | import groovy.lang.Closure;
4 | import groovy.lang.DelegatesTo;
5 | import groovy.transform.stc.ClosureParams;
6 | import groovy.transform.stc.FromString;
7 |
8 | public interface WorkbookDefinition extends CanDefineStyle {
9 |
10 | void sheet(String name, @DelegatesTo(SheetDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.SheetDefinition") Closure sheetDefinition);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/api/AbstractSpreadsheetCriteriaResult.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.api;
2 |
3 | import org.modelcatalogue.spreadsheet.api.Cell;
4 |
5 | import java.util.Iterator;
6 |
7 | public abstract class AbstractSpreadsheetCriteriaResult implements SpreadsheetCriteriaResult {
8 |
9 | @Override
10 | public Iterator iterator() {
11 | return getCells().iterator();
12 | }
13 |
14 | @Override
15 | public String toString() {
16 | return getCells().toString();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/api/BorderCriterion.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.api;
2 |
3 | import org.modelcatalogue.spreadsheet.api.BorderStyle;
4 | import org.modelcatalogue.spreadsheet.api.BorderStyleProvider;
5 | import org.modelcatalogue.spreadsheet.api.Color;
6 |
7 | public interface BorderCriterion extends BorderStyleProvider {
8 |
9 | void style(BorderStyle style);
10 | void style(Predicate predicate);
11 |
12 | void color(String hexColor);
13 | void color(Color color);
14 | void color(Predicate predicate);
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/api/CellCriterion.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.api;
2 |
3 | import groovy.lang.Closure;
4 | import groovy.lang.DelegatesTo;
5 | import groovy.transform.stc.ClosureParams;
6 | import groovy.transform.stc.FromString;
7 | import org.modelcatalogue.spreadsheet.api.Comment;
8 |
9 | import java.util.Date;
10 |
11 | public interface CellCriterion {
12 |
13 | void date(Date value);
14 | void date(Predicate predicate);
15 |
16 | void number(Double value);
17 | void number(Predicate predicate);
18 |
19 | void string(String value);
20 | void string(Predicate predicate);
21 |
22 | void value(Object value);
23 | void bool(Boolean value);
24 |
25 | void style(@DelegatesTo(CellStyleCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.CellStyleCriterion") Closure styleCriterion);
26 |
27 | void rowspan(int span);
28 | void rowspan(Predicate predicate);
29 | void colspan(int span);
30 | void colspan(Predicate predicate);
31 |
32 |
33 | void name(String name);
34 | void name(Predicate predicate);
35 |
36 | void comment(String comment);
37 | void comment(Predicate predicate);
38 |
39 | void or(@DelegatesTo(CellCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.CellCriterion") Closure sheetCriterion);
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/api/CellStyleCriterion.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.api;
2 |
3 | import groovy.lang.Closure;
4 | import groovy.lang.DelegatesTo;
5 | import groovy.transform.stc.ClosureParams;
6 | import groovy.transform.stc.FromString;
7 | import org.modelcatalogue.spreadsheet.api.*;
8 |
9 | public interface CellStyleCriterion extends HTMLColorProvider, ForegroundFillProvider {
10 |
11 | void background(String hexColor);
12 | void background(Color color);
13 | void background(Predicate predicate);
14 |
15 | void foreground(String hexColor);
16 | void foreground(Color color);
17 | void foreground(Predicate predicate);
18 |
19 | void fill(ForegroundFill fill);
20 | void fill(Predicate predicate);
21 |
22 | void indent(int indent);
23 | void indent(Predicate predicate);
24 |
25 | void rotation(int rotation);
26 | void rotation(Predicate predicate);
27 |
28 | void format(String format);
29 | void format(Predicate format);
30 |
31 | void font(@DelegatesTo(FontCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.FontCriterion") Closure fontCriterion);
32 |
33 | /**
34 | * Configures all the borders of the cell.
35 | * @param borderConfiguration border configuration closure
36 | */
37 | void border(@DelegatesTo(BorderCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.BorderCriterion") Closure borderConfiguration);
38 |
39 | /**
40 | * Configures one border of the cell.
41 | * @param location border to be configured
42 | * @param borderConfiguration border configuration closure
43 | */
44 | void border(Keywords.BorderSide location, @DelegatesTo(BorderCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.BorderCriterion") Closure borderConfiguration);
45 |
46 | /**
47 | * Configures two borders of the cell.
48 | * @param first first border to be configured
49 | * @param second second border to be configured
50 | * @param borderConfiguration border configuration closure
51 | */
52 | void border(Keywords.BorderSide first, Keywords.BorderSide second, @DelegatesTo(BorderCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.BorderCriterion") Closure borderConfiguration);
53 |
54 | /**
55 | * Configures three borders of the cell.
56 | * @param first first border to be configured
57 | * @param second second border to be configured
58 | * @param third third border to be configured
59 | * @param borderConfiguration border configuration closure
60 | */
61 | void border(Keywords.BorderSide first, Keywords.BorderSide second, Keywords.BorderSide third, @DelegatesTo(BorderCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.BorderCriterion") Closure borderConfiguration);
62 |
63 | // keywords
64 | Keywords.PureBorderSide getLeft();
65 | Keywords.PureBorderSide getRight();
66 |
67 | Keywords.BorderSideAndVerticalAlignment getTop();
68 | Keywords.BorderSideAndVerticalAlignment getBottom();
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/api/FontCriterion.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.api;
2 |
3 | import org.modelcatalogue.spreadsheet.api.Color;
4 | import org.modelcatalogue.spreadsheet.api.FontStyle;
5 | import org.modelcatalogue.spreadsheet.api.FontStylesProvider;
6 |
7 | import java.util.EnumSet;
8 |
9 | public interface FontCriterion extends FontStylesProvider {
10 |
11 | void color(String hexColor);
12 | void color(Color color);
13 | void color(Predicate predicate);
14 |
15 | void size(int size);
16 | void size(Predicate predicate);
17 |
18 | void name(String name);
19 | void name(Predicate predicate);
20 |
21 | void make(FontStyle first, FontStyle... other);
22 | void make(Predicate> predicate);
23 | }
24 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/api/PageCriterion.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.api;
2 |
3 | import org.modelcatalogue.spreadsheet.api.Keywords;
4 | import org.modelcatalogue.spreadsheet.api.PageSettingsProvider;
5 |
6 | public interface PageCriterion extends PageSettingsProvider {
7 |
8 | void orientation(Keywords.Orientation orientation);
9 | void paper(Keywords.Paper paper);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/api/Predicate.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.api;
2 |
3 | public interface Predicate {
4 |
5 | /**
6 | * @param o object to be evaluated
7 | * @return true if the object passes the condition
8 | */
9 | boolean test(T o);
10 |
11 | class EqualsTo implements Predicate {
12 | private final Object other;
13 |
14 | public EqualsTo(Object other) {
15 | this.other = other;
16 | }
17 |
18 | @Override
19 | public boolean test(T o) {
20 | return other.equals(o);
21 | }
22 | }
23 |
24 | class Negation implements Predicate {
25 | private final Predicate otherPredicate;
26 |
27 | public Negation(Predicate otherPredicate) {
28 | this.otherPredicate = otherPredicate;
29 | }
30 |
31 | @Override
32 | public boolean test(T o) {
33 | return !otherPredicate.test(o);
34 | }
35 | }
36 |
37 | class Match implements Predicate {
38 | private final String regexp;
39 |
40 | public Match(String regexp) {
41 | this.regexp = regexp;
42 | }
43 |
44 | @Override
45 | public boolean test(String o) {
46 | return o.matches(regexp);
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/api/RowCriterion.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.api;
2 |
3 | import groovy.lang.Closure;
4 | import groovy.lang.DelegatesTo;
5 | import groovy.transform.stc.ClosureParams;
6 | import groovy.transform.stc.FromString;
7 | import org.modelcatalogue.spreadsheet.api.Cell;
8 |
9 | public interface RowCriterion {
10 |
11 | Predicate column(int number);
12 | Predicate columnAsString(String name);
13 | Predicate range(int from, int to);
14 | Predicate range(String from, String to);
15 |
16 | void cell(Predicate predicate);
17 | void cell(int column);
18 | void cell(String column);
19 |
20 | void cell(@DelegatesTo(CellCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.CellCriterion") Closure cellCriterion);
21 | void cell(int column, @DelegatesTo(CellCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.CellCriterion") Closure cellCriterion);
22 | void cell(String column, @DelegatesTo(CellCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.CellCriterion") Closure cellCriterion);
23 | void cell(Predicate predicate, @DelegatesTo(CellCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.CellCriterion") Closure cellCriterion);
24 | void or(@DelegatesTo(RowCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.RowCriterion") Closure rowCriterion);
25 | }
26 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/api/SheetCriterion.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.api;
2 |
3 | import groovy.lang.Closure;
4 | import groovy.lang.DelegatesTo;
5 | import groovy.transform.stc.ClosureParams;
6 | import groovy.transform.stc.FromString;
7 | import org.modelcatalogue.spreadsheet.api.Page;
8 | import org.modelcatalogue.spreadsheet.api.Row;
9 |
10 | public interface SheetCriterion {
11 |
12 | Predicate number(int row);
13 | Predicate range(int from, int to);
14 |
15 | void row(@DelegatesTo(RowCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.RowCriterion") Closure rowCriterion);
16 | void row(int row);
17 | void row(int row, @DelegatesTo(RowCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.RowCriterion") Closure rowCriterion);
18 | void row(Predicate predicate, @DelegatesTo(RowCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.RowCriterion") Closure rowCriterion);
19 | void row(Predicate predicate);
20 | void page(@DelegatesTo(PageCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.PageCriterion") Closure pageCriterion);
21 | void page(Predicate predicate);
22 | void or(@DelegatesTo(SheetCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.SheetCriterion") Closure sheetCriterion);
23 | }
24 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/api/SpreadsheetCriteria.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.api;
2 |
3 | import groovy.lang.Closure;
4 | import groovy.lang.DelegatesTo;
5 | import groovy.transform.stc.ClosureParams;
6 | import groovy.transform.stc.FromString;
7 | import org.modelcatalogue.spreadsheet.api.Cell;
8 |
9 | import java.io.FileNotFoundException;
10 | import java.util.Collection;
11 |
12 |
13 | /**
14 | * Cell matcher uses the builder like syntax to find cells within the workbook.
15 | * Not all the constructs are be supported at the moment.
16 | * Check the documentation for the list of all supported features.
17 | */
18 | public interface SpreadsheetCriteria {
19 |
20 | SpreadsheetCriteriaResult all();
21 | SpreadsheetCriteriaResult query(@DelegatesTo(WorkbookCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.WorkbookCriterion") Closure workbookCriterion) throws FileNotFoundException;
22 | Cell find(@DelegatesTo(WorkbookCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.WorkbookCriterion") Closure workbookCriterion) throws FileNotFoundException;
23 | boolean exists(@DelegatesTo(WorkbookCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.WorkbookCriterion") Closure workbookCriterion) throws FileNotFoundException;
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/api/SpreadsheetCriteriaFactory.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.api;
2 |
3 | import java.io.File;
4 | import java.io.FileNotFoundException;
5 | import java.io.InputStream;
6 |
7 |
8 | /**
9 | * Cell matcher uses the builder like syntax to find cells within the workbook.
10 | * Not all the constructs are be supported at the moment.
11 | * Check the documentation for the list of all supported features.
12 | */
13 | public interface SpreadsheetCriteriaFactory {
14 |
15 | SpreadsheetCriteria forFile(File spreadsheet) throws FileNotFoundException;
16 | SpreadsheetCriteria forStream(InputStream inputStream);
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/api/SpreadsheetCriteriaResult.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.api;
2 |
3 | import org.modelcatalogue.spreadsheet.api.Cell;
4 | import org.modelcatalogue.spreadsheet.api.Row;
5 | import org.modelcatalogue.spreadsheet.api.Sheet;
6 |
7 | import java.util.Collection;
8 |
9 | public interface SpreadsheetCriteriaResult extends Iterable {
10 |
11 | /**
12 | * Returns all cells matching the criteria.
13 | * @return all cells matching the criteria
14 | */
15 | Collection getCells();
16 |
17 | /**
18 | * Returns all rows matching the criteria. If any cell criteria is present, at least one cell in the row
19 | * must pass the test.
20 | * @return all rows matching the criteria
21 | */
22 | Collection getRows();
23 |
24 | /**
25 | * Returns all sheets matching the criteria. If any row or cell criteria is present at least one row (or cell)
26 | * must pass the test.
27 | * @return all the sheets matching the criteria.
28 | */
29 | Collection getSheets();
30 |
31 | /**
32 | * Returns first cell matching the criteria or null.
33 | * @return first cell matching the criteria or null
34 | */
35 | Cell getCell();
36 |
37 | /**
38 | * Returns first row matching the criteria or null.
39 | * @return first row matching the criteria or null
40 | */
41 | Row getRow();
42 |
43 | /**
44 | * Returns first sheet matching the criteria or null.
45 | * @return first sheet matching the criteria or null
46 | */
47 | Sheet getSheet();
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/api/Transformation.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.api;
2 |
3 | public interface Transformation {
4 |
5 | R transform(S source);
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/api/WorkbookCriterion.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.api;
2 |
3 | import groovy.lang.Closure;
4 | import groovy.lang.DelegatesTo;
5 | import groovy.transform.stc.ClosureParams;
6 | import groovy.transform.stc.FromString;
7 | import org.modelcatalogue.spreadsheet.api.Sheet;
8 |
9 | public interface WorkbookCriterion {
10 |
11 | Predicate name(String name);
12 | Predicate name(Predicate namePredicate);
13 |
14 | void sheet(String name);
15 | void sheet(String name, @DelegatesTo(SheetCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.SheetCriterion") Closure sheetCriterion);
16 |
17 | void sheet(Predicate predicate);
18 | void sheet(Predicate predicate, @DelegatesTo(SheetCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.SheetCriterion") Closure sheetCriterion);
19 |
20 | void sheet(@DelegatesTo(SheetCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.SheetCriterion") Closure sheetCriterion);
21 |
22 | void or(@DelegatesTo(WorkbookCriterion.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.WorkbookCriterion") Closure workbookCriterion);
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/simple/AbstractCriterion.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.simple;
2 |
3 | import groovy.lang.Closure;
4 | import org.codehaus.groovy.runtime.DefaultGroovyMethods;
5 | import org.modelcatalogue.spreadsheet.query.api.Predicate;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | abstract class AbstractCriterion implements Predicate {
11 |
12 | private final List> predicates = new ArrayList>();
13 | private final boolean disjoint;
14 |
15 | AbstractCriterion() {
16 | this(false);
17 | }
18 |
19 | AbstractCriterion(boolean disjoint) {
20 | this.disjoint = disjoint;
21 | }
22 |
23 | @Override
24 | public boolean test(T o) {
25 | if (disjoint) {
26 | return passesAnyCondition(o);
27 | }
28 | return passesAllConditions(o);
29 | }
30 |
31 | abstract Predicate newDisjointCriterionInstance();
32 |
33 | public void or(Closure sheetCriterion) {
34 | Predicate criterion = newDisjointCriterionInstance();
35 | DefaultGroovyMethods.with(criterion, sheetCriterion);
36 | addCondition(criterion);
37 | }
38 |
39 | void addCondition(Predicate predicate) {
40 | predicates.add(predicate);
41 | }
42 |
43 | private boolean passesAnyCondition(T object) {
44 | if (predicates.isEmpty()) {
45 | return true;
46 | }
47 | for (Predicate predicate : predicates) {
48 | if (predicate.test(object)) {
49 | return true;
50 | }
51 | }
52 | return false;
53 | }
54 |
55 | private boolean passesAllConditions(T object) {
56 | if (predicates.isEmpty()) {
57 | return true;
58 | }
59 | for (Predicate predicate : predicates) {
60 | if (!predicate.test(object)) {
61 | return false;
62 | }
63 | }
64 | return true;
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/simple/SimpleBorderCriterion.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.simple;
2 |
3 | import org.modelcatalogue.spreadsheet.api.*;
4 | import org.modelcatalogue.spreadsheet.query.api.BorderCriterion;
5 | import org.modelcatalogue.spreadsheet.query.api.Predicate;
6 |
7 | final class SimpleBorderCriterion extends AbstractBorderProvider implements BorderCriterion {
8 |
9 | private final SimpleCellCriterion parent;
10 | private final Keywords.BorderSide side;
11 |
12 | SimpleBorderCriterion(SimpleCellCriterion parent, Keywords.BorderSide side) {
13 | this.parent = parent;
14 | this.side = side;
15 | }
16 |
17 | @Override
18 | public void style(final BorderStyle borderStyle) {
19 | parent.addCondition(new Predicate() {
20 | @Override
21 | public boolean test(Cell o) {
22 | CellStyle style = o.getStyle();
23 | if (style == null) {
24 | return false;
25 | }
26 | Border border = style.getBorder(side);
27 | return border != null && borderStyle.equals(border.getStyle());
28 | }
29 | });
30 | }
31 |
32 | @Override
33 | public void style(final Predicate predicate) {
34 | parent.addCondition(new Predicate() {
35 | @Override
36 | public boolean test(Cell o) {
37 | CellStyle style = o.getStyle();
38 | if (style == null) {
39 | return false;
40 | }
41 | Border border = style.getBorder(side);
42 | return border != null && predicate.test(border.getStyle());
43 | }
44 | });
45 | }
46 |
47 | @Override
48 | public void color(String hexColor) {
49 | color(new Color(hexColor));
50 | }
51 |
52 | @Override
53 | public void color(final Color color) {
54 | parent.addCondition(new Predicate() {
55 | @Override
56 | public boolean test(Cell o) {
57 | CellStyle style = o.getStyle();
58 | if (style == null) {
59 | return false;
60 | }
61 | Border border = style.getBorder(side);
62 | return border != null && color.equals(border.getColor());
63 | }
64 | });
65 | }
66 |
67 | @Override
68 | public void color(final Predicate predicate) {
69 | parent.addCondition(new Predicate() {
70 | @Override
71 | public boolean test(Cell o) {
72 | CellStyle style = o.getStyle();
73 | if (style == null) {
74 | return false;
75 | }
76 | Border border = style.getBorder(side);
77 | return border != null && predicate.test(border.getColor());
78 | }
79 | });
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/simple/SimpleCellCriterion.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.simple;
2 |
3 | import groovy.lang.Closure;
4 | import groovy.lang.DelegatesTo;
5 | import groovy.transform.stc.ClosureParams;
6 | import groovy.transform.stc.FromString;
7 | import org.codehaus.groovy.runtime.DefaultGroovyMethods;
8 | import org.modelcatalogue.spreadsheet.api.Cell;
9 | import org.modelcatalogue.spreadsheet.api.Comment;
10 | import org.modelcatalogue.spreadsheet.query.api.CellCriterion;
11 | import org.modelcatalogue.spreadsheet.query.api.CellStyleCriterion;
12 | import org.modelcatalogue.spreadsheet.query.api.Predicate;
13 |
14 | import java.util.Calendar;
15 | import java.util.Date;
16 |
17 | final class SimpleCellCriterion extends AbstractCriterion implements CellCriterion {
18 |
19 | SimpleCellCriterion() {
20 | }
21 |
22 | private SimpleCellCriterion(boolean disjoint) {
23 | super(disjoint);
24 | }
25 |
26 | @Override
27 | public void date(final Date value) {
28 | addValueCondition(value, Date.class);
29 | }
30 |
31 | @Override
32 | public void date(final Predicate predicate) {
33 | addValueCondition(predicate, Date.class);
34 | }
35 |
36 | @Override
37 | public void number(Double value) {
38 | addValueCondition(value, Double.class);
39 | }
40 |
41 | @Override
42 | public void number(Predicate predicate) {
43 | addValueCondition(predicate, Double.class);
44 | }
45 |
46 | @Override
47 | public void string(String value) {
48 | addValueCondition(value, String.class);
49 | }
50 |
51 | @Override
52 | public void string(Predicate predicate) {
53 | addValueCondition(predicate, String.class);
54 | }
55 |
56 | @Override
57 | public void value(Object value) {
58 | if (value == null) {
59 | string("");
60 | return;
61 | }
62 | if (value instanceof Date) {
63 | date((Date) value);
64 | return;
65 | }
66 | if (value instanceof Calendar) {
67 | date(((Calendar) value).getTime());
68 | return;
69 | }
70 | if (value instanceof Number) {
71 | number(((Number) value).doubleValue());
72 | return;
73 | }
74 | if (value instanceof Boolean) {
75 | bool((Boolean) value);
76 | }
77 | string(value.toString());
78 | }
79 |
80 | @Override
81 | public void name(final String name) {
82 | addCondition(new Predicate() {
83 | @Override
84 | public boolean test(Cell o) {
85 | return name.equals(o.getName());
86 | }
87 | });
88 | }
89 |
90 | @Override
91 | public void comment(final String comment) {
92 | addCondition(new Predicate() {
93 | @Override
94 | public boolean test(Cell o) {
95 | return comment.equals(o.getComment().getText());
96 | }
97 | });
98 | }
99 |
100 | @Override
101 | public void bool(Boolean value) {
102 | addValueCondition(value, Boolean.class);
103 | }
104 |
105 |
106 | @Override
107 | public void style(@DelegatesTo(CellStyleCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.CellStyleCriterion") Closure styleCriterion) {
108 | SimpleCellStyleCriterion criterion = new SimpleCellStyleCriterion(this);
109 | DefaultGroovyMethods.with(criterion, styleCriterion);
110 | // no need to add criteria, they are added by the style criterion itself
111 | }
112 |
113 | @Override
114 | public void rowspan(final int span) {
115 | addCondition(new Predicate() {
116 | @Override
117 | public boolean test(Cell o) {
118 | return span == o.getRowspan();
119 | }
120 | });
121 | }
122 |
123 | @Override
124 | public void rowspan(final Predicate predicate) {
125 | addCondition(new Predicate() {
126 | @Override
127 | public boolean test(Cell o) {
128 | return predicate.test(o.getRowspan());
129 | }
130 | });
131 | }
132 |
133 | @Override
134 | public void colspan(final int span) {
135 | addCondition(new Predicate() {
136 | @Override
137 | public boolean test(Cell o) {
138 | return span == o.getColspan();
139 | }
140 | });
141 | }
142 |
143 | @Override
144 | public void colspan(final Predicate predicate) {
145 | addCondition(new Predicate() {
146 | @Override
147 | public boolean test(Cell o) {
148 | return predicate.test(o.getColspan());
149 | }
150 | });
151 | }
152 |
153 | @Override
154 | public void name(final Predicate predicate) {
155 | addCondition(new Predicate() {
156 | @Override
157 | public boolean test(Cell o) {
158 | return predicate.test(o.getName());
159 | }
160 | });
161 | }
162 |
163 | @Override
164 | public void comment(final Predicate predicate) {
165 | addCondition(new Predicate() {
166 | @Override
167 | public boolean test(Cell o) {
168 | return predicate.test(o.getComment());
169 | }
170 | });
171 | }
172 |
173 | private void addValueCondition(final T value, final Class type) {
174 | addCondition(new Predicate() {
175 | @Override
176 | public boolean test(Cell o) {
177 | try {
178 | return value.equals(o.read(type));
179 | } catch (Exception e) {
180 | return false;
181 | }
182 | }
183 | });
184 | }
185 |
186 | private void addValueCondition(final Predicate predicate, final Class type) {
187 | addCondition(new Predicate() {
188 | @Override
189 | public boolean test(Cell o) {
190 | try {
191 | return predicate.test(o.read(type));
192 | } catch (Exception e) {
193 | return false;
194 | }
195 | }
196 | });
197 | }
198 |
199 | @Override
200 | Predicate newDisjointCriterionInstance() {
201 | return new SimpleCellCriterion(true);
202 | }
203 | }
204 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/simple/SimpleCellStyleCriterion.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.simple;
2 |
3 | import groovy.lang.Closure;
4 | import groovy.lang.DelegatesTo;
5 | import groovy.transform.stc.ClosureParams;
6 | import groovy.transform.stc.FromString;
7 | import org.codehaus.groovy.runtime.DefaultGroovyMethods;
8 | import org.modelcatalogue.spreadsheet.api.Cell;
9 | import org.modelcatalogue.spreadsheet.api.Color;
10 | import org.modelcatalogue.spreadsheet.api.ForegroundFill;
11 | import org.modelcatalogue.spreadsheet.api.Keywords;
12 | import org.modelcatalogue.spreadsheet.query.api.BorderCriterion;
13 | import org.modelcatalogue.spreadsheet.query.api.CellStyleCriterion;
14 | import org.modelcatalogue.spreadsheet.query.api.Predicate;
15 | import org.modelcatalogue.spreadsheet.query.api.FontCriterion;
16 |
17 | final class SimpleCellStyleCriterion implements CellStyleCriterion {
18 |
19 | private final SimpleCellCriterion parent;
20 |
21 | SimpleCellStyleCriterion(SimpleCellCriterion parent) {
22 | this.parent = parent;
23 | }
24 |
25 | @Override
26 | public void background(final String hexColor) {
27 | parent.addCondition(new Predicate() {
28 | @Override
29 | public boolean test(Cell o) {
30 | return o.getStyle() != null && new Color(hexColor).equals(o.getStyle().getBackground());
31 | }
32 | });
33 | }
34 |
35 | @Override
36 | public void background(final Color color) {
37 | parent.addCondition(new Predicate() {
38 | @Override
39 | public boolean test(Cell o) {
40 | return o.getStyle() != null && color.equals(o.getStyle().getBackground());
41 | }
42 | });
43 | }
44 |
45 | @Override
46 | public void background(final Predicate predicate) {
47 | parent.addCondition(new Predicate() {
48 | @Override
49 | public boolean test(Cell o) {
50 | return o.getStyle() != null && predicate.test(o.getStyle().getBackground());
51 | }
52 | });
53 | }
54 |
55 | @Override
56 | public void foreground(final String hexColor) {
57 | parent.addCondition(new Predicate() {
58 | @Override
59 | public boolean test(Cell o) {
60 | return o.getStyle() != null && new Color(hexColor).equals(o.getStyle().getForeground());
61 | }
62 | });
63 | }
64 |
65 | @Override
66 | public void foreground(final Color color) {
67 | parent.addCondition(new Predicate() {
68 | @Override
69 | public boolean test(Cell o) {
70 | return o.getStyle() != null && color.equals(o.getStyle().getForeground());
71 | }
72 | });
73 | }
74 |
75 | @Override
76 | public void foreground(final Predicate predicate) {
77 | parent.addCondition(new Predicate() {
78 | @Override
79 | public boolean test(Cell o) {
80 | return o.getStyle() != null && predicate.test(o.getStyle().getForeground());
81 | }
82 | });
83 | }
84 |
85 | @Override
86 | public void fill(final ForegroundFill fill) {
87 | parent.addCondition(new Predicate() {
88 | @Override
89 | public boolean test(Cell o) {
90 | return o.getStyle() != null && fill.equals(o.getStyle().getFill());
91 | }
92 | });
93 | }
94 |
95 | @Override
96 | public void fill(final Predicate predicate) {
97 | parent.addCondition(new Predicate() {
98 | @Override
99 | public boolean test(Cell o) {
100 | return o.getStyle() != null && predicate.test(o.getStyle().getFill());
101 | }
102 | });
103 | }
104 |
105 | @Override
106 | public void indent(final int indent) {
107 | parent.addCondition(new Predicate() {
108 | @Override
109 | public boolean test(Cell o) {
110 | return o.getStyle() != null && indent == o.getStyle().getIndent();
111 | }
112 | });
113 | }
114 |
115 | @Override
116 | public void indent(final Predicate predicate) {
117 | parent.addCondition(new Predicate() {
118 | @Override
119 | public boolean test(Cell o) {
120 | return o.getStyle() != null && predicate.test(o.getStyle().getIndent());
121 | }
122 | });
123 | }
124 |
125 | @Override
126 | public void rotation(final int rotation) {
127 | parent.addCondition(new Predicate() {
128 | @Override
129 | public boolean test(Cell o) {
130 | return o.getStyle() != null && rotation == o.getStyle().getRotation();
131 | }
132 | });
133 | }
134 |
135 | @Override
136 | public void rotation(final Predicate predicate) {
137 | parent.addCondition(new Predicate() {
138 | @Override
139 | public boolean test(Cell o) {
140 | return o.getStyle() != null && predicate.test(o.getStyle().getRotation());
141 | }
142 | });
143 | }
144 |
145 | @Override
146 | public void format(final String format) {
147 | parent.addCondition(new Predicate() {
148 | @Override
149 | public boolean test(Cell o) {
150 | return o.getStyle() != null && format.equals(o.getStyle().getFormat());
151 | }
152 | });
153 | }
154 |
155 | @Override
156 | public void format(final Predicate format) {
157 | parent.addCondition(new Predicate() {
158 | @Override
159 | public boolean test(Cell o) {
160 | return o.getStyle() != null && format.test(o.getStyle().getFormat());
161 | }
162 | });
163 | }
164 |
165 | @Override
166 | public void font(@DelegatesTo(FontCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.FontCriterion") Closure fontCriterion) {
167 | SimpleFontCriterion simpleFontCriterion = new SimpleFontCriterion(parent);
168 | DefaultGroovyMethods.with(simpleFontCriterion, fontCriterion);
169 | }
170 |
171 | @Override
172 | public void border(@DelegatesTo(BorderCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.BorderCriterion") Closure borderConfiguration) {
173 | border(Keywords.BorderSide.BORDER_SIDES, borderConfiguration);
174 | }
175 |
176 | @Override
177 | public void border(Keywords.BorderSide location, @DelegatesTo(BorderCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.BorderCriterion") Closure borderConfiguration) {
178 | border(new Keywords.BorderSide[] {location}, borderConfiguration);
179 | }
180 |
181 | @Override
182 | public void border(Keywords.BorderSide first, Keywords.BorderSide second, @DelegatesTo(BorderCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.BorderCriterion") Closure borderConfiguration) {
183 | border(new Keywords.BorderSide[] {first, second}, borderConfiguration);
184 | }
185 |
186 | @Override
187 | public void border(Keywords.BorderSide first, Keywords.BorderSide second, Keywords.BorderSide third, @DelegatesTo(BorderCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.BorderCriterion") Closure borderConfiguration) {
188 | border(new Keywords.BorderSide[] {first, second, third}, borderConfiguration);
189 | }
190 |
191 | private void border(Keywords.BorderSide[] sides, @DelegatesTo(BorderCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.BorderCriterion") Closure borderConfiguration) {
192 | for (Keywords.BorderSide side : sides) {
193 | SimpleBorderCriterion criterion = new SimpleBorderCriterion(parent, side);
194 | DefaultGroovyMethods.with(criterion, borderConfiguration);
195 | }
196 | }
197 |
198 | @Override
199 | public ForegroundFill getNoFill() {
200 | return ForegroundFill.NO_FILL;
201 | }
202 |
203 | @Override
204 | public ForegroundFill getSolidForeground() {
205 | return ForegroundFill.SOLID_FOREGROUND;
206 | }
207 |
208 | @Override
209 | public ForegroundFill getFineDots() {
210 | return ForegroundFill.FINE_DOTS;
211 | }
212 |
213 | @Override
214 | public ForegroundFill getAltBars() {
215 | return ForegroundFill.ALT_BARS;
216 | }
217 |
218 | @Override
219 | public ForegroundFill getSparseDots() {
220 | return ForegroundFill.SPARSE_DOTS;
221 | }
222 |
223 | @Override
224 | public ForegroundFill getThickHorizontalBands() {
225 | return ForegroundFill.THICK_HORZ_BANDS;
226 | }
227 |
228 | @Override
229 | public ForegroundFill getThickVerticalBands() {
230 | return ForegroundFill.THICK_VERT_BANDS;
231 | }
232 |
233 | @Override
234 | public ForegroundFill getThickBackwardDiagonals() {
235 | return ForegroundFill.THICK_BACKWARD_DIAG;
236 | }
237 |
238 | @Override
239 | public ForegroundFill getThickForwardDiagonals() {
240 | return ForegroundFill.THICK_FORWARD_DIAG;
241 | }
242 |
243 | @Override
244 | public ForegroundFill getBigSpots() {
245 | return ForegroundFill.BIG_SPOTS;
246 | }
247 |
248 | @Override
249 | public ForegroundFill getBricks() {
250 | return ForegroundFill.BRICKS;
251 | }
252 |
253 | @Override
254 | public ForegroundFill getThinHorizontalBands() {
255 | return ForegroundFill.THIN_HORZ_BANDS;
256 | }
257 |
258 | @Override
259 | public ForegroundFill getThinVerticalBands() {
260 | return ForegroundFill.THIN_VERT_BANDS;
261 | }
262 |
263 | @Override
264 | public ForegroundFill getThinBackwardDiagonals() {
265 | return ForegroundFill.THIN_BACKWARD_DIAG;
266 | }
267 |
268 | @Override
269 | public ForegroundFill getThinForwardDiagonals() {
270 | return ForegroundFill.THICK_FORWARD_DIAG;
271 | }
272 |
273 | @Override
274 | public ForegroundFill getSquares() {
275 | return ForegroundFill.SQUARES;
276 | }
277 |
278 | @Override
279 | public ForegroundFill getDiamonds() {
280 | return ForegroundFill.DIAMONDS;
281 | }
282 |
283 | @Override
284 | public Keywords.PureBorderSide getLeft() {
285 | return Keywords.PureBorderSide.LEFT;
286 | }
287 |
288 | @Override
289 | public Keywords.PureBorderSide getRight() {
290 | return Keywords.PureBorderSide.RIGHT;
291 | }
292 |
293 | @Override
294 | public Keywords.BorderSideAndVerticalAlignment getTop() {
295 | return Keywords.BorderSideAndVerticalAlignment.TOP;
296 | }
297 |
298 | @Override
299 | public Keywords.BorderSideAndVerticalAlignment getBottom() {
300 | return Keywords.BorderSideAndVerticalAlignment.BOTTOM;
301 | }
302 |
303 | }
304 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/simple/SimpleFontCriterion.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.simple;
2 |
3 | import org.modelcatalogue.spreadsheet.api.*;
4 | import org.modelcatalogue.spreadsheet.query.api.Predicate;
5 | import org.modelcatalogue.spreadsheet.query.api.FontCriterion;
6 |
7 | import java.util.EnumSet;
8 |
9 | final class SimpleFontCriterion implements FontCriterion {
10 |
11 | private final SimpleCellCriterion parent;
12 |
13 | SimpleFontCriterion(SimpleCellCriterion parent) {
14 | this.parent = parent;
15 | }
16 |
17 | @Override
18 | public void color(String hexColor) {
19 | color(new Color(hexColor));
20 | }
21 |
22 | @Override
23 | public void color(final Color color) {
24 | parent.addCondition(new Predicate() {
25 | @Override
26 | public boolean test(Cell o) {
27 | CellStyle style = o.getStyle();
28 | if (style == null) {
29 | return false;
30 | }
31 | Font font = style.getFont();
32 | return font != null && color.equals(font.getColor());
33 | }
34 | });
35 | }
36 |
37 | @Override
38 | public void color(final Predicate conition) {
39 | parent.addCondition(new Predicate() {
40 | @Override
41 | public boolean test(Cell o) {
42 | CellStyle style = o.getStyle();
43 | if (style == null) {
44 | return false;
45 | }
46 | Font font = style.getFont();
47 | return font != null && conition.test(font.getColor());
48 | }
49 | });
50 | }
51 |
52 | @Override
53 | public void size(final int size) {
54 | parent.addCondition(new Predicate() {
55 | @Override
56 | public boolean test(Cell o) {
57 | CellStyle style = o.getStyle();
58 | if (style == null) {
59 | return false;
60 | }
61 | Font font = style.getFont();
62 | return font != null && size == font.getSize();
63 | }
64 | });
65 | }
66 |
67 | @Override
68 | public void size(final Predicate predicate) {
69 | parent.addCondition(new Predicate() {
70 | @Override
71 | public boolean test(Cell o) {
72 | CellStyle style = o.getStyle();
73 | if (style == null) {
74 | return false;
75 | }
76 | Font font = style.getFont();
77 | return font != null && predicate.test(font.getSize());
78 | }
79 | });
80 | }
81 |
82 | @Override
83 | public void name(final String name) {
84 | parent.addCondition(new Predicate() {
85 | @Override
86 | public boolean test(Cell o) {
87 | CellStyle style = o.getStyle();
88 | if (style == null) {
89 | return false;
90 | }
91 | Font font = style.getFont();
92 | return font != null && name.equals(font.getName());
93 | }
94 | });
95 | }
96 |
97 | @Override
98 | public void name(final Predicate predicate) {
99 | parent.addCondition(new Predicate() {
100 | @Override
101 | public boolean test(Cell o) {
102 | CellStyle style = o.getStyle();
103 | if (style == null) {
104 | return false;
105 | }
106 | Font font = style.getFont();
107 | return font != null && predicate.test(font.getName());
108 | }
109 | });
110 | }
111 |
112 | @Override
113 | public void make(final FontStyle first, final FontStyle... other) {
114 | parent.addCondition(new Predicate() {
115 | @Override
116 | public boolean test(Cell o) {
117 | CellStyle style = o.getStyle();
118 | if (style == null) {
119 | return false;
120 | }
121 | Font font = style.getFont();
122 | if (font == null) {
123 | return false;
124 | }
125 |
126 | EnumSet wanted = EnumSet.of(first, other);
127 | EnumSet actual = font.getStyles();
128 |
129 | for (FontStyle fs : wanted) {
130 | if (!actual.contains(fs)) {
131 | return false;
132 | }
133 | }
134 |
135 | return true;
136 | }
137 | });
138 | }
139 |
140 | @Override
141 | public void make(final Predicate> predicate) {
142 | parent.addCondition(new Predicate() {
143 | @Override
144 | public boolean test(Cell o) {
145 | CellStyle style = o.getStyle();
146 | if (style == null) {
147 | return false;
148 | }
149 | Font font = style.getFont();
150 | return font != null && predicate.test(font.getStyles());
151 | }
152 | });
153 | }
154 |
155 | @Override
156 | public FontStyle getItalic() {
157 | return FontStyle.ITALIC;
158 | }
159 |
160 | @Override
161 | public FontStyle getBold() {
162 | return FontStyle.BOLD;
163 | }
164 |
165 | @Override
166 | public FontStyle getStrikeout() {
167 | return FontStyle.STRIKEOUT;
168 | }
169 |
170 | @Override
171 | public FontStyle getUnderline() {
172 | return FontStyle.UNDERLINE;
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/simple/SimplePageCriterion.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.simple;
2 |
3 | import org.modelcatalogue.spreadsheet.api.*;
4 | import org.modelcatalogue.spreadsheet.query.api.PageCriterion;
5 | import org.modelcatalogue.spreadsheet.query.api.Predicate;
6 |
7 | public class SimplePageCriterion extends AbstractPageSettingsProvider implements PageCriterion {
8 |
9 | private final SimpleWorkbookCriterion workbookCriterion;
10 |
11 | SimplePageCriterion(SimpleWorkbookCriterion workbookCriterion) {
12 | this.workbookCriterion = workbookCriterion;
13 | }
14 |
15 | @Override
16 | public void orientation(final Keywords.Orientation orientation) {
17 | workbookCriterion.addCondition(new Predicate() {
18 | @Override
19 | public boolean test(Sheet o) {
20 | return orientation.equals(o.getPage().getOrientation());
21 | }
22 | });
23 | }
24 |
25 | @Override
26 | public void paper(final Keywords.Paper paper) {
27 | workbookCriterion.addCondition(new Predicate() {
28 | @Override
29 | public boolean test(Sheet o) {
30 | return paper.equals(o.getPage().getPaper());
31 | }
32 | });
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/simple/SimpleRowCriterion.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.simple;
2 |
3 | import groovy.lang.Closure;
4 | import groovy.lang.DelegatesTo;
5 | import groovy.transform.stc.ClosureParams;
6 | import groovy.transform.stc.FromString;
7 | import org.codehaus.groovy.runtime.DefaultGroovyMethods;
8 | import org.modelcatalogue.spreadsheet.api.Cell;
9 | import org.modelcatalogue.spreadsheet.query.api.CellCriterion;
10 | import org.modelcatalogue.spreadsheet.query.api.Predicate;
11 | import org.modelcatalogue.spreadsheet.query.api.RowCriterion;
12 |
13 | final class SimpleRowCriterion extends AbstractCriterion implements RowCriterion {
14 |
15 | SimpleRowCriterion() {}
16 |
17 | private SimpleRowCriterion(boolean disjoint) {
18 | super(disjoint);
19 | }
20 |
21 | @Override
22 | public Predicate column(final int number) {
23 | return new Predicate() {
24 | @Override
25 | public boolean test(Cell o) {
26 | return number == o.getColumn();
27 | }
28 | };
29 | }
30 |
31 | @Override
32 | public Predicate columnAsString(final String name) {
33 | return new Predicate() {
34 | @Override
35 | public boolean test(Cell o) {
36 | return name.equals(o.getColumnAsString());
37 | }
38 | };
39 | }
40 |
41 | @Override
42 | public Predicate range(final int from, final int to) {
43 | return new Predicate() {
44 | @Override
45 | public boolean test(Cell o) {
46 | return o.getColumn() >= from && o.getColumn() <= to;
47 | }
48 | };
49 | }
50 |
51 | @Override
52 | public Predicate range(String from, String to) {
53 | return range(Cell.Util.parseColumn(from), Cell.Util.parseColumn(to));
54 | }
55 |
56 | @Override
57 | public void cell(Predicate predicate) {
58 | addCondition(predicate);
59 | }
60 |
61 | @Override
62 | public void cell(int column) {
63 | cell(column(column));
64 | }
65 |
66 | @Override
67 | public void cell(String column) {
68 | cell(columnAsString(column));
69 | }
70 |
71 | @Override
72 | public void cell(@DelegatesTo(CellCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.CellCriterion") Closure cellCriterion) {
73 | SimpleCellCriterion criterion = new SimpleCellCriterion();
74 | DefaultGroovyMethods.with(criterion, cellCriterion);
75 | addCondition(criterion);
76 | }
77 |
78 | @Override
79 | public void cell(int column, @DelegatesTo(CellCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.CellCriterion") Closure cellCriterion) {
80 | addCondition(column(column));
81 | cell(cellCriterion);
82 | }
83 |
84 | @Override
85 | public void cell(String column, @DelegatesTo(CellCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.CellCriterion") Closure cellCriterion) {
86 | addCondition(columnAsString(column));
87 | cell(cellCriterion);
88 | }
89 |
90 | @Override
91 | public void cell(Predicate predicate, @DelegatesTo(CellCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.CellCriterion") Closure cellCriterion) {
92 | addCondition(predicate);
93 | cell(cellCriterion);
94 | }
95 |
96 | @Override
97 | Predicate newDisjointCriterionInstance() {
98 | return new SimpleRowCriterion(true);
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/simple/SimpleSheetCriterion.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.simple;
2 |
3 | import groovy.lang.Closure;
4 | import groovy.lang.DelegatesTo;
5 | import groovy.transform.stc.ClosureParams;
6 | import groovy.transform.stc.FromString;
7 | import org.codehaus.groovy.runtime.DefaultGroovyMethods;
8 | import org.modelcatalogue.spreadsheet.api.Page;
9 | import org.modelcatalogue.spreadsheet.api.Row;
10 | import org.modelcatalogue.spreadsheet.api.Sheet;
11 | import org.modelcatalogue.spreadsheet.query.api.PageCriterion;
12 | import org.modelcatalogue.spreadsheet.query.api.Predicate;
13 | import org.modelcatalogue.spreadsheet.query.api.RowCriterion;
14 | import org.modelcatalogue.spreadsheet.query.api.SheetCriterion;
15 |
16 | import java.util.ArrayList;
17 | import java.util.Collection;
18 | import java.util.Collections;
19 |
20 | final class SimpleSheetCriterion extends AbstractCriterion implements SheetCriterion {
21 |
22 | private final Collection criteria = new ArrayList();
23 | private final SimpleWorkbookCriterion parent;
24 |
25 | SimpleSheetCriterion(SimpleWorkbookCriterion parent) {
26 | this.parent = parent;
27 | }
28 |
29 | private SimpleSheetCriterion(boolean disjoint, SimpleWorkbookCriterion parent) {
30 | super(disjoint);
31 | this.parent = parent;
32 | }
33 |
34 | @Override
35 | public Predicate number(final int row) {
36 | return new Predicate() {
37 | @Override
38 | public boolean test(Row o) {
39 | return o.getNumber() == row;
40 | }
41 | };
42 | }
43 |
44 | @Override
45 | public Predicate range(final int from, final int to) {
46 | return new Predicate() {
47 | @Override
48 | public boolean test(Row o) {
49 | return o.getNumber() >= from && o.getNumber() <= to;
50 | }
51 | };
52 | }
53 |
54 | @Override
55 | public void row(@DelegatesTo(RowCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.RowCriterion") Closure rowCriterion) {
56 | SimpleRowCriterion criterion = new SimpleRowCriterion();
57 | DefaultGroovyMethods.with(criterion, rowCriterion);
58 | criteria.add(criterion);
59 | }
60 |
61 | @Override
62 | public void row(int row, @DelegatesTo(RowCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.RowCriterion") Closure rowCriterion) {
63 | row(row);
64 | row(rowCriterion);
65 | }
66 |
67 | @Override
68 | public void row(Predicate predicate, @DelegatesTo(RowCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.RowCriterion") Closure rowCriterion) {
69 | row(predicate);
70 | row(rowCriterion);
71 | }
72 |
73 | @Override
74 | public void row(Predicate predicate) {
75 | addCondition(predicate);
76 | }
77 |
78 | @Override
79 | public void page(@DelegatesTo(PageCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.PageCriterion") Closure pageCriterion) {
80 | SimplePageCriterion criterion = new SimplePageCriterion(parent);
81 | DefaultGroovyMethods.with(criterion, pageCriterion);
82 | }
83 |
84 | @Override
85 | public void page(final Predicate predicate) {
86 | parent.addCondition(new Predicate() {
87 | @Override
88 | public boolean test(Sheet o) {
89 | return predicate.test(o.getPage());
90 | }
91 | });
92 | }
93 |
94 | @Override
95 | public void row(int row) {
96 | row(number(row));
97 | }
98 |
99 | Collection getCriteria() {
100 | return Collections.unmodifiableCollection(criteria);
101 | }
102 |
103 | @Override
104 | Predicate newDisjointCriterionInstance() {
105 | return new SimpleSheetCriterion(true, parent);
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/simple/SimpleSpreadsheetCriteria.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.simple;
2 |
3 | import groovy.lang.Closure;
4 | import groovy.lang.DelegatesTo;
5 | import groovy.transform.stc.ClosureParams;
6 | import groovy.transform.stc.FromString;
7 | import org.modelcatalogue.spreadsheet.api.*;
8 | import org.modelcatalogue.spreadsheet.query.api.*;
9 |
10 | import java.io.FileNotFoundException;
11 | import java.util.Iterator;
12 |
13 | public final class SimpleSpreadsheetCriteria implements SpreadsheetCriteria {
14 |
15 | private final Workbook workbook;
16 |
17 | public static SpreadsheetCriteria forWorkbook(Workbook workbook) {
18 | return new SimpleSpreadsheetCriteria(workbook);
19 | }
20 |
21 | private SimpleSpreadsheetCriteria(Workbook workbook) {
22 | this.workbook = workbook;
23 | }
24 |
25 | private SpreadsheetCriteriaResult queryInternal(final int max, @DelegatesTo(WorkbookCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.WorkbookCriterion") final Closure workbookCriterion) {
26 | return new SimpleSpreadsheetCriteriaResult(workbook, workbookCriterion, max);
27 | }
28 |
29 | @Override
30 | public SpreadsheetCriteriaResult all() {
31 | return queryInternal(Integer.MAX_VALUE, Closure.IDENTITY);
32 | }
33 |
34 | @Override
35 | public SpreadsheetCriteriaResult query(@DelegatesTo(WorkbookCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.WorkbookCriterion") Closure workbookCriterion) throws FileNotFoundException {
36 | return queryInternal(Integer.MAX_VALUE, workbookCriterion);
37 | }
38 |
39 | @Override
40 | public Cell find(@DelegatesTo(WorkbookCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.WorkbookCriterion") Closure workbookCriterion) throws FileNotFoundException {
41 | SpreadsheetCriteriaResult cells = queryInternal(1, workbookCriterion);
42 | Iterator cellIterator = cells.iterator();
43 | if (cellIterator.hasNext()) {
44 | return cellIterator.next();
45 | }
46 | return null;
47 | }
48 |
49 | @Override
50 | public boolean exists(@DelegatesTo(WorkbookCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.WorkbookCriterion") Closure workbookCriterion) throws FileNotFoundException {
51 | return find(workbookCriterion) != null;
52 | }
53 |
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/simple/SimpleSpreadsheetCriteriaResult.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.simple;
2 |
3 | import groovy.lang.Closure;
4 | import org.codehaus.groovy.runtime.DefaultGroovyMethods;
5 | import org.modelcatalogue.spreadsheet.api.Cell;
6 | import org.modelcatalogue.spreadsheet.api.Row;
7 | import org.modelcatalogue.spreadsheet.api.Sheet;
8 | import org.modelcatalogue.spreadsheet.api.Workbook;
9 | import org.modelcatalogue.spreadsheet.query.api.AbstractSpreadsheetCriteriaResult;
10 |
11 | import java.util.Collection;
12 | import java.util.LinkedHashSet;
13 |
14 | final class SimpleSpreadsheetCriteriaResult extends AbstractSpreadsheetCriteriaResult {
15 |
16 | private final Workbook workbook;
17 | private final Closure workbookCriterion;
18 | private final int max;
19 |
20 | SimpleSpreadsheetCriteriaResult(Workbook workbook, Closure workbookCriterion, int max) {
21 | this.workbook = workbook;
22 | this.workbookCriterion = workbookCriterion;
23 | this.max = max;
24 | }
25 |
26 | private Collection getCellsInternal(int currentMax) {
27 | Collection cells = new LinkedHashSet();
28 | SimpleWorkbookCriterion criterion = new SimpleWorkbookCriterion();
29 | DefaultGroovyMethods.with(criterion, workbookCriterion);
30 |
31 | for (Sheet sheet : workbook.getSheets()) {
32 | if (criterion.test(sheet)) {
33 | for (Row row : sheet.getRows()) {
34 | if (criterion.getCriteria().isEmpty()) {
35 | cells.addAll(row.getCells());
36 | if (cells.size() >= currentMax) {
37 | return cells;
38 | }
39 | } else {
40 | for (SimpleSheetCriterion sheetCriterion : criterion.getCriteria()) {
41 | if (sheetCriterion.test(row)) {
42 | if (sheetCriterion.getCriteria().isEmpty()) {
43 | cells.addAll(row.getCells());
44 | if (cells.size() >= currentMax) {
45 | return cells;
46 | }
47 | } else {
48 | for (Cell cell : row.getCells()) {
49 | for (SimpleRowCriterion rowCriterion : sheetCriterion.getCriteria()) {
50 | if (rowCriterion.test(cell)) {
51 | cells.add(cell);
52 | if (cells.size() >= currentMax) {
53 | return cells;
54 | }
55 | }
56 | }
57 | }
58 | }
59 | }
60 | }
61 | }
62 | }
63 | }
64 | }
65 |
66 | return cells;
67 | }
68 |
69 | private Collection getRowsInternal(int currentMax) {
70 | Collection rows = new LinkedHashSet();
71 | SimpleWorkbookCriterion criterion = new SimpleWorkbookCriterion();
72 | DefaultGroovyMethods.with(criterion, workbookCriterion);
73 |
74 | for (Sheet sheet : workbook.getSheets()) {
75 | if (criterion.test(sheet)) {
76 | rows_loop:
77 | for (Row row : sheet.getRows()) {
78 | if (criterion.getCriteria().isEmpty()) {
79 | rows.add(row);
80 | if (rows.size() >= currentMax) {
81 | return rows;
82 | }
83 | } else {
84 | for (SimpleSheetCriterion sheetCriterion : criterion.getCriteria()) {
85 | if (sheetCriterion.test(row)) {
86 | if (sheetCriterion.getCriteria().isEmpty()) {
87 | rows.add(row);
88 | if (rows.size() >= currentMax) {
89 | return rows;
90 | }
91 | } else {
92 | for (Cell cell : row.getCells()) {
93 | for (SimpleRowCriterion rowCriterion : sheetCriterion.getCriteria()) {
94 | if (rowCriterion.test(cell)) {
95 | rows.add(row);
96 | if (rows.size() >= currentMax) {
97 | return rows;
98 | }
99 | continue rows_loop;
100 | }
101 | }
102 | }
103 | }
104 | }
105 | }
106 | }
107 | }
108 | }
109 | }
110 |
111 | return rows;
112 | }
113 |
114 | private Collection getSheetsInternal(int currentMax) {
115 | Collection sheets = new LinkedHashSet();
116 | SimpleWorkbookCriterion criterion = new SimpleWorkbookCriterion();
117 | DefaultGroovyMethods.with(criterion, workbookCriterion);
118 |
119 | sheets_loop:
120 | for (Sheet sheet : workbook.getSheets()) {
121 | if (criterion.test(sheet)) {
122 | for (Row row : sheet.getRows()) {
123 | if (criterion.getCriteria().isEmpty()) {
124 | sheets.add(sheet);
125 | if (sheets.size() >= currentMax) {
126 | return sheets;
127 | }
128 | } else {
129 | for (SimpleSheetCriterion sheetCriterion : criterion.getCriteria()) {
130 | if (sheetCriterion.test(row)) {
131 | if (sheetCriterion.getCriteria().isEmpty()) {
132 | sheets.add(sheet);
133 | if (sheets.size() >= currentMax) {
134 | return sheets;
135 | }
136 | } else {
137 | for (Cell cell : row.getCells()) {
138 | for (SimpleRowCriterion rowCriterion : sheetCriterion.getCriteria()) {
139 | if (rowCriterion.test(cell)) {
140 | sheets.add(sheet);
141 | if (sheets.size() >= currentMax) {
142 | return sheets;
143 | }
144 | continue sheets_loop;
145 | }
146 | }
147 | }
148 | }
149 | }
150 | }
151 | }
152 | }
153 | }
154 | }
155 |
156 | return sheets;
157 | }
158 |
159 | @Override
160 | public Collection getCells() {
161 | return getCellsInternal(max);
162 | }
163 |
164 | @Override
165 | public Collection getRows() {
166 | return getRowsInternal(max);
167 | }
168 |
169 | @Override
170 | public Collection getSheets() {
171 | return getSheetsInternal(max);
172 | }
173 |
174 | @Override
175 | public Cell getCell() {
176 | Collection cells = getCellsInternal(1);
177 | if (cells.size() > 0) {
178 | return cells.iterator().next();
179 | }
180 | return null;
181 | }
182 |
183 | @Override
184 | public Row getRow() {
185 | Collection rows = getRowsInternal(1);
186 | if (rows.size() > 0) {
187 | return rows.iterator().next();
188 | }
189 | return null;
190 | }
191 |
192 | @Override
193 | public Sheet getSheet() {
194 | Collection sheets = getSheetsInternal(1);
195 | if (sheets.size() > 0) {
196 | return sheets.iterator().next();
197 | }
198 | return null;
199 | }
200 |
201 | }
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/main/java/org/modelcatalogue/spreadsheet/query/simple/SimpleWorkbookCriterion.java:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.simple;
2 |
3 | import groovy.lang.Closure;
4 | import groovy.lang.DelegatesTo;
5 | import groovy.transform.stc.ClosureParams;
6 | import groovy.transform.stc.FromString;
7 | import org.codehaus.groovy.runtime.DefaultGroovyMethods;
8 | import org.modelcatalogue.spreadsheet.api.Sheet;
9 | import org.modelcatalogue.spreadsheet.query.api.Predicate;
10 | import org.modelcatalogue.spreadsheet.query.api.SheetCriterion;
11 | import org.modelcatalogue.spreadsheet.query.api.WorkbookCriterion;
12 |
13 | import java.util.ArrayList;
14 | import java.util.Collection;
15 | import java.util.Collections;
16 |
17 | final class SimpleWorkbookCriterion extends AbstractCriterion implements WorkbookCriterion {
18 |
19 | private final Collection criteria = new ArrayList();
20 |
21 | private SimpleWorkbookCriterion(boolean disjoint) {
22 | super(disjoint);
23 | }
24 |
25 | SimpleWorkbookCriterion() {}
26 |
27 | @Override
28 | public Predicate name(final String name) {
29 | return new Predicate() {
30 | @Override
31 | public boolean test(Sheet o) {
32 | return o.getName().equals(name);
33 | }
34 | };
35 | }
36 |
37 | @Override
38 | public Predicate name(final Predicate namePredicate) {
39 | return new Predicate() {
40 | @Override
41 | public boolean test(Sheet o) {
42 | return namePredicate.test(o.getName());
43 | }
44 | };
45 | }
46 |
47 | @Override
48 | public void sheet(String name) {
49 | sheet(name(name));
50 | }
51 |
52 | @Override
53 | public void sheet(String name, @DelegatesTo(SheetCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.SheetCriterion") Closure sheetCriterion) {
54 | sheet(name(name));
55 | sheet(sheetCriterion);
56 | }
57 |
58 | @Override
59 | public void sheet(Predicate name) {
60 | addCondition(name);
61 | }
62 |
63 | @Override
64 | public void sheet(Predicate name, @DelegatesTo(SheetCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.SheetCriterion") Closure sheetCriterion) {
65 | sheet(name);
66 | sheet(sheetCriterion);
67 | }
68 |
69 | @Override
70 | public void sheet(@DelegatesTo(SheetCriterion.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.query.api.SheetCriterion") Closure sheetCriterion) {
71 | SimpleSheetCriterion sheet = new SimpleSheetCriterion(this);
72 | DefaultGroovyMethods.with(sheet, sheetCriterion);
73 | criteria.add(sheet);
74 | }
75 |
76 | Collection getCriteria() {
77 | return Collections.unmodifiableCollection(criteria);
78 | }
79 |
80 | @Override
81 | Predicate newDisjointCriterionInstance() {
82 | return new SimpleWorkbookCriterion(true);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/spreadsheet-builder-api/src/test/groovy/org/modelcatalogue/spreadsheet/api/CellUtilSpec.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.api
2 |
3 | import spock.lang.Specification
4 | import spock.lang.Unroll
5 |
6 | /**
7 | * Tests for Cell
8 | */
9 | class CellUtilSpec extends Specification {
10 |
11 | @Unroll
12 | void "parse column #column to number #index"() {
13 | expect:
14 | Cell.Util.parseColumn(column) == index
15 | Cell.Util.toColumn(index) == column
16 | where:
17 | column | index
18 | 'A' | 1
19 | 'B' | 2
20 | 'Z' | 26
21 | 'AA' | 27
22 | 'AB' | 28
23 | 'DA' | 105
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/build.gradle:
--------------------------------------------------------------------------------
1 | dependencies {
2 | compile project(':spreadsheet-builder-api')
3 |
4 | compile 'org.codehaus.groovy:groovy-all:2.4.7'
5 | compile 'org.apache.poi:poi-ooxml:3.13'
6 | compile 'org.apache.poi:ooxml-schemas:1.1'
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PendingFormula.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import groovy.transform.PackageScope
4 | import org.apache.poi.ss.usermodel.Cell
5 | import org.apache.poi.xssf.usermodel.XSSFCell
6 | import org.apache.poi.xssf.usermodel.XSSFName
7 |
8 | /**
9 | * Pending formula is a formula definition which needs to be resolved at the end of the build where all named references
10 | * are know.
11 | */
12 | @PackageScope class PendingFormula implements Resolvable {
13 |
14 | final XSSFCell cell
15 | final String formula
16 |
17 | PendingFormula(XSSFCell cell, String formula) {
18 | this.cell = cell
19 | this.formula = formula
20 | }
21 |
22 | void resolve() {
23 | cell.setCellFormula(expandNames(formula))
24 | cell.cellType = Cell.CELL_TYPE_FORMULA
25 | }
26 |
27 | protected String expandNames(String withNames) {
28 | withNames.replaceAll(/\#\{(.+?)\}/) { List found ->
29 | XSSFName nameFound = cell.sheet.workbook.getName(PoiCellDefinition.fixName(found[1]))
30 | if (!found) {
31 | throw new IllegalArgumentException("Named cell '${found[1]}' cannot be found! Please, take a note " +
32 | "that the name was normalized to ${PoiCellDefinition.fixName(found[1])} due the Excel constraints.")
33 | }
34 | nameFound.refersToFormula
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PendingLink.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import groovy.transform.PackageScope
4 | import org.apache.poi.common.usermodel.Hyperlink
5 | import org.apache.poi.xssf.usermodel.XSSFCell
6 | import org.apache.poi.xssf.usermodel.XSSFHyperlink
7 | import org.apache.poi.xssf.usermodel.XSSFName
8 | import org.apache.poi.xssf.usermodel.XSSFWorkbook
9 |
10 | /**
11 | * Pending link is a link which needs to be resolved at the end of the build when all the named references are known.
12 | */
13 | @PackageScope class PendingLink implements Resolvable {
14 |
15 | final XSSFCell cell
16 | final String name
17 |
18 | PendingLink(XSSFCell cell, String name) {
19 | this.cell = cell
20 | this.name = name
21 | }
22 |
23 | void resolve() {
24 | XSSFWorkbook workbook = cell.row.sheet.workbook as XSSFWorkbook
25 | XSSFName xssfName = workbook.getName(PoiCellDefinition.fixName(name)) as XSSFName
26 |
27 | if (!xssfName) {
28 | throw new IllegalArgumentException("Name $name does not exist! Please consider that the name was normalized to ${PoiCellDefinition.fixName(name)}")
29 | }
30 |
31 | XSSFHyperlink link = workbook.creationHelper.createHyperlink(Hyperlink.LINK_DOCUMENT) as XSSFHyperlink
32 | link.address = xssfName.refersToFormula
33 |
34 | cell.hyperlink = link
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiBorder.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import org.apache.poi.ss.usermodel.BorderStyle
4 | import org.apache.poi.xssf.usermodel.XSSFColor
5 | import org.modelcatalogue.spreadsheet.api.Border
6 | import org.modelcatalogue.spreadsheet.api.Color
7 |
8 | /**
9 | * Represents the current border configuration of the cell style.
10 | */
11 | class PoiBorder implements Border {
12 | private XSSFColor xssfColor
13 | private BorderStyle borderStyle
14 |
15 | PoiBorder(XSSFColor xssfColor, BorderStyle borderStyle) {
16 | this.borderStyle = borderStyle
17 | this.xssfColor = xssfColor
18 | }
19 |
20 | @Override
21 | Color getColor() {
22 | if (xssfColor == null) {
23 | return null
24 | }
25 | return new Color(xssfColor.getRGB())
26 | }
27 |
28 | @Override
29 | org.modelcatalogue.spreadsheet.api.BorderStyle getStyle() {
30 | switch (borderStyle) {
31 | case BorderStyle.NONE:
32 | return org.modelcatalogue.spreadsheet.api.BorderStyle.NONE
33 | case BorderStyle.THIN:
34 | return org.modelcatalogue.spreadsheet.api.BorderStyle.THIN
35 | case BorderStyle.MEDIUM:
36 | return org.modelcatalogue.spreadsheet.api.BorderStyle.MEDIUM
37 | case BorderStyle.DASHED:
38 | return org.modelcatalogue.spreadsheet.api.BorderStyle.DASHED
39 | case BorderStyle.DOTTED:
40 | return org.modelcatalogue.spreadsheet.api.BorderStyle.DOTTED
41 | case BorderStyle.THICK:
42 | return org.modelcatalogue.spreadsheet.api.BorderStyle.THICK
43 | case BorderStyle.DOUBLE:
44 | return org.modelcatalogue.spreadsheet.api.BorderStyle.DOUBLE
45 | case BorderStyle.HAIR:
46 | return org.modelcatalogue.spreadsheet.api.BorderStyle.HAIR
47 | case BorderStyle.MEDIUM_DASHED:
48 | return org.modelcatalogue.spreadsheet.api.BorderStyle.MEDIUM_DASHED
49 | case BorderStyle.DASH_DOT:
50 | return org.modelcatalogue.spreadsheet.api.BorderStyle.DASH_DOT
51 | case BorderStyle.MEDIUM_DASH_DOT:
52 | return org.modelcatalogue.spreadsheet.api.BorderStyle.MEDIUM_DASH_DOT
53 | case BorderStyle.DASH_DOT_DOT:
54 | return org.modelcatalogue.spreadsheet.api.BorderStyle.DASH_DOT_DOT
55 | case BorderStyle.MEDIUM_DASH_DOT_DOTC:
56 | return org.modelcatalogue.spreadsheet.api.BorderStyle.MEDIUM_DASH_DOT_DOT
57 | case BorderStyle.SLANTED_DASH_DOT:
58 | return org.modelcatalogue.spreadsheet.api.BorderStyle.SLANTED_DASH_DOT
59 | }
60 | return null
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiBorderDefinition.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import org.apache.poi.xssf.usermodel.XSSFCellStyle
4 | import org.apache.poi.xssf.usermodel.XSSFColor
5 | import org.modelcatalogue.spreadsheet.api.AbstractBorderProvider
6 |
7 | import org.modelcatalogue.spreadsheet.api.BorderStyle
8 | import org.modelcatalogue.spreadsheet.api.Color
9 | import org.modelcatalogue.spreadsheet.api.Keywords
10 |
11 | class PoiBorderDefinition extends AbstractBorderProvider {
12 |
13 | private final XSSFCellStyle xssfCellStyle
14 |
15 | private XSSFColor color
16 | private BorderStyle borderStyle
17 |
18 | PoiBorderDefinition(XSSFCellStyle xssfCellStyle) {
19 | this.xssfCellStyle = xssfCellStyle
20 | }
21 |
22 | @Override
23 | void style(BorderStyle style) {
24 | borderStyle = style
25 | }
26 |
27 | @Override
28 | void color(String hexColor) {
29 | color = PoiCellStyleDefinition.parseColor(hexColor)
30 | }
31 |
32 | @Override
33 | void color(Color colorPreset) {
34 | color colorPreset.hex
35 | }
36 |
37 | protected void applyTo(Keywords.BorderSide location) {
38 | switch (location) {
39 | case Keywords.PureBorderSide.BOTTOM:
40 | if (borderStyle) {
41 | xssfCellStyle.setBorderBottom(poiBorderStyle)
42 | }
43 | if (color) {
44 | xssfCellStyle.setBottomBorderColor(color)
45 | }
46 | break
47 | case Keywords.PureBorderSide.TOP:
48 | if (borderStyle) {
49 | xssfCellStyle.setBorderTop(poiBorderStyle)
50 | }
51 | if (color) {
52 | xssfCellStyle.setTopBorderColor(color)
53 | }
54 | break
55 | case Keywords.BorderSideAndVerticalAlignment.LEFT:
56 | if (borderStyle) {
57 | xssfCellStyle.setBorderLeft(poiBorderStyle)
58 | }
59 | if (color) {
60 | xssfCellStyle.setLeftBorderColor(color)
61 | }
62 | break
63 | case Keywords.BorderSideAndVerticalAlignment.RIGHT:
64 | if (borderStyle) {
65 | xssfCellStyle.setBorderRight(poiBorderStyle)
66 | }
67 | if (color) {
68 | xssfCellStyle.setRightBorderColor(color)
69 | }
70 | break
71 | default:
72 | throw new IllegalArgumentException("$location is not supported!")
73 | }
74 |
75 | }
76 |
77 | private org.apache.poi.ss.usermodel.BorderStyle getPoiBorderStyle() {
78 | switch (borderStyle) {
79 | case BorderStyle.NONE:
80 | return org.apache.poi.ss.usermodel.BorderStyle.NONE
81 | case BorderStyle.THIN:
82 | return org.apache.poi.ss.usermodel.BorderStyle.THIN
83 | case BorderStyle.MEDIUM:
84 | return org.apache.poi.ss.usermodel.BorderStyle.MEDIUM
85 | case BorderStyle.DASHED:
86 | return org.apache.poi.ss.usermodel.BorderStyle.DASHED
87 | case BorderStyle.DOTTED:
88 | return org.apache.poi.ss.usermodel.BorderStyle.DOTTED
89 | case BorderStyle.THICK:
90 | return org.apache.poi.ss.usermodel.BorderStyle.THICK
91 | case BorderStyle.DOUBLE:
92 | return org.apache.poi.ss.usermodel.BorderStyle.DOUBLE
93 | case BorderStyle.HAIR:
94 | return org.apache.poi.ss.usermodel.BorderStyle.HAIR
95 | case BorderStyle.MEDIUM_DASHED:
96 | return org.apache.poi.ss.usermodel.BorderStyle.MEDIUM_DASHED
97 | case BorderStyle.DASH_DOT:
98 | return org.apache.poi.ss.usermodel.BorderStyle.DASH_DOT
99 | case BorderStyle.MEDIUM_DASH_DOT:
100 | return org.apache.poi.ss.usermodel.BorderStyle.MEDIUM_DASH_DOT
101 | case BorderStyle.DASH_DOT_DOT:
102 | return org.apache.poi.ss.usermodel.BorderStyle.DASH_DOT_DOT
103 | case BorderStyle.MEDIUM_DASH_DOT_DOT:
104 | return org.apache.poi.ss.usermodel.BorderStyle.MEDIUM_DASH_DOT_DOTC
105 | case BorderStyle.SLANTED_DASH_DOT:
106 | return org.apache.poi.ss.usermodel.BorderStyle.SLANTED_DASH_DOT
107 | }
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiCellStyle.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import org.apache.poi.xssf.usermodel.XSSFCellStyle
4 | import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder
5 | import org.modelcatalogue.spreadsheet.api.Border
6 | import org.modelcatalogue.spreadsheet.api.CellStyle
7 | import org.modelcatalogue.spreadsheet.api.Color
8 | import org.modelcatalogue.spreadsheet.api.Font
9 | import org.modelcatalogue.spreadsheet.api.ForegroundFill
10 | import org.modelcatalogue.spreadsheet.api.Keywords
11 |
12 | class PoiCellStyle implements CellStyle {
13 |
14 | private final XSSFCellStyle style
15 |
16 | PoiCellStyle(XSSFCellStyle style) {
17 | this.style = style
18 | }
19 |
20 | @Override
21 | Color getForeground() {
22 | return style.getFillForegroundColorColor()?.getRGB() ? new Color(style.getFillForegroundColorColor().getRGB()) : null
23 | }
24 |
25 | @Override
26 | Color getBackground() {
27 | return style.getFillBackgroundColorColor()?.getRGB() ? new Color(style.getFillBackgroundColorColor().getRGB()) : null
28 | }
29 |
30 | @Override
31 | ForegroundFill getFill() {
32 | switch (style.fillPattern) {
33 | case org.apache.poi.ss.usermodel.CellStyle.NO_FILL: return ForegroundFill.NO_FILL
34 | case org.apache.poi.ss.usermodel.CellStyle.SOLID_FOREGROUND: return ForegroundFill.SOLID_FOREGROUND
35 | case org.apache.poi.ss.usermodel.CellStyle.FINE_DOTS: return ForegroundFill.FINE_DOTS
36 | case org.apache.poi.ss.usermodel.CellStyle.ALT_BARS: return ForegroundFill.ALT_BARS
37 | case org.apache.poi.ss.usermodel.CellStyle.SPARSE_DOTS: return ForegroundFill.SPARSE_DOTS
38 | case org.apache.poi.ss.usermodel.CellStyle.THICK_HORZ_BANDS: return ForegroundFill.THICK_HORZ_BANDS
39 | case org.apache.poi.ss.usermodel.CellStyle.THICK_VERT_BANDS: return ForegroundFill.THICK_VERT_BANDS
40 | case org.apache.poi.ss.usermodel.CellStyle.THICK_BACKWARD_DIAG: return ForegroundFill.THICK_BACKWARD_DIAG
41 | case org.apache.poi.ss.usermodel.CellStyle.THICK_FORWARD_DIAG: return ForegroundFill.THICK_FORWARD_DIAG
42 | case org.apache.poi.ss.usermodel.CellStyle.BIG_SPOTS: return ForegroundFill.BIG_SPOTS
43 | case org.apache.poi.ss.usermodel.CellStyle.BRICKS: return ForegroundFill.BRICKS
44 | case org.apache.poi.ss.usermodel.CellStyle.THIN_HORZ_BANDS: return ForegroundFill.THIN_HORZ_BANDS
45 | case org.apache.poi.ss.usermodel.CellStyle.THIN_VERT_BANDS: return ForegroundFill.THIN_VERT_BANDS
46 | case org.apache.poi.ss.usermodel.CellStyle.THIN_BACKWARD_DIAG: return ForegroundFill.THIN_BACKWARD_DIAG
47 | case org.apache.poi.ss.usermodel.CellStyle.THIN_FORWARD_DIAG: return ForegroundFill.THIN_FORWARD_DIAG
48 | case org.apache.poi.ss.usermodel.CellStyle.SQUARES: return ForegroundFill.SQUARES
49 | case org.apache.poi.ss.usermodel.CellStyle.DIAMONDS: return ForegroundFill.DIAMONDS
50 | }
51 | return null
52 | }
53 |
54 | @Override
55 | int getIndent() {
56 | return style.getIndention()
57 | }
58 |
59 | @Override
60 | int getRotation() {
61 | return style.getRotation()
62 | }
63 |
64 | @Override
65 | String getFormat() {
66 | return style.dataFormatString
67 | }
68 |
69 | @Override
70 | Font getFont() {
71 | return style.getFont() ? new PoiFont(style.getFont()) : null
72 | }
73 |
74 | @Override
75 | Border getBorder(Keywords.BorderSide borderSide) {
76 | switch(borderSide) {
77 | case Keywords.BorderSide.TOP: return new PoiBorder(style.getBorderColor(XSSFCellBorder.BorderSide.TOP), style.getBorderTopEnum())
78 | case Keywords.BorderSide.BOTTOM: return new PoiBorder(style.getBorderColor(XSSFCellBorder.BorderSide.BOTTOM), style.getBorderBottomEnum())
79 | case Keywords.BorderSide.LEFT: return new PoiBorder(style.getBorderColor(XSSFCellBorder.BorderSide.LEFT), style.getBorderLeftEnum())
80 | case Keywords.BorderSide.RIGHT: return new PoiBorder(style.getBorderColor(XSSFCellBorder.BorderSide.RIGHT), style.getBorderRightEnum())
81 | }
82 | return new PoiBorder(null, null)
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiCommentDefinition.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import org.apache.poi.xssf.usermodel.XSSFCell
4 | import org.apache.poi.xssf.usermodel.XSSFClientAnchor
5 | import org.apache.poi.xssf.usermodel.XSSFComment
6 | import org.apache.poi.xssf.usermodel.XSSFCreationHelper
7 | import org.apache.poi.xssf.usermodel.XSSFDrawing
8 | import org.apache.poi.xssf.usermodel.XSSFWorkbook
9 | import org.modelcatalogue.spreadsheet.api.Comment
10 | import org.modelcatalogue.spreadsheet.builder.api.CommentDefinition
11 |
12 | class PoiCommentDefinition implements CommentDefinition, Comment{
13 |
14 | private String author
15 | private String text
16 | private int width = DEFAULT_WIDTH
17 | private int height = DEFAULT_HEIGHT
18 |
19 | @Override
20 | void author(String author) {
21 | this.author = author
22 | }
23 |
24 | @Override
25 | void text(String text) {
26 | assert text
27 | this.text = text
28 | }
29 |
30 |
31 | void width(int widthInCells) {
32 | assert widthInCells > 0
33 | this.width = widthInCells
34 | }
35 |
36 |
37 | void height(int heightInCells) {
38 | assert heightInCells > 0
39 | this.height = heightInCells
40 | }
41 |
42 | void applyTo(XSSFCell cell) {
43 | if (!text) {
44 | throw new IllegalStateException("Comment text has not been set!")
45 | }
46 | XSSFWorkbook wb = cell.row.sheet.workbook as XSSFWorkbook
47 | XSSFCreationHelper factory = wb.getCreationHelper();
48 |
49 | XSSFDrawing drawing = cell.row.sheet.createDrawingPatriarch() as XSSFDrawing;
50 |
51 | XSSFClientAnchor anchor = factory.createClientAnchor();
52 | anchor.setCol1(cell.getColumnIndex());
53 | anchor.setCol2(cell.getColumnIndex() + width);
54 | anchor.setRow1(cell.row.getRowNum());
55 | anchor.setRow2(cell.row.getRowNum() + height);
56 |
57 | // Create the comment and set the text+author
58 | XSSFComment comment = drawing.createCellComment(anchor);
59 | comment.setString(text)
60 | if (author) {
61 | comment.setAuthor(author)
62 | }
63 |
64 | // Assign the comment to the cell
65 | cell.setCellComment(comment)
66 |
67 |
68 | }
69 |
70 | @Override
71 | String getAuthor() {
72 | return author
73 | }
74 |
75 | @Override
76 | String getText() {
77 | return text
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiFitDimension.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import org.apache.poi.xssf.usermodel.XSSFPrintSetup
4 | import org.modelcatalogue.spreadsheet.api.Keywords.Fit
5 | import org.modelcatalogue.spreadsheet.builder.api.FitDimension
6 |
7 | class PoiFitDimension implements FitDimension{
8 |
9 | private final XSSFPrintSetup printSetup
10 | private final Fit fit
11 |
12 | PoiFitDimension(XSSFPrintSetup printSetup, Fit fit) {
13 | this.printSetup = printSetup
14 | this.fit = fit
15 | }
16 |
17 | @Override
18 | void to(int numberOfPages) {
19 | switch (fit) {
20 | case Fit.HEIGHT:
21 | printSetup.setFitHeight(numberOfPages.shortValue())
22 | break
23 | case Fit.WIDTH:
24 | printSetup.setFitWidth(numberOfPages.shortValue())
25 | break
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiFont.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import org.apache.poi.ss.usermodel.FontUnderline
4 | import org.apache.poi.xssf.usermodel.XSSFFont
5 | import org.modelcatalogue.spreadsheet.api.Color
6 | import org.modelcatalogue.spreadsheet.api.Font
7 | import org.modelcatalogue.spreadsheet.api.FontStyle
8 |
9 | class PoiFont implements Font {
10 | XSSFFont font
11 |
12 | PoiFont(XSSFFont xssfFont) {
13 | this.font = xssfFont
14 | }
15 |
16 | @Override
17 | Color getColor() {
18 | return font.getXSSFColor()?.getRGB() ? new Color(font.getXSSFColor().getRGB()) : null
19 | }
20 |
21 | @Override
22 | int getSize() {
23 | return font.getFontHeightInPoints()
24 | }
25 |
26 | @Override
27 | String getName() {
28 | return font.getFontName()
29 | }
30 |
31 | @Override
32 | EnumSet getStyles() {
33 | EnumSet set = EnumSet.noneOf(FontStyle)
34 |
35 | if (font.italic) {
36 | set.add(FontStyle.ITALIC)
37 | }
38 |
39 | if (font.bold) {
40 | set.add(FontStyle.BOLD)
41 | }
42 |
43 | if (font.strikeout) {
44 | set.add(FontStyle.STRIKEOUT)
45 | }
46 |
47 | if (font.underline != FontUnderline.NONE.byteValue) {
48 | set.add(FontStyle.UNDERLINE)
49 | }
50 |
51 | return set
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiFontDefinition.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import org.apache.poi.ss.usermodel.FontUnderline
4 | import org.apache.poi.xssf.usermodel.XSSFCellStyle
5 | import org.apache.poi.xssf.usermodel.XSSFFont
6 | import org.apache.poi.xssf.usermodel.XSSFWorkbook
7 | import org.modelcatalogue.spreadsheet.api.HTMLColorProvider
8 | import org.modelcatalogue.spreadsheet.api.Color
9 | import org.modelcatalogue.spreadsheet.builder.api.FontDefinition
10 | import org.modelcatalogue.spreadsheet.api.FontStyle
11 |
12 | class PoiFontDefinition implements FontDefinition, HTMLColorProvider {
13 |
14 | private final XSSFFont font
15 |
16 | PoiFontDefinition(XSSFWorkbook workbook) {
17 | font = workbook.createFont()
18 | }
19 |
20 | PoiFontDefinition(XSSFWorkbook workbook, XSSFCellStyle style) {
21 | font = workbook.createFont()
22 | style.font = font
23 | }
24 |
25 | @Override
26 | void color(String hexColor) {
27 | font.setColor(PoiCellStyleDefinition.parseColor(hexColor))
28 | }
29 |
30 | @Override
31 | void color(Color colorPreset) {
32 | color colorPreset.hex
33 | }
34 |
35 | @Override
36 | void size(int size) {
37 | font.setFontHeightInPoints(size.shortValue())
38 | }
39 |
40 | @Override
41 | void name(String name) {
42 | font.setFontName(name)
43 | }
44 |
45 | @Override
46 | FontStyle getItalic() {
47 | FontStyle.ITALIC
48 | }
49 |
50 | @Override
51 | FontStyle getBold() {
52 | FontStyle.BOLD
53 | }
54 |
55 | @Override
56 | FontStyle getStrikeout() {
57 | FontStyle.STRIKEOUT
58 | }
59 |
60 | @Override
61 | FontStyle getUnderline() {
62 | FontStyle.UNDERLINE
63 | }
64 |
65 | @Override
66 | void make(FontStyle first, FontStyle... other) {
67 | EnumSet enumSet = EnumSet.of(first, other)
68 | if (FontStyle.ITALIC in enumSet) {
69 | font.italic = true
70 | }
71 |
72 | if (FontStyle.BOLD in enumSet) {
73 | font.bold = true
74 | }
75 |
76 | if (FontStyle.STRIKEOUT in enumSet) {
77 | font.strikeout = true
78 | }
79 |
80 | if (FontStyle.UNDERLINE in enumSet) {
81 | font.setUnderline(FontUnderline.SINGLE)
82 | }
83 | }
84 |
85 | protected XSSFFont getFont() {
86 | return font
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiHeightModifier.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import org.modelcatalogue.spreadsheet.builder.api.DimensionModifier
4 |
5 | class PoiHeightModifier implements DimensionModifier {
6 |
7 | private final PoiCellDefinition cell
8 | private final double height
9 |
10 | PoiHeightModifier(PoiCellDefinition cell, double height) {
11 | this.height = height
12 | this.cell = cell
13 | }
14 |
15 | @Override
16 | Object getCm() {
17 | cell.height(28 * height)
18 | return null
19 | }
20 |
21 | @Override
22 | Object getInch() {
23 | cell.height(72 * height)
24 | return null
25 | }
26 |
27 | @Override
28 | Object getInches() {
29 | inch
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiHorizontalAlignmentConfigurer.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import org.apache.poi.ss.usermodel.HorizontalAlignment
4 | import org.modelcatalogue.spreadsheet.api.HorizontalAlignmentConfigurer
5 |
6 | class PoiHorizontalAlignmentConfigurer implements HorizontalAlignmentConfigurer {
7 |
8 | final PoiCellStyleDefinition style
9 |
10 | PoiHorizontalAlignmentConfigurer(PoiCellStyleDefinition style) {
11 | this.style = style
12 | }
13 |
14 | @Override
15 | Object getRight() {
16 | style.setHorizontalAlignment(HorizontalAlignment.RIGHT)
17 | return null
18 | }
19 |
20 | @Override
21 | Object getLeft() {
22 | style.setHorizontalAlignment(HorizontalAlignment.LEFT)
23 | return null
24 | }
25 |
26 | @Override
27 | Object getGeneral() {
28 | style.setHorizontalAlignment(HorizontalAlignment.GENERAL)
29 | return null
30 | }
31 |
32 | @Override
33 | Object getCenter() {
34 | style.setHorizontalAlignment(HorizontalAlignment.CENTER)
35 | return null
36 | }
37 |
38 | @Override
39 | Object getFill() {
40 | style.setHorizontalAlignment(HorizontalAlignment.FILL)
41 | return null
42 | }
43 |
44 | @Override
45 | Object getJustify() {
46 | style.setHorizontalAlignment(HorizontalAlignment.JUSTIFY)
47 | return null
48 | }
49 |
50 | @Override
51 | Object getCenterSelection() {
52 | style.setHorizontalAlignment(HorizontalAlignment.CENTER_SELECTION)
53 | return null
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiImageCreator.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import org.apache.poi.ss.usermodel.ClientAnchor
4 | import org.apache.poi.ss.usermodel.CreationHelper
5 | import org.apache.poi.ss.usermodel.Drawing
6 | import org.apache.poi.ss.usermodel.Picture
7 | import org.modelcatalogue.spreadsheet.builder.api.ImageCreator
8 |
9 | class PoiImageCreator implements ImageCreator {
10 |
11 | private final PoiCellDefinition cell
12 | private final int type
13 |
14 | PoiImageCreator(PoiCellDefinition poiCell, int type) {
15 | this.cell = poiCell
16 | this.type = type
17 | }
18 |
19 | @Override
20 | void from(String fileOrUrl) {
21 | if (fileOrUrl.startsWith('https://') || fileOrUrl.startsWith('http://')) {
22 | from new URL(fileOrUrl).newInputStream()
23 | return
24 | }
25 | from new FileInputStream(new File(fileOrUrl))
26 | }
27 |
28 | @Override
29 | void from(InputStream stream) {
30 | addPicture(cell.row.sheet.sheet.workbook.addPicture(stream, type))
31 | }
32 |
33 | @Override
34 | void from(byte[] imageData) {
35 | addPicture(cell.row.sheet.sheet.workbook.addPicture(imageData, type))
36 | }
37 |
38 | void addPicture(int pictureIdx) {
39 | Drawing drawing = cell.row.sheet.sheet.createDrawingPatriarch();
40 |
41 | CreationHelper helper = cell.row.sheet.sheet.workbook.getCreationHelper();
42 | ClientAnchor anchor = helper.createClientAnchor();
43 | anchor.setCol1(cell.cell.columnIndex)
44 | anchor.setRow1(cell.cell.rowIndex)
45 |
46 | Picture pict = drawing.createPicture(anchor, pictureIdx);
47 | pict.resize();
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiLinkDefinition.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import org.apache.poi.common.usermodel.Hyperlink
4 | import org.apache.poi.xssf.usermodel.XSSFCell
5 | import org.apache.poi.xssf.usermodel.XSSFHyperlink
6 | import org.apache.poi.xssf.usermodel.XSSFWorkbook
7 | import org.modelcatalogue.spreadsheet.builder.api.LinkDefinition
8 |
9 | class PoiLinkDefinition implements LinkDefinition {
10 |
11 | private final XSSFCell cell
12 | private final PoiWorkbookDefinition workbook
13 |
14 | PoiLinkDefinition(PoiWorkbookDefinition workbook, XSSFCell xssfCell) {
15 | this.cell = xssfCell
16 | this.workbook = workbook
17 | }
18 |
19 | @Override
20 | void name(String name) {
21 | workbook.addPendingLink(name, cell)
22 | }
23 |
24 | @Override
25 | void email(String email) {
26 | XSSFWorkbook workbook = cell.row.sheet.workbook as XSSFWorkbook
27 | XSSFHyperlink link = workbook.creationHelper.createHyperlink(Hyperlink.LINK_EMAIL) as XSSFHyperlink
28 | link.address = "mailto:$email"
29 | cell.hyperlink = link
30 | }
31 |
32 | @Override
33 | void email(Map parameters, String email) {
34 | XSSFWorkbook workbook = cell.row.sheet.workbook as XSSFWorkbook
35 | XSSFHyperlink link = workbook.creationHelper.createHyperlink(Hyperlink.LINK_EMAIL) as XSSFHyperlink
36 | link.address = "mailto:$email?${parameters.collect { String key, value -> "${URLEncoder.encode(key, 'UTF-8')}=${value ? URLEncoder.encode(value.toString(), 'UTF-8') : ''}"}.join('&')}"
37 | cell.hyperlink = link
38 | }
39 |
40 | @Override
41 | void url(String url) {
42 | XSSFWorkbook workbook = cell.row.sheet.workbook as XSSFWorkbook
43 | XSSFHyperlink link = workbook.creationHelper.createHyperlink(Hyperlink.LINK_URL) as XSSFHyperlink
44 | link.address = url
45 | cell.hyperlink = link
46 | }
47 |
48 | @Override
49 | void file(String path) {
50 | XSSFWorkbook workbook = cell.row.sheet.workbook as XSSFWorkbook
51 | XSSFHyperlink link = workbook.creationHelper.createHyperlink(Hyperlink.LINK_FILE) as XSSFHyperlink
52 | link.address = path
53 | cell.hyperlink = link
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiPageSettingsProvider.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import org.apache.poi.ss.usermodel.PaperSize
4 | import org.apache.poi.ss.usermodel.PrintOrientation
5 | import org.apache.poi.xssf.usermodel.XSSFPrintSetup
6 | import org.modelcatalogue.spreadsheet.api.Keywords
7 | import org.modelcatalogue.spreadsheet.api.Page
8 | import org.modelcatalogue.spreadsheet.api.AbstractPageSettingsProvider
9 | import org.modelcatalogue.spreadsheet.builder.api.FitDimension
10 | import org.modelcatalogue.spreadsheet.builder.api.PageDefinition
11 |
12 | class PoiPageSettingsProvider extends AbstractPageSettingsProvider implements Page, PageDefinition {
13 |
14 | private final XSSFPrintSetup printSetup
15 |
16 | PoiPageSettingsProvider(PoiSheetDefinition sheet) {
17 | this.printSetup = sheet.sheet.printSetup
18 | }
19 |
20 | @Override
21 | void orientation(Keywords.Orientation orientation) {
22 | switch (orientation) {
23 | case Keywords.Orientation.PORTRAIT:
24 | printSetup.setOrientation(PrintOrientation.PORTRAIT)
25 | break
26 | case Keywords.Orientation.LANDSCAPE:
27 | printSetup.setOrientation(PrintOrientation.LANDSCAPE)
28 | break
29 | }
30 | }
31 |
32 | @Override
33 | void paper(Keywords.Paper paper) {
34 | switch (paper) {
35 | case Keywords.Paper.LETTER:
36 | printSetup.setPaperSize(PaperSize.LETTER_PAPER)
37 | break
38 | case Keywords.Paper.LETTER_SMALL:
39 | printSetup.setPaperSize(PaperSize.LETTER_SMALL_PAPER)
40 | break
41 | case Keywords.Paper.TABLOID:
42 | printSetup.setPaperSize(PaperSize.TABLOID_PAPER)
43 | break
44 | case Keywords.Paper.LEDGER:
45 | printSetup.setPaperSize(PaperSize.LEDGER_PAPER)
46 | break
47 | case Keywords.Paper.LEGAL:
48 | printSetup.setPaperSize(PaperSize.LEGAL_PAPER)
49 | break
50 | case Keywords.Paper.STATEMENT:
51 | printSetup.setPaperSize(PaperSize.STATEMENT_PAPER)
52 | break
53 | case Keywords.Paper.EXECUTIVE:
54 | printSetup.setPaperSize(PaperSize.EXECUTIVE_PAPER)
55 | break
56 | case Keywords.Paper.A3:
57 | printSetup.setPaperSize(PaperSize.A3_PAPER)
58 | break
59 | case Keywords.Paper.A4:
60 | printSetup.setPaperSize(PaperSize.A4_PAPER)
61 | break
62 | case Keywords.Paper.A4_SMALL:
63 | printSetup.setPaperSize(PaperSize.A4_SMALL_PAPER)
64 | break
65 | case Keywords.Paper.A5:
66 | printSetup.setPaperSize(PaperSize.A5_PAPER)
67 | break
68 | case Keywords.Paper.B4:
69 | printSetup.setPaperSize(PaperSize.B4_PAPER)
70 | break
71 | case Keywords.Paper.B5:
72 | printSetup.setPaperSize(PaperSize.B5_PAPER)
73 | break
74 | case Keywords.Paper.FOLIO:
75 | printSetup.setPaperSize(PaperSize.FOLIO_PAPER)
76 | break
77 | case Keywords.Paper.QUARTO:
78 | printSetup.setPaperSize(PaperSize.QUARTO_PAPER)
79 | break
80 | case Keywords.Paper.STANDARD_10_14:
81 | printSetup.setPaperSize(PaperSize.STANDARD_PAPER_10_14)
82 | break
83 | case Keywords.Paper.STANDARD_11_17:
84 | printSetup.setPaperSize(PaperSize.STANDARD_PAPER_11_17)
85 | break
86 | }
87 | }
88 |
89 | @Override
90 | FitDimension fit(Keywords.Fit widthOrHeight) {
91 | return new PoiFitDimension(printSetup, widthOrHeight)
92 | }
93 |
94 | @Override
95 | Keywords.Orientation getOrientation() {
96 | switch(printSetup.orientation) {
97 | case PrintOrientation.DEFAULT:
98 | return null
99 | case PrintOrientation.PORTRAIT:
100 | return Keywords.Orientation.PORTRAIT
101 | case PrintOrientation.LANDSCAPE:
102 | return Keywords.Orientation.LANDSCAPE
103 | }
104 | return null
105 | }
106 |
107 | @Override
108 | Keywords.Paper getPaper() {
109 | switch (printSetup.paperSizeEnum) {
110 | case PaperSize.LETTER_PAPER:
111 | return Keywords.Paper.LETTER
112 | case PaperSize.LETTER_SMALL_PAPER:
113 | return Keywords.Paper.LETTER_SMALL
114 | case PaperSize.TABLOID_PAPER:
115 | return Keywords.Paper.TABLOID
116 | case PaperSize.LEDGER_PAPER:
117 | return Keywords.Paper.LEDGER
118 | case PaperSize.LEGAL_PAPER:
119 | return Keywords.Paper.LEGAL
120 | case PaperSize.STATEMENT_PAPER:
121 | return Keywords.Paper.STATEMENT
122 | case PaperSize.EXECUTIVE_PAPER:
123 | return Keywords.Paper.EXECUTIVE
124 | case PaperSize.A3_PAPER:
125 | return Keywords.Paper.A3
126 | case PaperSize.A4_PAPER:
127 | return Keywords.Paper.A4
128 | case PaperSize.A4_SMALL_PAPER:
129 | return Keywords.Paper.A4_SMALL
130 | case PaperSize.A5_PAPER:
131 | return Keywords.Paper.A5
132 | case PaperSize.B4_PAPER:
133 | return Keywords.Paper.B4
134 | case PaperSize.B5_PAPER:
135 | return Keywords.Paper.B5
136 | case PaperSize.FOLIO_PAPER:
137 | return Keywords.Paper.FOLIO
138 | case PaperSize.QUARTO_PAPER:
139 | return Keywords.Paper.QUARTO
140 | case PaperSize.STANDARD_PAPER_10_14:
141 | return Keywords.Paper.STANDARD_10_14
142 | case PaperSize.STANDARD_PAPER_11_17:
143 | return Keywords.Paper.STANDARD_11_17
144 | }
145 | return null
146 | }
147 | }
148 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiRowDefinition.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import groovy.transform.stc.ClosureParams
4 | import groovy.transform.stc.FromString
5 | import org.apache.poi.xssf.usermodel.XSSFCell
6 | import org.apache.poi.xssf.usermodel.XSSFRow
7 | import org.modelcatalogue.spreadsheet.api.Cell
8 | import org.modelcatalogue.spreadsheet.api.Row
9 | import org.modelcatalogue.spreadsheet.builder.api.CellDefinition
10 | import org.modelcatalogue.spreadsheet.builder.api.CellStyleDefinition
11 | import org.modelcatalogue.spreadsheet.builder.api.RowDefinition
12 |
13 | class PoiRowDefinition implements RowDefinition, Row {
14 |
15 | private final XSSFRow xssfRow
16 | private final PoiSheetDefinition sheet
17 |
18 | private String styleName
19 | private String[] styleNames
20 | private Closure styleDefinition
21 |
22 | private final List startPositions = []
23 | private int nextColNumber = 0
24 | private final Map cells = [:]
25 |
26 | PoiRowDefinition(PoiSheetDefinition sheet, XSSFRow xssfRow) {
27 | this.sheet = sheet
28 | this.xssfRow = xssfRow
29 | }
30 |
31 | List getCells() {
32 | // TODO: reuse existing cells
33 | xssfRow.collect { new PoiCellDefinition(this, it as XSSFCell) }
34 | }
35 |
36 | private PoiCellDefinition findOrCreateCell(int zeroBasedCellNumber) {
37 | PoiCellDefinition cell = cells[zeroBasedCellNumber + 1]
38 |
39 | if (cell) {
40 | return cell
41 | }
42 |
43 | XSSFCell xssfCell = xssfRow.createCell(zeroBasedCellNumber)
44 |
45 | cell = new PoiCellDefinition(this, xssfCell)
46 |
47 | cells[zeroBasedCellNumber + 1] = cell
48 |
49 | return cell
50 | }
51 |
52 | @Override
53 | void cell() {
54 | cell null
55 | }
56 |
57 | @Override
58 | int getNumber() {
59 | return xssfRow.rowNum + 1
60 | }
61 |
62 | @Override
63 | void cell(Object value) {
64 | PoiCellDefinition poiCell = findOrCreateCell nextColNumber++
65 |
66 | if (styles) {
67 | if (styleDefinition) {
68 | poiCell.styles styles, styleDefinition
69 | } else {
70 | poiCell.styles styles
71 | }
72 | } else if(styleDefinition) {
73 | poiCell.style styleDefinition
74 | }
75 |
76 | poiCell.value value
77 |
78 | poiCell.resolve()
79 | }
80 |
81 | @Override
82 | void cell(@DelegatesTo(CellDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.CellDefinition") Closure cellDefinition) {
83 | PoiCellDefinition poiCell = findOrCreateCell nextColNumber
84 |
85 | if (styles) {
86 | if (styleDefinition) {
87 | poiCell.styles styles, styleDefinition
88 | } else {
89 | poiCell.styles styles
90 | }
91 | } else if(styleDefinition) {
92 | poiCell.style styleDefinition
93 | }
94 |
95 | poiCell.with cellDefinition
96 |
97 | nextColNumber += poiCell.colspan
98 |
99 | handleSpans(poiCell)
100 |
101 | poiCell.resolve()
102 | }
103 |
104 | private void handleSpans(PoiCellDefinition poiCell) {
105 | if (poiCell.colspan > 1 || poiCell.rowspan > 1) {
106 | xssfRow.sheet.addMergedRegion(poiCell.cellRangeAddress);
107 | }
108 | }
109 |
110 | @Override
111 | void cell(int column, @DelegatesTo(CellDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.CellDefinition") Closure cellDefinition) {
112 | nextColNumber = column
113 |
114 | PoiCellDefinition poiCell = findOrCreateCell column - 1
115 |
116 | if (styles) {
117 | if (styleDefinition) {
118 | poiCell.styles styles, styleDefinition
119 | } else {
120 | poiCell.styles styles
121 | }
122 | } else if(styleDefinition) {
123 | poiCell.style styleDefinition
124 | }
125 |
126 | poiCell.with cellDefinition
127 |
128 | handleSpans(poiCell)
129 |
130 | poiCell.resolve()
131 | }
132 |
133 | @Override
134 | void cell(String column, @DelegatesTo(CellDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.CellDefinition") Closure cellDefinition) {
135 | cell Cell.Util.parseColumn(column), cellDefinition
136 | }
137 |
138 | @Override
139 | void style(@DelegatesTo(CellStyleDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.CellStyleDefinition") Closure styleDefinition) {
140 | this.styleDefinition = styleDefinition
141 | }
142 |
143 | @Override
144 | void style(String name) {
145 | this.styleName = name
146 | }
147 |
148 | @Override
149 | void style(String name, @DelegatesTo(CellStyleDefinition.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.CellStyleDefinition") Closure styleDefinition) {
150 | style name
151 | style styleDefinition
152 | }
153 |
154 | @Override
155 | void styles(Iterable names, @DelegatesTo(CellStyleDefinition.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.CellStyleDefinition") Closure styleDefinition) {
156 | styles names
157 | style styleDefinition
158 | }
159 |
160 | @Override
161 | void styles(String... names) {
162 | this.styleNames = names
163 | }
164 |
165 | @Override
166 | void styles(Iterable names) {
167 | styles(names.toList().toArray(new String[names.size()]))
168 | }
169 |
170 | @Override
171 | PoiSheetDefinition getSheet() {
172 | return sheet
173 | }
174 |
175 | protected XSSFRow getRow() {
176 | return xssfRow
177 | }
178 |
179 | @Override
180 | void group(@DelegatesTo(RowDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.RowDefinition") Closure insideGroupDefinition) {
181 | createGroup(false, insideGroupDefinition)
182 | }
183 |
184 | @Override
185 | void collapse(@DelegatesTo(RowDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.RowDefinition") Closure insideGroupDefinition) {
186 | createGroup(true, insideGroupDefinition)
187 | }
188 |
189 | @Override
190 | PoiRowDefinition getAbove(int howMany) {
191 | aboveOrBellow(-howMany)
192 | }
193 |
194 | @Override
195 | PoiRowDefinition getAbove() {
196 | return getAbove(1)
197 | }
198 |
199 | @Override
200 | PoiRowDefinition getBellow(int howMany) {
201 | aboveOrBellow(howMany)
202 | }
203 |
204 | @Override
205 | PoiRowDefinition getBellow() {
206 | return getBellow(1)
207 | }
208 |
209 | private PoiRowDefinition aboveOrBellow(int howMany) {
210 | if (xssfRow.rowNum + howMany < 0 || xssfRow.rowNum + howMany > xssfRow.sheet.lastRowNum) {
211 | return null
212 | }
213 | PoiRowDefinition existing = sheet.getRowByNumber(number + howMany)
214 | if (existing) {
215 | return existing
216 | }
217 | return sheet.createRowWrapper(number + howMany)
218 | }
219 |
220 | private void createGroup(boolean collapsed, @DelegatesTo(RowDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.RowDefinition") Closure insideGroupDefinition) {
221 | startPositions.push nextColNumber
222 | with insideGroupDefinition
223 |
224 | int startPosition = startPositions.pop()
225 |
226 | if (nextColNumber - startPosition > 1) {
227 | int endPosition = nextColNumber - 1
228 | sheet.sheet.groupColumn(startPosition, endPosition)
229 | if (collapsed) {
230 | sheet.sheet.setColumnGroupCollapsed(endPosition, true)
231 | }
232 | }
233 |
234 | }
235 |
236 | PoiCellDefinition getCellByNumber(int oneBasedColumnNumber) {
237 | cells[oneBasedColumnNumber]
238 | }
239 |
240 | @Override
241 | String toString() {
242 | return "Row[${sheet.name}!${number}]"
243 | }
244 |
245 | public T asType(Class type) {
246 | if (type.isInstance(row)) {
247 | return row
248 | }
249 | return super.asType(type)
250 | }
251 |
252 | protected List getStyles() {
253 | List styles = []
254 | if (styleName) {
255 | styles << styleName
256 | }
257 | if (styleNames) {
258 | styles.addAll(styleNames)
259 | }
260 | return styles
261 | }
262 | }
263 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiSheetDefinition.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import groovy.transform.stc.ClosureParams
4 | import groovy.transform.stc.FromString
5 | import org.apache.poi.ss.util.CellRangeAddress
6 | import org.apache.poi.xssf.usermodel.XSSFRow
7 | import org.apache.poi.xssf.usermodel.XSSFSheet
8 | import org.modelcatalogue.spreadsheet.api.Cell
9 | import org.modelcatalogue.spreadsheet.api.Keywords
10 | import org.modelcatalogue.spreadsheet.api.Page
11 | import org.modelcatalogue.spreadsheet.api.Sheet
12 | import org.modelcatalogue.spreadsheet.builder.api.PageDefinition
13 | import org.modelcatalogue.spreadsheet.builder.api.RowDefinition
14 | import org.modelcatalogue.spreadsheet.builder.api.SheetDefinition
15 |
16 | class PoiSheetDefinition implements SheetDefinition, Sheet {
17 |
18 | private final XSSFSheet xssfSheet
19 | private final PoiWorkbookDefinition workbook
20 |
21 | private final List startPositions = []
22 | private int nextRowNumber = 0
23 | private final Set autoColumns = new HashSet()
24 | private final Map rows = [:]
25 | private boolean automaticFilter
26 |
27 | PoiSheetDefinition(PoiWorkbookDefinition workbook, XSSFSheet xssfSheet) {
28 | this.workbook = workbook
29 | this.xssfSheet = xssfSheet
30 | }
31 |
32 |
33 | @Override
34 | String getName() {
35 | return xssfSheet.sheetName
36 | }
37 |
38 | @Override
39 | PoiWorkbookDefinition getWorkbook() {
40 | return workbook
41 | }
42 |
43 | List getRows() {
44 | xssfSheet.collect {
45 | PoiRowDefinition row = getRowByNumber(it.rowNum + 1)
46 | if (row) {
47 | return row
48 | }
49 | return createRowWrapper(it.rowNum + 1)
50 | }
51 | }
52 |
53 | PoiRowDefinition getRowByNumber(int rowNumberStartingOne) {
54 | rows[rowNumberStartingOne]
55 | }
56 |
57 | @Override
58 | void row() {
59 | findOrCreateRow nextRowNumber++
60 | }
61 |
62 | @Override
63 | Sheet getNext() {
64 | int current = workbook.workbook.getSheetIndex(sheet.getSheetName())
65 |
66 | if (current == workbook.workbook.getNumberOfSheets() - 1) {
67 | return null
68 | }
69 | XSSFSheet next = workbook.workbook.getSheetAt(current + 1)
70 | Sheet nextPoiSheet = workbook.sheets.find { it.sheet.sheetName == next.sheetName }
71 | if (nextPoiSheet) {
72 | return nextPoiSheet
73 | }
74 | return new PoiSheetDefinition(workbook, next)
75 | }
76 |
77 | @Override
78 | Sheet getPrevious() {
79 | int current = workbook.workbook.getSheetIndex(sheet.getSheetName());
80 |
81 | if (current == 0) {
82 | return null
83 | }
84 | XSSFSheet next = workbook.workbook.getSheetAt(current - 1);
85 | Sheet nextPoiSheet = workbook.sheets.find { it.sheet.sheetName == next.sheetName }
86 | if (nextPoiSheet) {
87 | return nextPoiSheet
88 | }
89 | return new PoiSheetDefinition(workbook, next)
90 | }
91 |
92 | @Override
93 | Page getPage() {
94 | return new PoiPageSettingsProvider(this)
95 | }
96 |
97 | private PoiRowDefinition findOrCreateRow(int zeroBasedRowNumber) {
98 | PoiRowDefinition row = rows[zeroBasedRowNumber + 1]
99 |
100 | if (row) {
101 | return row
102 | }
103 |
104 | XSSFRow xssfRow = xssfSheet.createRow(zeroBasedRowNumber)
105 |
106 | row = new PoiRowDefinition(this, xssfRow)
107 |
108 | rows[zeroBasedRowNumber + 1] = row
109 |
110 | return row
111 | }
112 |
113 | @Override
114 | void row(@DelegatesTo(RowDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.RowDefinition") Closure rowDefinition) {
115 | PoiRowDefinition row = findOrCreateRow nextRowNumber++
116 | row.with rowDefinition
117 | }
118 |
119 | @Override
120 | void row(int oneBasedRowNumber, @DelegatesTo(RowDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.RowDefinition") Closure rowDefinition) {
121 | assert oneBasedRowNumber > 0
122 | nextRowNumber = oneBasedRowNumber
123 |
124 | PoiRowDefinition poiRow = findOrCreateRow oneBasedRowNumber - 1
125 | poiRow.with rowDefinition
126 | }
127 |
128 | @Override
129 | void freeze(int column, int row) {
130 | xssfSheet.createFreezePane(column, row)
131 | }
132 |
133 | @Override
134 | void freeze(String column, int row) {
135 | freeze Cell.Util.parseColumn(column), row
136 | }
137 |
138 | @Override
139 | void collapse(@DelegatesTo(SheetDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.SheetDefinition") Closure insideGroupDefinition) {
140 | createGroup(true, insideGroupDefinition)
141 | }
142 |
143 | @Override
144 | void group(@DelegatesTo(SheetDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.SheetDefinition") Closure insideGroupDefinition) {
145 | createGroup(false, insideGroupDefinition)
146 | }
147 |
148 | @Override
149 | Object getLocked() {
150 | sheet.enableLocking()
151 | return null
152 | }
153 |
154 | @Override
155 | void password(String password) {
156 | sheet.protectSheet(password)
157 | }
158 |
159 | @Override
160 | void filter(Keywords.Auto auto) {
161 | automaticFilter = true
162 | }
163 |
164 | @Override
165 | Keywords.Auto getAuto() {
166 | return Keywords.Auto.AUTO
167 | }
168 |
169 | @Override
170 | void page(@DelegatesTo(PageDefinition.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.PageDefinition") Closure pageDefinition) {
171 | PageDefinition page = new PoiPageSettingsProvider(this)
172 | page.with pageDefinition
173 | }
174 |
175 | private void createGroup(boolean collapsed, @DelegatesTo(SheetDefinition.class) Closure insideGroupDefinition) {
176 | startPositions.push nextRowNumber
177 | with insideGroupDefinition
178 |
179 | int startPosition = startPositions.pop()
180 |
181 | if (nextRowNumber - startPosition > 1) {
182 | int endPosition = nextRowNumber - 1
183 | xssfSheet.groupRow(startPosition, endPosition)
184 | if (collapsed) {
185 | xssfSheet.setRowGroupCollapsed(endPosition, true)
186 | }
187 | }
188 |
189 | }
190 |
191 | protected XSSFSheet getSheet() {
192 | return xssfSheet
193 | }
194 |
195 | protected void addAutoColumn(int i) {
196 | autoColumns << i
197 | }
198 |
199 | protected void processAutoColumns() {
200 | for (int index in autoColumns) {
201 | xssfSheet.autoSizeColumn(index)
202 | }
203 | }
204 |
205 | PoiRowDefinition createRowWrapper(int oneBasedRowNumber) {
206 | rows[oneBasedRowNumber] = new PoiRowDefinition(this, sheet.getRow(oneBasedRowNumber - 1))
207 | }
208 |
209 | @Override
210 | String toString() {
211 | return "Sheet[${name}]"
212 | }
213 |
214 | public T asType(Class type) {
215 | if (type.isInstance(sheet)) {
216 | return sheet
217 | }
218 | return super.asType(type)
219 | }
220 |
221 | protected void processAutomaticFilter() {
222 | if (automaticFilter && sheet.lastRowNum > 0) {
223 | sheet.setAutoFilter(new CellRangeAddress(
224 | sheet.firstRowNum,
225 | sheet.lastRowNum,
226 | sheet.getRow(sheet.firstRowNum).firstCellNum,
227 | sheet.getRow(sheet.firstRowNum).lastCellNum - 1
228 | ))
229 | }
230 | }
231 | }
232 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiSpreadsheetBuilder.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import groovy.transform.stc.ClosureParams
4 | import groovy.transform.stc.FromString
5 | import org.apache.poi.xssf.usermodel.XSSFWorkbook
6 | import org.modelcatalogue.spreadsheet.builder.api.SpreadsheetBuilder
7 | import org.modelcatalogue.spreadsheet.builder.api.SpreadsheetDefinition
8 | import org.modelcatalogue.spreadsheet.builder.api.WorkbookDefinition
9 |
10 |
11 | enum PoiSpreadsheetBuilder implements SpreadsheetBuilder {
12 |
13 | INSTANCE;
14 |
15 | @Override
16 | SpreadsheetDefinition build( @DelegatesTo(WorkbookDefinition.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.WorkbookDefinition") Closure workbookDefinition) {
17 | return buildInternal(new XSSFWorkbook(), workbookDefinition)
18 | }
19 |
20 | private static PoiWorkbookDefinition buildInternal(XSSFWorkbook workbook, @DelegatesTo(WorkbookDefinition.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.WorkbookDefinition") Closure workbookDefinition) {
21 | PoiWorkbookDefinition poiWorkbook = new PoiWorkbookDefinition(workbook)
22 | poiWorkbook.with workbookDefinition
23 | poiWorkbook.resolve()
24 |
25 | return poiWorkbook
26 | }
27 |
28 | @Override
29 | SpreadsheetDefinition build(InputStream template, @DelegatesTo(WorkbookDefinition.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.WorkbookDefinition") Closure workbookDefinition) {
30 | template.withStream {
31 | buildInternal(new XSSFWorkbook(it), workbookDefinition)
32 | }
33 | }
34 |
35 | @Override
36 | SpreadsheetDefinition build(File template, @DelegatesTo(WorkbookDefinition.class) @ClosureParams(value = FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.WorkbookDefinition") Closure workbookDefinition) {
37 | template.withInputStream {
38 | buildInternal(new XSSFWorkbook(it), workbookDefinition)
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiWidthModifier.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import org.modelcatalogue.spreadsheet.builder.api.DimensionModifier
4 |
5 | class PoiWidthModifier implements DimensionModifier {
6 |
7 | private PoiCellDefinition cell
8 | private final double width
9 |
10 | PoiWidthModifier(PoiCellDefinition cell, double width) {
11 | this.cell = cell
12 | this.width = width
13 | }
14 |
15 | @Override
16 | Object getCm() {
17 | cell.width(width * 4.6666666666666666666667)
18 | return null
19 | }
20 |
21 | @Override
22 | Object getInch() {
23 | cell.width(width * 12)
24 | return null
25 | }
26 |
27 | @Override
28 | Object getInches() {
29 | inch
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiWorkbookDefinition.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import groovy.transform.stc.ClosureParams
4 | import groovy.transform.stc.FromString
5 | import org.apache.poi.ss.util.WorkbookUtil
6 | import org.apache.poi.xssf.usermodel.XSSFCell
7 | import org.apache.poi.xssf.usermodel.XSSFSheet
8 | import org.apache.poi.xssf.usermodel.XSSFWorkbook
9 | import org.modelcatalogue.spreadsheet.api.Workbook
10 | import org.modelcatalogue.spreadsheet.builder.api.CellStyleDefinition
11 | import org.modelcatalogue.spreadsheet.builder.api.SheetDefinition
12 | import org.modelcatalogue.spreadsheet.builder.api.SpreadsheetDefinition
13 | import org.modelcatalogue.spreadsheet.builder.api.Stylesheet
14 | import org.modelcatalogue.spreadsheet.builder.api.WorkbookDefinition
15 |
16 | class PoiWorkbookDefinition implements WorkbookDefinition, Workbook, SpreadsheetDefinition {
17 |
18 | private final XSSFWorkbook workbook
19 | private final Map namedStylesDefinition = [:]
20 | private final Map namedStyles = [:]
21 | private final Map sheets = [:]
22 | private final List toBeResolved = []
23 |
24 | PoiWorkbookDefinition(XSSFWorkbook workbook) {
25 | this.workbook = workbook
26 | }
27 |
28 | @Override
29 | void sheet(String name, @DelegatesTo(SheetDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.SheetDefinition") Closure sheetDefinition) {
30 | PoiSheetDefinition sheet = sheets[name]
31 |
32 | if (!sheet) {
33 | XSSFSheet xssfSheet = workbook.getSheet(WorkbookUtil.createSafeSheetName(name)) ?: workbook.createSheet(WorkbookUtil.createSafeSheetName(name))
34 | sheet = new PoiSheetDefinition(this, xssfSheet)
35 | sheets[name] = sheet
36 | }
37 |
38 | sheet.with sheetDefinition
39 |
40 | sheet.processAutoColumns()
41 | sheet.processAutomaticFilter()
42 | }
43 |
44 | @Override
45 | void style(String name, @DelegatesTo(CellStyleDefinition.class) @ClosureParams(value=FromString.class, options = "org.modelcatalogue.spreadsheet.builder.api.CellStyleDefinition") Closure styleDefinition) {
46 | namedStylesDefinition[name] = styleDefinition
47 | }
48 |
49 | @Override
50 | void apply(Class extends Stylesheet> stylesheet) {
51 | apply stylesheet.newInstance()
52 | }
53 |
54 | @Override
55 | void apply(Stylesheet stylesheet) {
56 | stylesheet.declareStyles(this)
57 | }
58 |
59 | XSSFWorkbook getWorkbook() {
60 | return workbook
61 | }
62 |
63 | protected PoiCellStyleDefinition getStyle(String name) {
64 | PoiCellStyleDefinition style = namedStyles[name]
65 |
66 | if (style) {
67 | return style
68 | }
69 |
70 | style = new PoiCellStyleDefinition(this)
71 | style.with getStyleDefinition(name)
72 | style.seal()
73 |
74 | namedStyles[name] = style
75 |
76 | return style
77 | }
78 |
79 | protected PoiCellStyleDefinition getStyles(Iterable names) {
80 | String name = names.join('.')
81 |
82 | PoiCellStyleDefinition style = namedStyles[name]
83 |
84 | if (style) {
85 | return style
86 | }
87 |
88 | style = new PoiCellStyleDefinition(this)
89 | for (String n in names) {
90 | style.with getStyleDefinition(n)
91 | }
92 | style.seal()
93 |
94 | namedStyles[name] = style
95 |
96 | return style
97 | }
98 |
99 | protected Closure getStyleDefinition(String name) {
100 | Closure style = namedStylesDefinition[name]
101 | if (!style) {
102 | throw new IllegalArgumentException("Style '$name' not defined")
103 | }
104 | return style
105 | }
106 |
107 | protected void addPendingFormula(String formula, XSSFCell cell) {
108 | toBeResolved << new PendingFormula(cell, formula)
109 | }
110 |
111 | protected void addPendingLink(String ref, XSSFCell cell) {
112 | toBeResolved << new PendingLink(cell, ref)
113 | }
114 |
115 | protected void resolve() {
116 | for (Resolvable resolvable in toBeResolved) {
117 | resolvable.resolve()
118 | }
119 | }
120 |
121 | List getSheets() {
122 | // TODO: reuse existing sheets
123 | workbook.collect { new PoiSheetDefinition(this, it as XSSFSheet) }
124 | }
125 |
126 | @Override
127 | void writeTo(OutputStream outputStream) {
128 | workbook.write(outputStream)
129 | }
130 |
131 | @Override
132 | void writeTo(File file) {
133 | file.withOutputStream {
134 | writeTo(it)
135 | }
136 | }
137 |
138 | public T asType(Class type) {
139 | if (type.isInstance(workbook)) {
140 | return workbook
141 | }
142 | return super.asType(type)
143 | }
144 |
145 |
146 | }
147 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/Resolvable.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import groovy.transform.PackageScope;
4 |
5 | @PackageScope interface Resolvable {
6 |
7 | void resolve()
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/builder/poi/RichTextPart.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | class RichTextPart {
4 |
5 | final String text
6 | final PoiFontDefinition font
7 | final int start
8 | final int end
9 |
10 | RichTextPart(String text, PoiFontDefinition font, int start, int end) {
11 | this.text = text
12 | this.font = font
13 | this.start = start
14 | this.end = end
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/main/groovy/org/modelcatalogue/spreadsheet/query/poi/PoiSpreadsheetCriteria.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.query.poi
2 |
3 | import org.apache.poi.xssf.usermodel.XSSFWorkbook
4 | import org.modelcatalogue.spreadsheet.builder.poi.PoiWorkbookDefinition
5 | import org.modelcatalogue.spreadsheet.query.api.SpreadsheetCriteria
6 | import org.modelcatalogue.spreadsheet.query.api.SpreadsheetCriteriaFactory
7 | import org.modelcatalogue.spreadsheet.query.simple.SimpleSpreadsheetCriteria
8 |
9 | enum PoiSpreadsheetCriteria implements SpreadsheetCriteriaFactory {
10 |
11 | FACTORY;
12 |
13 | @Override
14 | SpreadsheetCriteria forFile(File spreadsheet) throws FileNotFoundException {
15 | return forStream(new FileInputStream(spreadsheet));
16 | }
17 |
18 | @Override
19 | SpreadsheetCriteria forStream(InputStream stream) {
20 | return SimpleSpreadsheetCriteria.forWorkbook(new PoiWorkbookDefinition(new XSSFWorkbook(stream)))
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/test/groovy/org/modelcatalogue/spreadsheet/builder/poi/MyStyles.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import org.modelcatalogue.spreadsheet.builder.api.CanDefineStyle
4 | import org.modelcatalogue.spreadsheet.builder.api.Stylesheet
5 |
6 | class MyStyles implements Stylesheet {
7 |
8 | void declareStyles(CanDefineStyle stylable) {
9 | stylable.style('h1') {
10 | foreground whiteSmoke
11 | fill solidForeground
12 | font {
13 | size 22
14 | }
15 | }
16 | stylable.style('h2') {
17 | base 'h1'
18 | font {
19 | size 16
20 | }
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/test/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiCellSpec.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import spock.lang.Specification
4 | import spock.lang.Unroll
5 |
6 | class PoiCellSpec extends Specification {
7 |
8 | @Unroll
9 | def "normalize name #name to #result"() {
10 | expect:
11 | PoiCellDefinition.fixName(name) == result
12 |
13 | where:
14 | name | result
15 | 'C' | /_C/
16 | 'c' | /_c/
17 | 'R' | /_R/
18 | 'r' | /_r/
19 | '10' | /_10/
20 | '(5)' | /_5_/
21 | '2.4' | /_2.4/
22 | 'foo' | /foo/
23 | 'foo bar' | /foo_bar/
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/spreadsheet-builder-poi/src/test/groovy/org/modelcatalogue/spreadsheet/builder/poi/PoiCellStyleSpec.groovy:
--------------------------------------------------------------------------------
1 | package org.modelcatalogue.spreadsheet.builder.poi
2 |
3 | import org.apache.poi.xssf.usermodel.XSSFColor
4 | import spock.lang.Specification
5 | import spock.lang.Unroll
6 |
7 | class PoiCellStyleSpec extends Specification {
8 |
9 | @Unroll
10 | def "parse #hex to #r,#g,#b"() {
11 | when:
12 | XSSFColor color = PoiCellStyleDefinition.parseColor(hex)
13 |
14 | then:
15 | color.getRGB() == [r,g,b] as byte[]
16 |
17 | where:
18 | hex | r | g | b
19 | '#000000' | 0 | 0 | 0
20 | '#aabbcc' | -86 | -69 | -52
21 | '#ffffff' | -1 | -1 | -1
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |