You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by on...@apache.org on 2016/07/15 16:59:39 UTC
svn commit: r1752852 -
/poi/site/src/documentation/content/xdocs/poi-jvm-languages.xml
Author: onealj
Date: Fri Jul 15 16:59:39 2016
New Revision: 1752852
URL: http://svn.apache.org/viewvc?rev=1752852&view=rev
Log:
add Java code example to assist with JVM language translations
Modified:
poi/site/src/documentation/content/xdocs/poi-jvm-languages.xml
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=1752852&r1=1752851&r2=1752852&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 16:59:39 2016
@@ -51,6 +51,54 @@
<p>Please let us know if you use POI in an environment not listed here</p>
</section>
+ <section><title>Java code</title>
+ <source>
+ // include poi-{version}-{yyyymmdd}.jar, poi-ooxml-{version}-{yyyymmdd}.jar, and poi-ooxml-schemas-{version}-{yyyymmdd}.jar on Java classpath
+ </source>
+
+ <section><title>POILanguageExample.java</title>
+ <source> <!-- lang="java" -->
+ // Import the POI classes
+ import java.io.File;
+ import java.io.FileOutputStream;
+ import java.io.OutputStream;
+ import org.apache.poi.ss.usermodel.Cell;
+ import org.apache.poi.ss.usermodel.Row;
+ import org.apache.poi.ss.usermodel.Sheet;
+ import org.apache.poi.ss.usermodel.Workbook;
+ import org.apache.poi.ss.usermodel.WorkbookFactory;
+ import org.apache.poi.ss.usermodel.DataFormatter;
+
+ // Read the contents of the workbook
+ File f = new File("SampleSS.xlsx");
+ Workbook wb = WorkbookFactory.create(f);
+ DataFormatter formatter = new DataFormatter();
+ int i = 1;
+ int numberOfSheets = wb.getNumberOfSheets();
+ for ( Sheet sheet : wb ) {
+ System.out.println("Sheet " + i + " of " + numberOfSheets + ": " + sheet.getSheetName());
+ for ( Row row : sheet ) {
+ System.out.println("\tRow " + row.getRowNum());
+ for ( Cell cell : row ) {
+ System.out.println("\t\t"+ cell.getAddress().formatAsString() + ": " + formatter.formatCellValue(cell));
+ }
+ }
+ }
+
+ // Modify the workbook
+ Sheet sh = wb.createSheet("new sheet");
+ Row row = sh.createRow(7);
+ Cell cell = row.createCell(42);
+ cell.setActiveCell(true);
+ cell.setCellValue("The answer to life, the universe, and everything");
+
+ // Save and close the workbook
+ OutputStream fos = FileOutputStream("SampleSS-updated.xlsx");
+ wb.write(fos);
+ fos.close();
+ </source>
+ </section> <!-- POILanguageExample.java -->
+ </section> <!-- Java code -->
<section><title>Jython example</title>
<source> <!-- lang="python" -->
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org