Skip to content

Commit

Permalink
Refs #3 - doc update.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbmarcum committed Jul 4, 2020
1 parent 13aa5e3 commit 8fe424f
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 6 deletions.
31 changes: 29 additions & 2 deletions docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ If you start OpenOffice from the command line you can see stdout and stderr mess
The best way to explain the differences between the Java UNO API's and using Groovy with and without the extension is with some example code. Many of the examples are spreadsheet examples are from SCalc.java that is included with the AOO SDK.

=== Import Statement
To use the UnoExtension you need to add to your imports section
.Add the UnoExtension to imports
[source, groovy]
----
Expand Down Expand Up @@ -219,7 +220,7 @@ See below for an even faster method to set Cell Properties.
The GUNO Extension adds a method to XSpreadsheetDocument that returns the XSpreadsheet by the index position saving the steps of getting the XIndexAccess enumeration of sheets and then getting the sheet by index. Likewise there is a method that uses the sheet name to get the sheet. `XSpreadsheet getSheetByIndex(Integer nIndex)` and
`XSpreadsheet getSheetByName(String name)`.

The example leaves out the try/catch for brevity and assumes we have a reference to XSpreadsheetDocument _myDoc_
The example leaves out the try/catch for brevity and assumes we have a reference to XSpreadsheetDocument `myDoc`

.Java
[source,java]
Expand All @@ -237,6 +238,32 @@ XSpreadsheet xSheet = myDoc.getSheetByIndex(0)

From this point on, the examples are Groovy without and then with the GUNO Extension.

=== Index Access
The GUNO Extension adds a special `getAt(int index)` method to XIndexAccess that allows the Groovy Subscript operator to be used.

This first example will ignore that we already have a method to get a sheet by index from a spreadsheet document to highlight the the Subscript operator with XIndexAccess `xIndexAccess[0]` instead of `xIndexAccess.getByIndex(0)`.

Example: Set the active sheet.

.With Extension (begin with an XSpreadsheetDocument `xSpreadsheetDocument` reference)
----
XSpreadsheets xSheets = xSpreadsheetDocument.sheets
XIndexAccess xIndexAccess = xSheets.guno(XIndexAccess.class)
xSheet = xIndexAccess[0].guno(XSpreadsheet.class)
XController xController = xModel.currentController
XSpreadsheetView xSpreadsheetView = xController.guno(XSpreadsheetView.class)
xSpreadsheetView.activeSheet = xSheet
----

.GUNO Extension (shorter version)
----
xSheet = xSpreadsheetDocument.getSheetByIndex(0)
XController xController = xModel.currentController
XSpreadsheetView xSpreadsheetView = xController.guno(XSpreadsheetView.class)
xSpreadsheetView.activeSheet = xSheet
----


=== Cell Contents
The GUNO Extension adds getters and setters for cell Formulas (text) and Values (numeric) to XCellRange. This allows you to get or set the contents of a cell by it's position in a XCellRange, XSheetCellRange, or XSpreadsheet depending on which Interface you use. +
The methods are: +
Expand Down Expand Up @@ -393,7 +420,7 @@ com.sun.star.container.XEnumerationAccess xCellsEA = xRangeCont.getCells()
com.sun.star.container.XEnumeration xEnum = xCellsEA.createEnumeration()
while (xEnum.hasMoreElements()) {
Object aCellObj = xEnum.nextElement()
xCell = (XCell)UnoRuntime.queryInterface(XCell.class, aCellObj);
xCell = UnoRuntime.queryInterface(XCell.class, aCellObj);
com.sun.star.sheet.XCellAddressable xAddr = UnoRuntime.queryInterface(com.sun.star.sheet.XCellAddressable.class, aCellObj)
com.sun.star.table.CellAddress cellAddress = xAddr.getCellAddress()
println("Formula cell in column ${cellAddress.Column}, row ${cellAddress.Row} contains ${xCell.formula}")
Expand Down
44 changes: 40 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ <h1>GUNO Extension Documentation</h1>
<li><a href="#trueunoruntime-queryinterface">UnoRuntime.queryInterface</a></li>
<li><a href="#trueproperty-access-2">Property Access</a></li>
<li><a href="#truespreadsheet-by-index-and-name">Spreadsheet By Index and Name</a></li>
<li><a href="#trueindex-access">Index Access</a></li>
<li><a href="#truecell-contents">Cell Contents</a></li>
<li><a href="#truecell-address">Cell Address</a></li>
<li><a href="#truecell-style">Cell Style</a></li>
Expand Down Expand Up @@ -677,8 +678,11 @@ <h2 id="trueusing-the-extension"><a class="anchor" href="#trueusing-the-extensio
</div>
<div class="sect2">
<h3 id="trueimport-statement"><a class="anchor" href="#trueimport-statement"></a>Import Statement</h3>
<div class="paragraph">
<p>To use the UnoExtension you need to add to your imports section
.Add the UnoExtension to imports</p>
</div>
<div class="listingblock">
<div class="title">Add the UnoExtension to imports</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="groovy" class="language-groovy hljs">import org.openoffice.guno.UnoExtension</code></pre>
</div>
Expand Down Expand Up @@ -790,7 +794,7 @@ <h3 id="truespreadsheet-by-index-and-name"><a class="anchor" href="#truespreadsh
<code>XSpreadsheet getSheetByName(String name)</code>.</p>
</div>
<div class="paragraph">
<p>The example leaves out the try/catch for brevity and assumes we have a reference to XSpreadsheetDocument <em>myDoc</em></p>
<p>The example leaves out the try/catch for brevity and assumes we have a reference to XSpreadsheetDocument <code>myDoc</code></p>
</div>
<div class="listingblock">
<div class="title">Java</div>
Expand All @@ -811,6 +815,38 @@ <h3 id="truespreadsheet-by-index-and-name"><a class="anchor" href="#truespreadsh
</div>
</div>
<div class="sect2">
<h3 id="trueindex-access"><a class="anchor" href="#trueindex-access"></a>Index Access</h3>
<div class="paragraph">
<p>The GUNO Extension adds a special <code>getAt(int index)</code> method to XIndexAccess that allows the Groovy Subscript operator to be used.</p>
</div>
<div class="paragraph">
<p>This first example will ignore that we already have a method to get a sheet by index from a spreadsheet document to highlight the the Subscript operator with XIndexAccess <code>xIndexAccess[0]</code> instead of <code>xIndexAccess.getByIndex(0)</code>.</p>
</div>
<div class="paragraph">
<p>Example: Set the active sheet.</p>
</div>
<div class="listingblock">
<div class="title">With Extension (begin with an XSpreadsheetDocument <code>xSpreadsheetDocument</code> reference)</div>
<div class="content">
<pre>XSpreadsheets xSheets = xSpreadsheetDocument.sheets
XIndexAccess xIndexAccess = xSheets.guno(XIndexAccess.class)
xSheet = xIndexAccess[0].guno(XSpreadsheet.class)
XController xController = xModel.currentController
XSpreadsheetView xSpreadsheetView = xController.guno(XSpreadsheetView.class)
xSpreadsheetView.activeSheet = xSheet</pre>
</div>
</div>
<div class="listingblock">
<div class="title">GUNO Extension (shorter version)</div>
<div class="content">
<pre>xSheet = xSpreadsheetDocument.getSheetByIndex(0)
XController xController = xModel.currentController
XSpreadsheetView xSpreadsheetView = xController.guno(XSpreadsheetView.class)
xSpreadsheetView.activeSheet = xSheet</pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="truecell-contents"><a class="anchor" href="#truecell-contents"></a>Cell Contents</h3>
<div class="paragraph">
<p>The GUNO Extension adds getters and setters for cell Formulas (text) and Values (numeric) to XCellRange. This allows you to get or set the contents of a cell by it&#8217;s position in a XCellRange, XSheetCellRange, or XSpreadsheet depending on which Interface you use.<br>
Expand Down Expand Up @@ -992,7 +1028,7 @@ <h3 id="truerangecontainer"><a class="anchor" href="#truerangecontainer"></a>Ran
com.sun.star.container.XEnumeration xEnum = xCellsEA.createEnumeration()
while (xEnum.hasMoreElements()) {
Object aCellObj = xEnum.nextElement()
xCell = (XCell)UnoRuntime.queryInterface(XCell.class, aCellObj);
xCell = UnoRuntime.queryInterface(XCell.class, aCellObj);
com.sun.star.sheet.XCellAddressable xAddr = UnoRuntime.queryInterface(com.sun.star.sheet.XCellAddressable.class, aCellObj)
com.sun.star.table.CellAddress cellAddress = xAddr.getCellAddress()
println("Formula cell in column ${cellAddress.Column}, row ${cellAddress.Row} contains ${xCell.formula}")
Expand Down Expand Up @@ -1021,7 +1057,7 @@ <h3 id="truerangecontainer"><a class="anchor" href="#truerangecontainer"></a>Ran
</div>
<div id="footer">
<div id="footer-text">
Last updated 2020-07-03 17:41:29 -0400
Last updated 2020-07-04 15:36:34 -0400
</div>
</div>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/github.min.css">
Expand Down

0 comments on commit 8fe424f

Please sign in to comment.