aboutsummaryrefslogtreecommitdiffstats
path: root/src/examples/groovy
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2018-02-15 21:45:47 +0000
committerNick Burch <nick@apache.org>2018-02-15 21:45:47 +0000
commit31eb52b8ab1f35493fc2a5d7173eb2ffde0c2b2c (patch)
tree2a9f72537f317cb265d3889b3533a3483ddb479f /src/examples/groovy
parente80f53af6effa0e295ffe6df80667fc24c14c883 (diff)
downloadpoi-31eb52b8ab1f35493fc2a5d7173eb2ffde0c2b2c.tar.gz
poi-31eb52b8ab1f35493fc2a5d7173eb2ffde0c2b2c.zip
Commit examples from the JVM Languages page
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1824371 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/examples/groovy')
-rw-r--r--src/examples/groovy/SpreadSheetDemo.groovy17
-rw-r--r--src/examples/groovy/build.gradle26
2 files changed, 43 insertions, 0 deletions
diff --git a/src/examples/groovy/SpreadSheetDemo.groovy b/src/examples/groovy/SpreadSheetDemo.groovy
new file mode 100644
index 0000000000..379cb9f7d3
--- /dev/null
+++ b/src/examples/groovy/SpreadSheetDemo.groovy
@@ -0,0 +1,17 @@
+import org.apache.poi.ss.usermodel.*
+import java.io.File
+
+if (args.length == 0) {
+ println "Use:"
+ println " SpreadSheetDemo [excel-file]"
+ return 1
+}
+
+File f = new File(args[0]);
+WorkbookFactory.create(f,null,true).withCloseable { workbook ->
+ println "Has ${workbook.getNumberOfSheets()} sheets"
+ 0.step workbook.getNumberOfSheets(), 1, { sheetNum ->
+ println "Sheet ${sheetNum} is called ${workbook.getSheetName(sheetNum)}"
+ }
+}
+
diff --git a/src/examples/groovy/build.gradle b/src/examples/groovy/build.gradle
new file mode 100644
index 0000000000..8da2711991
--- /dev/null
+++ b/src/examples/groovy/build.gradle
@@ -0,0 +1,26 @@
+// Add the POI core and OOXML support dependencies into your gradle build,
+// along with all of Groovy so it can run as a standalone script
+apply plugin: 'groovy'
+repositories {
+ mavenCentral()
+}
+dependencies {
+ compile 'org.codehaus.groovy:groovy-all:2.4.13'
+ compile 'org.apache.poi:poi:3.17'
+ compile 'org.apache.poi:poi-ooxml:3.17'
+}
+
+// Our files are in the current directory
+sourceSets {
+ main { groovy { srcDirs = ['.'] } }
+}
+
+// Run out read demo by default
+tasks.withType(JavaExec) {
+ classpath = sourceSets.main.runtimeClasspath
+}
+task runScript(type: JavaExec) {
+ main = "SpreadSheetDemo"
+ args = ["../../../test-data/spreadsheet/Simple.xls"]
+}
+defaultTasks 'runScript'