poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1752769 - in /poi/site: publish/poi-jvm-languages.html src/documentation/content/xdocs/poi-jvm-languages.xml
Date Fri, 15 Jul 2016 04:51:36 GMT
Author: onealj
Date: Fri Jul 15 04:51:35 2016
New Revision: 1752769

URL: http://svn.apache.org/viewvc?rev=1752769&view=rev
Log:
add Scala code example for POI

Modified:
    poi/site/publish/poi-jvm-languages.html
    poi/site/src/documentation/content/xdocs/poi-jvm-languages.xml

Modified: poi/site/publish/poi-jvm-languages.html
URL: http://svn.apache.org/viewvc/poi/site/publish/poi-jvm-languages.html?rev=1752769&r1=1752768&r2=1752769&view=diff
==============================================================================
--- poi/site/publish/poi-jvm-languages.html (original)
+++ poi/site/publish/poi-jvm-languages.html Fri Jul 15 04:51:35 2016
@@ -291,39 +291,38 @@ if (VERSION > 3) {
 <div class="h3">
 <h3>Jython example</h3>
 </div>
-      
-	
+    
 <pre class="code"> <!-- lang="python" -->
-        # Add <a href="overview.html#components">poi jars</a> onto the python
classpath or add them at run time
-        import sys
-        for jar in ('poi', 'poi-ooxml', 'poi-ooxml-schemas'):
-            sys.path.append('/path/to/%s-3.14-20160307.jar')
-
-        # Import the POI classes
-        from org.apache.poi.ss.usermodel import <a href="https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/WorkbookFactory.html">WorkbookFactory</a>,
<a href="https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/DataFormatter.html">DataFormatter</a>
-
-        # Read the contents of the workbook
-	wb = XSSFWorkbook('<a href="https://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/SampleSS.xlsx">SampleSS.xlsx</a>')
-        formatter = DataFormatter()
-        for i, sheet in enumerate(wb, start=1):
-            print('Sheet %d of %d: %s'.format(i, wb.numberOfSheets, sheet.sheetName))
-            for row in sheet:
-                print('\tRow %i' % row.rowNum)
-                for cell in row:
-                    print('\t\t%s: %s' % (cell.address, formatter.formatCellValue(cell)))
-
-        # Modify the workbook
-        sh = wb.createSheet('new sheet')
-        row = sh.createRow(7)
-        cell = sh.createCell(42)
-        cell.activeCell = True
-        cell.cellValue = 'The answer to life, the universe, and everything'
-
-        # Save and close the workbook
-        from java.io import FileOutputStream
-        fos = FileOutputStream('SampleSS-saved.xlsx')
-        wb.write(fos)
-        wb.close()
+    # Add <a href="overview.html#components">poi jars</a> onto the python classpath
or add them at run time
+    import sys
+    for jar in ('poi', 'poi-ooxml', 'poi-ooxml-schemas'):
+        sys.path.append('/path/to/%s-3.14-20160307.jar')
+
+    # Import the POI classes
+    from org.apache.poi.ss.usermodel import <a href="https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/WorkbookFactory.html">WorkbookFactory</a>,
<a href="https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/DataFormatter.html">DataFormatter</a>
+
+    # Read the contents of the workbook
+    wb = XSSFWorkbook('<a href="https://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/SampleSS.xlsx">SampleSS.xlsx</a>')
+    formatter = DataFormatter()
+    for i, sheet in enumerate(wb, start=1):
+        print('Sheet %d of %d: %s'.format(i, wb.numberOfSheets, sheet.sheetName))
+        for row in sheet:
+            print('\tRow %i' % row.rowNum)
+            for cell in row:
+                print('\t\t%s: %s' % (cell.address, formatter.formatCellValue(cell)))
+
+    # Modify the workbook
+    sh = wb.createSheet('new sheet')
+    row = sh.createRow(7)
+    cell = sh.createCell(42)
+    cell.activeCell = True
+    cell.cellValue = 'The answer to life, the universe, and everything'
+
+    # Save and close the workbook
+    from java.io import FileOutputStream
+    fos = FileOutputStream('SampleSS-saved.xlsx')
+    wb.write(fos)
+    wb.close()
       </pre>
       
 <p>There are several websites that have examples of using Apache POI in Jython projects:
@@ -331,6 +330,75 @@ if (VERSION > 3) {
         <a href="http://www.jython.org/jythonbook/en/1.0/appendixB.html#working-with-spreadsheets">jython.org</a>,
and many others.
       </p>
     
+    
+    
+<a name="Scala+example"></a>
+<div class="h3">
+<h3>Scala example</h3>
+</div>
+    
+<a name="build.sbt"></a>
+<div class="h4">
+<h4>build.sbt</h4>
+</div>
+      
+<pre class="code"> <!-- lang="scala" -->
+    // Add the POI core and OOXML support dependencies into your build.sbt
+    libraryDependencies ++= Seq(
+      "org.apache.poi" % "poi" % "3.15-beta2",
+      "org.apache.poi" % "poi-ooxml" % "3.15-beta2",
+      "org.apache.poi" % "poi-ooxml-schemas" "3.15-beta2"
+    )
+      </pre>
+    
+    
+<a name="XSSFMain.scala"></a>
+<div class="h4">
+<h4>XSSFMain.scala</h4>
+</div>
+      
+<pre class="code"> <!-- lang="scala" -->
+    // Import the required classes
+    import org.apache.poi.xssf.usermodel.XSSFWorkbook
+    import java.io.FileOutputStream
+
+    object XSSFMain extends App {
+
+        // Automatically convert Java collections to Scala equivalents
+        import scala.collection.JavaConversions._
+
+        // Read the contents of the workbook
+        val workbook = new XSSFWorkbook("SampleSS.xlsx")
+        for {
+            // Iterate and print the sheets
+            (sheet, i) &lt;- workbook.zipWithIndex
+            _ = println(s"Sheet $i of ${workbook.getNumberOfSheets}: ${sheet.getSheetName}")
+
+            // Iterate and print the rows
+            row &lt;- sheet
+            _ = println(s"\tRow ${row.getRowNum}")
+
+            // Iterate and print the cells
+            cell &lt;- row
+        } {
+            println(s"\t\t${cell.getColumnIndex}: ${cell.getStringCellValue}")
+        }
+
+        // Add a sheet to the workbook
+        val sheet = workbook.createSheet("new sheet")
+        val row = sheet.createRow(7)
+        val cell = row.createCell(42)
+        cell.setAsActiveCell()
+        cell.setCellValue("The answer to life, the universe, and everything")
+
+        // Save the updated workbook as a new file
+        val fos = new FileOutputStream("UpdatedSampleSS.xlsx")
+        workbook.write(fos)
+        workbook.close()
+    }
+      </pre>
+    
+    
   
   
 

Modified: poi/site/src/documentation/content/xdocs/poi-jvm-languages.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/poi-jvm-languages.xml?rev=1752769&r1=1752768&r2=1752769&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/poi-jvm-languages.xml (original)
+++ poi/site/src/documentation/content/xdocs/poi-jvm-languages.xml Fri Jul 15 04:51:35 2016
@@ -45,45 +45,99 @@
     </section>
 
 
-    <section>
-      <title>Jython example</title>
-	<source> <!-- lang="python" -->
-        # Add <link href="overview.html#components">poi jars</link> onto the
python classpath or add them at run time
-        import sys
-        for jar in ('poi', 'poi-ooxml', 'poi-ooxml-schemas'):
-            sys.path.append('/path/to/%s-3.14-20160307.jar')
-
-        # Import the POI classes
-        from org.apache.poi.ss.usermodel import <link href="https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/WorkbookFactory.html">WorkbookFactory</link>,
<link href="https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/DataFormatter.html">DataFormatter</link>
-
-        # Read the contents of the workbook
-	wb = XSSFWorkbook('<link href="https://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/SampleSS.xlsx">SampleSS.xlsx</link>')
-        formatter = DataFormatter()
-        for i, sheet in enumerate(wb, start=1):
-            print('Sheet %d of %d: %s'.format(i, wb.numberOfSheets, sheet.sheetName))
-            for row in sheet:
-                print('\tRow %i' % row.rowNum)
-                for cell in row:
-                    print('\t\t%s: %s' % (cell.address, formatter.formatCellValue(cell)))
-
-        # Modify the workbook
-        sh = wb.createSheet('new sheet')
-        row = sh.createRow(7)
-        cell = sh.createCell(42)
-        cell.activeCell = True
-        cell.cellValue = 'The answer to life, the universe, and everything'
-
-        # Save and close the workbook
-        from java.io import FileOutputStream
-        fos = FileOutputStream('SampleSS-saved.xlsx')
-        wb.write(fos)
-        wb.close()
+    <section><title>Jython example</title>
+    <source> <!-- lang="python" -->
+    # Add <link href="overview.html#components">poi jars</link> onto the python
classpath or add them at run time
+    import sys
+    for jar in ('poi', 'poi-ooxml', 'poi-ooxml-schemas'):
+        sys.path.append('/path/to/%s-3.14-20160307.jar')
+
+    # Import the POI classes
+    from org.apache.poi.ss.usermodel import <link href="https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/WorkbookFactory.html">WorkbookFactory</link>,
<link href="https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/DataFormatter.html">DataFormatter</link>
+
+    # Read the contents of the workbook
+    wb = XSSFWorkbook('<link href="https://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/SampleSS.xlsx">SampleSS.xlsx</link>')
+    formatter = DataFormatter()
+    for i, sheet in enumerate(wb, start=1):
+        print('Sheet %d of %d: %s'.format(i, wb.numberOfSheets, sheet.sheetName))
+        for row in sheet:
+            print('\tRow %i' % row.rowNum)
+            for cell in row:
+                print('\t\t%s: %s' % (cell.address, formatter.formatCellValue(cell)))
+
+    # Modify the workbook
+    sh = wb.createSheet('new sheet')
+    row = sh.createRow(7)
+    cell = sh.createCell(42)
+    cell.activeCell = True
+    cell.cellValue = 'The answer to life, the universe, and everything'
+
+    # Save and close the workbook
+    from java.io import FileOutputStream
+    fos = FileOutputStream('SampleSS-saved.xlsx')
+    wb.write(fos)
+    wb.close()
       </source>
       <p>There are several websites that have examples of using Apache POI in Jython
projects:
         <link href="https://wiki.python.org/jython/PoiExample">python.org</link>,

         <link href="http://www.jython.org/jythonbook/en/1.0/appendixB.html#working-with-spreadsheets">jython.org</link>,
and many others.
       </p>
     </section>
+    
+    <section><title>Scala example</title>
+    <section><title>build.sbt</title>
+      <source> <!-- lang="scala" -->
+    // Add the POI core and OOXML support dependencies into your build.sbt
+    libraryDependencies ++= Seq(
+      "org.apache.poi" % "poi" % "3.15-beta2",
+      "org.apache.poi" % "poi-ooxml" % "3.15-beta2",
+      "org.apache.poi" % "poi-ooxml-schemas" "3.15-beta2"
+    )
+      </source>
+    </section>
+    <section><title>XSSFMain.scala</title>
+      <source> <!-- lang="scala" -->
+    // Import the required classes
+    import org.apache.poi.xssf.usermodel.XSSFWorkbook
+    import java.io.FileOutputStream
+
+    object XSSFMain extends App {
+
+        // Automatically convert Java collections to Scala equivalents
+        import scala.collection.JavaConversions._
+
+        // Read the contents of the workbook
+        val workbook = new XSSFWorkbook("SampleSS.xlsx")
+        for {
+            // Iterate and print the sheets
+            (sheet, i) &lt;- workbook.zipWithIndex
+            _ = println(s"Sheet $i of ${workbook.getNumberOfSheets}: ${sheet.getSheetName}")
+
+            // Iterate and print the rows
+            row &lt;- sheet
+            _ = println(s"\tRow ${row.getRowNum}")
+
+            // Iterate and print the cells
+            cell &lt;- row
+        } {
+            println(s"\t\t${cell.getColumnIndex}: ${cell.getStringCellValue}")
+        }
+
+        // Add a sheet to the workbook
+        val sheet = workbook.createSheet("new sheet")
+        val row = sheet.createRow(7)
+        val cell = row.createCell(42)
+        cell.setAsActiveCell()
+        cell.setCellValue("The answer to life, the universe, and everything")
+
+        // Save the updated workbook as a new file
+        val fos = new FileOutputStream("UpdatedSampleSS.xlsx")
+        workbook.write(fos)
+        workbook.close()
+    }
+      </source>
+    </section>
+    </section>
   </body>
   <footer>
     <legal>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message