summaryrefslogtreecommitdiffstats
path: root/odk/examples/java/Spreadsheet
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /odk/examples/java/Spreadsheet
parentInitial commit. (diff)
downloadlibreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz
libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'odk/examples/java/Spreadsheet')
-rw-r--r--odk/examples/java/Spreadsheet/CalcAddins.components9
-rw-r--r--odk/examples/java/Spreadsheet/CalcAddins.java283
-rw-r--r--odk/examples/java/Spreadsheet/CalcAddins.odsbin0 -> 8653 bytes
-rw-r--r--odk/examples/java/Spreadsheet/ChartTypeChange.java347
-rw-r--r--odk/examples/java/Spreadsheet/EuroAdaption.java383
-rw-r--r--odk/examples/java/Spreadsheet/Makefile209
-rw-r--r--odk/examples/java/Spreadsheet/SCalc.java408
-rw-r--r--odk/examples/java/Spreadsheet/XCalcAddins.idl103
-rw-r--r--odk/examples/java/Spreadsheet/description.xml15
9 files changed, 1757 insertions, 0 deletions
diff --git a/odk/examples/java/Spreadsheet/CalcAddins.components b/odk/examples/java/Spreadsheet/CalcAddins.components
new file mode 100644
index 000000000..c16c4a3a9
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/CalcAddins.components
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<components xmlns="http://openoffice.org/2010/uno-components">
+ <component loader="com.sun.star.loader.Java2" uri="CalcAddins.uno.jar">
+ <implementation name="CalcAddins$_CalcAddins">
+ <service name="org.openoffice.sheet.addin.CalcAddins"/>
+ <service name="com.sun.star.sheet.AddIn"/>
+ </implementation>
+ </component>
+</components>
diff --git a/odk/examples/java/Spreadsheet/CalcAddins.java b/odk/examples/java/Spreadsheet/CalcAddins.java
new file mode 100644
index 000000000..37785056e
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/CalcAddins.java
@@ -0,0 +1,283 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// Template for an Office Calc add-in Java implementation file.
+
+/** You can find more
+ * information on the following web page:
+ * https://api.libreoffice.org/
+ */
+import com.sun.star.comp.loader.FactoryHelper;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XSingleServiceFactory;
+import com.sun.star.registry.XRegistryKey;
+import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XServiceName;
+import com.sun.star.sheet.XAddIn;
+import com.sun.star.lang.Locale;
+import org.openoffice.sheet.addin.XCalcAddins;
+
+/** This outer class provides an inner class to implement the service
+ * description, a method to instantiate the
+ * component on demand (__getServiceFactory()), and a method to give
+ * information about the component (__writeRegistryServiceInfo()).
+ */
+public class CalcAddins {
+
+/** This inner class provides the component as a concrete implementation
+ * of the service description. It implements the needed interfaces.
+ * @implements XCalcAddins, XAddIn, XServiceName, XServiceInfo, XTypeProvider
+ */
+ public static class _CalcAddins extends WeakBase implements
+ XCalcAddins,
+ XAddIn,
+ XServiceName,
+ XServiceInfo
+ {
+
+/** The component will be registered under this name.
+ */
+ private static final String __serviceName = "org.openoffice.sheet.addin.CalcAddins";
+
+ private static final String ADDIN_SERVICE = "com.sun.star.sheet.AddIn";
+
+ private Locale aFuncLoc;
+
+ private static final String[] stringFunctionName = {
+/** TO DO:
+ * You should replace these method names by the method names of your interface.
+ */
+ "getMyFirstValue",
+ "getMySecondValue"
+ };
+
+/** TO DO:
+ * For each of your methods you should make up a new constant with a different value.
+ */
+ private static final short shortGETMYFIRSTVALUE = 0;
+ private static final short shortGETMYSECONDVALUE = 1;
+
+/** TO DO:
+ * This is where you implement all methods of your interface. The parameters have to
+ * be the same as in your IDL file and their types have to be the correct
+ * IDL-to-Java mappings of their types in the IDL file.
+ */
+ public int getMyFirstValue(
+ com.sun.star.beans.XPropertySet xOptions
+ ) {
+ return 1;
+ }
+
+ public int getMySecondValue(
+ com.sun.star.beans.XPropertySet xOptions,
+ int intDummy
+ ) {
+ return 2 + intDummy;
+ }
+
+ // Implement method from interface XServiceName
+ public String getServiceName() {
+ return __serviceName;
+ }
+
+ // Implement methods from interface XServiceInfo
+ public boolean supportsService(String stringServiceName) {
+ return( stringServiceName.equals( ADDIN_SERVICE ) ||
+ stringServiceName.equals( __serviceName ) );
+ }
+
+ public String getImplementationName() {
+ return _CalcAddins.class.getName();
+ }
+
+ public String[] getSupportedServiceNames() {
+ String[] stringSupportedServiceNames = { ADDIN_SERVICE, __serviceName };
+ return stringSupportedServiceNames;
+ }
+
+ // Implement methods from interface XAddIn
+ public String getDisplayArgumentName(String stringProgrammaticFunctionName,int intArgument) {
+ String stringReturn = "";
+
+ switch( this.getFunctionID( stringProgrammaticFunctionName ) ) {
+/** TO DO:
+ * You should list all argument names for each of your methods, here.
+ */
+ case shortGETMYFIRSTVALUE:
+ switch( intArgument ) {
+ case 0:
+ stringReturn = "(internal)";
+ break;
+ }
+ break;
+ case shortGETMYSECONDVALUE:
+ switch( intArgument ) {
+ case 0:
+ stringReturn = "(internal)";
+ break;
+ case 1:
+ stringReturn = "intDummy";
+ break;
+ }
+ break;
+ }
+ return stringReturn;
+ }
+
+ public String getDisplayFunctionName(String stringProgrammaticName) {
+ String stringReturn = "";
+
+ switch( this.getFunctionID( stringProgrammaticName ) ) {
+/** TO DO:
+ * Assign the name of each of your methods.
+ */
+ case shortGETMYFIRSTVALUE:
+ stringReturn = "getMyFirstValue";
+ break;
+ case shortGETMYSECONDVALUE:
+ stringReturn = "getMySecondValue";
+ break;
+ }
+
+ return stringReturn;
+ }
+
+ public String getProgrammaticCategoryName(String p1) {
+ return "Add-In";
+ }
+
+ public String getDisplayCategoryName(String p1) {
+ return "Add-In";
+ }
+
+ public String getFunctionDescription(String stringProgrammaticName) {
+ String stringReturn = "";
+
+ switch( this.getFunctionID( stringProgrammaticName ) ) {
+/** TO DO:
+ * Enter a description for each of your methods that office users will understand.
+ */
+ case shortGETMYFIRSTVALUE:
+ stringReturn = "This is your first method.";
+ break;
+ case shortGETMYSECONDVALUE:
+ stringReturn = "This is your second method.";
+ break;
+ }
+
+ return stringReturn;
+ }
+
+ public String getArgumentDescription(String stringProgrammaticFunctionName,int intArgument) {
+ String stringReturn = "";
+
+ switch( this.getFunctionID( stringProgrammaticFunctionName ) ) {
+/** TO DO:
+ * Enter a description for every argument of every method. Make them so that office users will understand.
+ */
+ case shortGETMYFIRSTVALUE:
+ switch( intArgument ) {
+ case 0:
+ stringReturn = "(internal)";
+ break;
+ }
+ break;
+ case shortGETMYSECONDVALUE:
+ switch( intArgument ) {
+ case 0:
+ stringReturn = "(internal)";
+ break;
+ case 1:
+ stringReturn = "You can add this value.";
+ break;
+ }
+ break;
+ }
+ return stringReturn;
+ }
+
+ public String getProgrammaticFuntionName(String p1) {
+ return "";
+ }
+
+ // Implement methods from interface XLocalizable
+ public Locale getLocale() {
+ return aFuncLoc;
+ }
+
+ public void setLocale(Locale p1) {
+ aFuncLoc = p1;
+ }
+
+ // Auxiliary functions
+ private short getFunctionID( String stringProgrammaticName ) {
+ for ( int i = 0; i < stringFunctionName.length; i++ ) {
+ if ( stringProgrammaticName.equals( stringFunctionName[ i ] ) ) {
+ return ( short ) i;
+ }
+ }
+
+ return -1;
+ }
+ }
+
+ /**
+ * Returns a factory for creating the service.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns a <code>XSingleServiceFactory</code> for creating the component
+ * @param implName the name of the implementation for which a service is desired
+ * @param multiFactory the service manager to be used if needed
+ * @param regKey the registryKey
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleServiceFactory __getServiceFactory(String implName,
+ XMultiServiceFactory multiFactory,
+ XRegistryKey regKey) {
+ XSingleServiceFactory xSingleServiceFactory = null;
+
+ if (implName.equals(_CalcAddins.class.getName()) )
+ xSingleServiceFactory = FactoryHelper.getServiceFactory(_CalcAddins.class,
+ _CalcAddins.__serviceName,
+ multiFactory,
+ regKey);
+
+ return xSingleServiceFactory;
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Spreadsheet/CalcAddins.ods b/odk/examples/java/Spreadsheet/CalcAddins.ods
new file mode 100644
index 000000000..133539d5a
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/CalcAddins.ods
Binary files differ
diff --git a/odk/examples/java/Spreadsheet/ChartTypeChange.java b/odk/examples/java/Spreadsheet/ChartTypeChange.java
new file mode 100644
index 000000000..d436b3889
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/ChartTypeChange.java
@@ -0,0 +1,347 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+import com.sun.star.awt.Rectangle;
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.XPropertySet;
+
+import com.sun.star.chart.XDiagram;
+import com.sun.star.chart.XChartDocument;
+
+import com.sun.star.container.XNameAccess;
+import com.sun.star.container.XIndexAccess;
+
+import com.sun.star.document.XEmbeddedObjectSupplier;
+
+import com.sun.star.frame.XComponentLoader;
+
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XMultiComponentFactory;
+
+import com.sun.star.sheet.XSpreadsheets;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.sheet.XCellRangeAddressable;
+
+import com.sun.star.table.XTableChart;
+import com.sun.star.table.XTableCharts;
+import com.sun.star.table.XCell;
+import com.sun.star.table.XCellRange;
+import com.sun.star.table.XTableChartsSupplier;
+import com.sun.star.table.CellRangeAddress;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+import com.sun.star.uno.XComponentContext;
+
+
+
+/** This class loads an OpenOffice.org Calc document and changes the type of the
+ * embedded chart.
+ */
+public class ChartTypeChange {
+
+ /** Table chart, which type will be changed.
+ */
+ private XTableChart xtablechart = null;
+
+ /** Service factory
+ */
+ private final XMultiComponentFactory xMCF;
+
+ /** Component context
+ */
+ private final XComponentContext xCompContext;
+
+ /** Beginning of the program.
+ * @param args No arguments will be passed to the class.
+ */
+ public static void main(String args[]) {
+ try {
+ ChartTypeChange charttypechange = new ChartTypeChange();
+
+ // Double array holding all values the chart should be based on.
+ String[][] stringValues = {
+ { "", "Jan", "Feb", "Mar", "Apr", "Mai" },
+ { "Profit", "12.3", "43.2", "5.1", "76", "56.8" },
+ { "Rival in business", "12.2", "12.6", "17.7", "20.4", "100" },
+ };
+
+ // Create the chart with
+ charttypechange.getChart( stringValues );
+
+ String[] stringChartType = {
+ "com.sun.star.chart.LineDiagram",
+ "com.sun.star.chart.BarDiagram",
+ "com.sun.star.chart.PieDiagram",
+ "com.sun.star.chart.NetDiagram",
+ "com.sun.star.chart.XYDiagram",
+ "com.sun.star.chart.StockDiagram",
+ "com.sun.star.chart.AreaDiagram"
+ };
+
+ for ( int intCounter = 0; intCounter < stringChartType.length;
+ intCounter++ ) {
+ charttypechange.changeChartType( stringChartType[ intCounter ],
+ false );
+ Thread.sleep( 3000 );
+ }
+
+ System.exit(0);
+ }
+ catch( Exception exception ) {
+ System.err.println( exception );
+ }
+ }
+
+ /** The constructor connects to the OpenOffice.org.
+ * @throws Exception All exceptions are thrown from this method.
+ */
+ public ChartTypeChange()
+ throws Exception {
+
+ /* Bootstraps a component context. Component context to be granted
+ to a component for running. Arbitrary values can be retrieved
+ from the context. */
+ xCompContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+
+ /* Gets the service manager instance to be used (or null). This method has
+ been added for convenience, because the service manager is an often used
+ object. */
+ xMCF = xCompContext.getServiceManager();
+ }
+
+ /** This method will change the type of a specified chart.
+ * @param stringType The chart will be converted to this type.
+ * @param booleanIs3D If the chart should be displayed in 3D this parameter should be set to true.
+ * @throws Exception All exceptions are thrown from this method.
+ */
+ public void changeChartType( String stringType, boolean booleanIs3D )
+ throws Exception {
+ XEmbeddedObjectSupplier xEmbeddedObjSupplier = UnoRuntime.queryInterface(XEmbeddedObjectSupplier.class, xtablechart);
+ XInterface xInterface = xEmbeddedObjSupplier.getEmbeddedObject();
+
+ XChartDocument xChartDoc = UnoRuntime.queryInterface(
+ XChartDocument.class, xInterface);
+ XDiagram xDiagram = xChartDoc.getDiagram();
+ XMultiServiceFactory xMSF = UnoRuntime.queryInterface( XMultiServiceFactory.class, xChartDoc );
+ Object object = xMSF.createInstance( stringType );
+ xDiagram = UnoRuntime.queryInterface(XDiagram.class, object);
+
+ XPropertySet xPropSet = UnoRuntime.queryInterface(
+ XPropertySet.class, xDiagram );
+ xPropSet.setPropertyValue( "Dim3D", Boolean.valueOf( booleanIs3D ) );
+
+ xChartDoc.setDiagram(xDiagram);
+ }
+
+ /** Loading an OpenOffice.org Calc document and getting a chart by name.
+ * @param stringFileName Name of the OpenOffice.org Calc document which should
+ * be loaded.
+ * @param stringChartName Name of the chart which should get a new chart type.
+ */
+ public void getChart( String stringFileName, String stringChartName ) {
+ try {
+ /* A desktop environment contains tasks with one or more
+ frames in which components can be loaded. Desktop is the
+ environment for components which can instantiate within
+ frames. */
+ XComponentLoader xComponentloader = UnoRuntime.queryInterface( XComponentLoader.class,
+ xMCF.createInstanceWithContext("com.sun.star.frame.Desktop",
+ xCompContext ) );
+
+ // Load a Writer document, which will be automatically displayed
+ XComponent xComponent = xComponentloader.loadComponentFromURL(
+ "file:///" + stringFileName, "_blank", 0,
+ new PropertyValue[0] );
+
+ // Query for the interface XSpreadsheetDocument
+ XSpreadsheetDocument xSpreadSheetDocument = UnoRuntime.queryInterface( XSpreadsheetDocument.class, xComponent );
+
+ XSpreadsheets xSpreadsheets = xSpreadSheetDocument.getSheets() ;
+
+ XIndexAccess xIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets );
+
+ XSpreadsheet xSpreadsheet = UnoRuntime.queryInterface(
+ XSpreadsheet.class, xIndexAccess.getByIndex(0));
+
+ XTableChartsSupplier xTableChartsSupplier = UnoRuntime.queryInterface( XTableChartsSupplier.class, xSpreadsheet );
+
+ xIndexAccess = UnoRuntime.queryInterface(
+ XIndexAccess.class, xTableChartsSupplier.getCharts() );
+
+ this.xtablechart = UnoRuntime.queryInterface(
+ XTableChart.class, xIndexAccess.getByIndex( 0 ) );
+ }
+ catch( Exception exception ) {
+ System.err.println( exception );
+ }
+ }
+
+ /** Creating an empty OpenOffice.org Calc document, inserting data, and getting a
+ * chart by name.
+ * @param stringValues Double array with the values for the chart.
+ */
+ public void getChart( String[][] stringValues ) {
+ try {
+ /* A desktop environment contains tasks with one or more
+ frames in which components can be loaded. Desktop is the
+ environment for components which can instantiate within
+ frames. */
+ XComponentLoader xcomponentloader = UnoRuntime.queryInterface( XComponentLoader.class,
+ xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop",
+ xCompContext ) );
+
+ // Create an empty calc document, which will be automatically displayed
+ XComponent xComponent = xcomponentloader.loadComponentFromURL(
+ "private:factory/scalc", "_blank", 0,
+ new PropertyValue[0] );
+
+ // Query for the interface XSpreadsheetDocument
+ XSpreadsheetDocument xspreadsheetdocument = UnoRuntime.queryInterface( XSpreadsheetDocument.class, xComponent );
+
+ // Get all sheets of the spreadsheet document.
+ XSpreadsheets xspreadsheets = xspreadsheetdocument.getSheets() ;
+
+ // Get the index of the spreadsheet document.
+ XIndexAccess xindexaccess = UnoRuntime.queryInterface(
+ XIndexAccess.class, xspreadsheets );
+
+ // Get the first spreadsheet.
+ XSpreadsheet xspreadsheet = UnoRuntime.queryInterface(
+ XSpreadsheet.class, xindexaccess.getByIndex(0));
+
+ // The double array will written to the spreadsheet
+ for ( int intY = 0; intY < stringValues.length; intY++ ) {
+ for ( int intX = 0; intX < stringValues[ intY ].length;
+ intX++ ) {
+ // Insert the value to the cell, specified by intY and intX.
+ ChartTypeChange.insertIntoCell( intY, intX,
+ stringValues[ intY ][ intX ], xspreadsheet, "" );
+ }
+ }
+
+ // Create a rectangle, which holds the size of the chart.
+ Rectangle rectangle = new Rectangle();
+ rectangle.X = 500;
+ rectangle.Y = 3000;
+ rectangle.Width = 25000;
+ rectangle.Height = 11000;
+
+ // Get the cell range of the spreadsheet.
+ XCellRange xcellrange = UnoRuntime.queryInterface(
+ XCellRange.class, xspreadsheet );
+
+ // Create the Unicode of the character for the column name.
+ char charRectangle = ( char ) ( 65 + stringValues.length - 1 );
+
+ // Get maximum length all rows in the double array.
+ int intMaximumWidthRow = 0;
+ for ( int intRow = 0; intRow < stringValues.length; intRow++ ) {
+ if ( stringValues[ intRow ].length > intMaximumWidthRow ) {
+ intMaximumWidthRow = stringValues[ intRow ].length;
+ }
+ }
+
+ // Get the cell range of the written values.
+ XCellRange xcellrangeChart = xcellrange.getCellRangeByName( "A1:" +
+ charRectangle + intMaximumWidthRow );
+
+ // Get the addressable cell range.
+ XCellRangeAddressable xcellrangeaddressable =
+ UnoRuntime.queryInterface(
+ XCellRangeAddressable.class, xcellrangeChart );
+
+ // Get the cell range address.
+ CellRangeAddress cellrangeaddress = xcellrangeaddressable.getRangeAddress();
+
+ // Create the cell range address for the chart.
+ CellRangeAddress[] cellrangeaddressChart =
+ new CellRangeAddress[ 1 ];
+ cellrangeaddressChart[ 0 ] = cellrangeaddress;
+
+ // Get the table charts supplier of the spreadsheet.
+ XTableChartsSupplier xtablechartssupplier = UnoRuntime.queryInterface( XTableChartsSupplier.class, xspreadsheet );
+
+ // Get all table charts of the spreadsheet.
+ XTableCharts xtablecharts = xtablechartssupplier.getCharts();
+
+ // Create a table chart with all written values.
+ xtablecharts.addNewByName( "Example", rectangle,
+ cellrangeaddressChart, true, true );
+
+ // Get the created table chart.
+ this.xtablechart = UnoRuntime.queryInterface(
+ XTableChart.class, UnoRuntime.queryInterface(
+ XNameAccess.class, xtablecharts ).getByName( "Example" ));
+ }
+ catch( Exception exception ) {
+ System.err.println( exception );
+ }
+ }
+
+ /** Inserting a given value to a cell, that is specified by the parameters intX
+ * and intY.
+ * @param intX Column on the spreadsheet.
+ * @param intY Row on the spreadsheet.
+ * @param stringValue Value to be inserted to a cell.
+ * @param xspreadsheet Spreadsheet of the cell, which will be changed.
+ * @param stringFlag If the value of stringFlag is "V", the stringValue
+ * will be converted to the
+ * float type. Otherwise the stringValue will be written as a formula.
+ */
+ public static void insertIntoCell( int intX, int intY, String stringValue,
+ XSpreadsheet xspreadsheet, String stringFlag )
+ {
+ XCell xcell = null;
+
+ try {
+ xcell = xspreadsheet.getCellByPosition( intX, intY );
+ }
+ catch ( com.sun.star.lang.IndexOutOfBoundsException exception ) {
+ System.out.println( "Could not get cell." );
+ }
+ if ( stringFlag.equals( "V" ) ) {
+ xcell.setValue( ( new Float( stringValue ) ).floatValue() );
+ }
+ else {
+ xcell.setFormula( stringValue );
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Spreadsheet/EuroAdaption.java b/odk/examples/java/Spreadsheet/EuroAdaption.java
new file mode 100644
index 000000000..c6906f45b
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/EuroAdaption.java
@@ -0,0 +1,383 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+// comment: Step 1: get the Desktop object from the office
+// Step 2: open an empty Calc document
+// Step 3: enter an example text, set the numberformat to DM
+// Step 4: change the numberformat to EUR (Euro)
+// Step 5: use the DM/EUR factor on each cell with a content
+
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.XPropertySet;
+
+import com.sun.star.container.XEnumeration;
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.container.XEnumerationAccess;
+
+import com.sun.star.document.XActionLockable;
+
+import com.sun.star.frame.XDesktop;
+import com.sun.star.frame.XComponentLoader;
+
+import com.sun.star.lang.Locale;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiComponentFactory;
+
+import com.sun.star.table.XCell;
+import com.sun.star.table.XCellRange;
+
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheets;
+import com.sun.star.sheet.XSheetCellRanges;
+import com.sun.star.sheet.XCellRangesQuery;
+import com.sun.star.sheet.XCellFormatRangesSupplier;
+import com.sun.star.sheet.XSpreadsheetDocument;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.XComponentContext;
+
+import com.sun.star.util.XNumberFormats;
+import com.sun.star.util.XNumberFormatsSupplier;
+
+
+public class EuroAdaption {
+
+ public static void main(String args[]) {
+ // You need the desktop to create a document
+ // The getDesktop method does the UNO bootstrapping, gets the
+ // remote service manager and the desktop object.
+ com.sun.star.frame.XDesktop xDesktop = null;
+ xDesktop = getDesktop();
+
+ // create a sheet document
+ XSpreadsheetDocument xSheetdocument = null;
+ xSheetdocument = createSheetdocument( xDesktop );
+ System.out.println( "Create a new Spreadsheet" );
+
+ // get the collection of all sheets from the document
+ XSpreadsheets xSheets = null;
+ xSheets = xSheetdocument.getSheets();
+
+ // the Action Interface provides methods to hide actions,
+ // like inserting data, on a sheet, that increase the performance
+ XActionLockable xActionInterface = null;
+ xActionInterface = UnoRuntime.queryInterface(
+ XActionLockable.class, xSheetdocument );
+
+ // lock all actions
+ xActionInterface.addActionLock();
+
+ com.sun.star.sheet.XSpreadsheet xSheet = null;
+ try {
+ // get via the index access the first sheet
+ XIndexAccess xElements = UnoRuntime.queryInterface(
+ XIndexAccess.class, xSheets );
+
+ // specify the first sheet from the spreadsheet
+ xSheet = UnoRuntime.queryInterface(
+ XSpreadsheet.class, xElements.getByIndex( 0 ));
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ // get the interface to apply and create new numberformats
+ XNumberFormatsSupplier xNumberFormatSupplier = null;
+ xNumberFormatSupplier = UnoRuntime.queryInterface(
+ XNumberFormatsSupplier.class, xSheetdocument );
+ XNumberFormats xNumberFormats = null;
+ xNumberFormats = xNumberFormatSupplier.getNumberFormats();
+
+ // insert some example data in a sheet
+ createExampleData( xSheet, xNumberFormats );
+ System.out.println( "Insert example data and use the number format with the currency 'DM'" );
+
+ // Change the currency from the cells from DM to Euro
+ Convert( xSheet, xNumberFormats, "DM", "EUR", 1.95583f );
+ System.out.println( "Change the number format to EUR and divide the values with the factor 1.95583" );
+
+ // remove all locks, the user see all changes
+ xActionInterface.removeActionLock();
+
+ System.out.println("done");
+ System.exit(0);
+ }
+
+
+ public static void Convert( XSpreadsheet xSheet, XNumberFormats xNumberFormats,
+ String sOldSymbol, String sNewSymbol,
+ float fFactor ) {
+ try {
+ Locale xLanguage = new Locale();
+ xLanguage.Country = "de"; // Germany -> DM
+ xLanguage.Language = "de"; // German
+
+ // Numberformat string with sNewSymbol
+ String sSimple = "0 [$" + sNewSymbol + "]";
+ // create a number format key with the sNewSymbol
+ int iSimpleKey = NumberFormat( xNumberFormats, sSimple, xLanguage );
+
+ // you have to use the FormatSupplier interface to get the
+ // CellFormat enumeration
+ XCellFormatRangesSupplier xCellFormatSupplier =
+ UnoRuntime.queryInterface(
+ XCellFormatRangesSupplier.class, xSheet );
+
+ // getCellFormatRanges() has the interfaces for the enumeration
+ XEnumerationAccess xEnumerationAccess =
+ UnoRuntime.queryInterface(
+ XEnumerationAccess.class,
+ xCellFormatSupplier.getCellFormatRanges() );
+
+ XEnumeration xRanges = xEnumerationAccess.createEnumeration();
+
+ while( xRanges.hasMoreElements() ) {
+ // the enumeration returns a cellrange
+ XCellRange xCellRange = UnoRuntime.queryInterface(
+ XCellRange.class, xRanges.nextElement());
+
+ // the PropertySet the get and set the properties from the cellrange
+ XPropertySet xCellProp = UnoRuntime.queryInterface(
+ XPropertySet.class, xCellRange );
+
+ // getPropertyValue returns an Object, you have to cast it to
+ // type that you need
+ Object oNumberObject = xCellProp.getPropertyValue( "NumberFormat" );
+ int iNumberFormat = AnyConverter.toInt(oNumberObject);
+
+ // get the properties from the cellrange numberformat
+ XPropertySet xFormat = xNumberFormats.getByKey(iNumberFormat );
+
+ short fType = AnyConverter.toShort(xFormat.getPropertyValue("Type"));
+ String sCurrencySymbol = AnyConverter.toString(
+ xFormat.getPropertyValue("CurrencySymbol"));
+
+ // change the numberformat only on cellranges with a
+ // currency numberformat
+ if( ( (fType & com.sun.star.util.NumberFormat.CURRENCY) > 0) &&
+ ( sCurrencySymbol.equals( sOldSymbol ) ) ) {
+ boolean bThousandSep = AnyConverter.toBoolean(
+ xFormat.getPropertyValue("ThousandsSeparator"));
+ boolean bNegativeRed = AnyConverter.toBoolean(
+ xFormat.getPropertyValue("NegativeRed"));
+ short fDecimals = AnyConverter.toShort(
+ xFormat.getPropertyValue("Decimals"));
+ short fLeadingZeros = AnyConverter.toShort(
+ xFormat.getPropertyValue("LeadingZeros"));
+ Locale oLocale = (Locale) AnyConverter.toObject(
+ new com.sun.star.uno.Type(Locale.class),
+ xFormat.getPropertyValue("Locale"));
+
+ // create a new numberformat string
+ String sNew = xNumberFormats.generateFormat( iSimpleKey,
+ oLocale, bThousandSep, bNegativeRed,
+ fDecimals, fLeadingZeros );
+
+ // get the NumberKey from the numberformat
+ int iNewNumberFormat = NumberFormat( xNumberFormats,
+ sNew, oLocale );
+
+ // set the new numberformat to the cellrange DM->EUR
+ xCellProp.setPropertyValue( "NumberFormat",
+ Integer.valueOf( iNewNumberFormat ) );
+
+ // iterate over all cells from the cellrange with an
+ // content and use the DM/EUR factor
+ XCellRangesQuery xCellRangesQuery = UnoRuntime.queryInterface(
+ XCellRangesQuery.class, xCellRange );
+
+ XSheetCellRanges xSheetCellRanges =
+ xCellRangesQuery.queryContentCells(
+ (short) com.sun.star.sheet.CellFlags.VALUE );
+
+ if( xSheetCellRanges.getCount() > 0 ) {
+ XEnumerationAccess xCellEnumerationAccess =
+ xSheetCellRanges.getCells();
+ XEnumeration xCellEnumeration =
+ xCellEnumerationAccess.createEnumeration();
+
+ while( xCellEnumeration.hasMoreElements() ) {
+ XCell xCell = UnoRuntime.queryInterface(
+ XCell.class, xCellEnumeration.nextElement());
+ xCell.setValue( xCell.getValue() / fFactor );
+ }
+ }
+ }
+ }
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+ }
+
+
+ public static int NumberFormat( XNumberFormats xNumberFormat, String sFormat,
+ com.sun.star.lang.Locale xLanguage ) {
+ int nRetKey = 0;
+
+ try {
+ // exists the numberformat
+ nRetKey = xNumberFormat.queryKey( sFormat, xLanguage, true );
+
+ // if not, create a new one
+ if( nRetKey == -1 ) {
+ nRetKey = xNumberFormat.addNew( sFormat, xLanguage );
+ if( nRetKey == -1 )
+ nRetKey = 0;
+ }
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return nRetKey;
+ }
+
+
+ public static void createExampleData( XSpreadsheet xSheet,
+ XNumberFormats xNumberFormat ) {
+
+ // enter in a cellrange numbers and change the numberformat to DM
+ XCell xCell = null;
+ XCellRange xCellRange = null;
+
+ try {
+ Locale xLanguage = new Locale();
+ xLanguage.Country = "de"; // Germany -> DM
+ xLanguage.Language = "de"; // German
+
+ // Numberformat string from DM
+ String sSimple = "0 [$DM]";
+
+ // get the numberformat key
+ int iNumberFormatKey = NumberFormat(xNumberFormat, sSimple, xLanguage);
+
+ for( int iCounter=1; iCounter < 10; iCounter++ ) {
+ // get one cell and insert a number
+ xCell = xSheet.getCellByPosition( 2, 1 + iCounter );
+ xCell.setValue( (double) iCounter * 2 );
+ xCellRange = xSheet.getCellRangeByPosition( 2, 1 + iCounter,
+ 2, 1 + iCounter );
+
+ // get the PropertySet from the cell, to change the numberformat
+ XPropertySet xCellProp = UnoRuntime.queryInterface(
+ XPropertySet.class, xCellRange );
+ xCellProp.setPropertyValue( "NumberFormat",
+ Integer.valueOf(iNumberFormatKey) );
+ }
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+ }
+
+ public static XDesktop getDesktop() {
+ XDesktop xDesktop = null;
+ XMultiComponentFactory xMCF = null;
+
+ try {
+ XComponentContext xContext = null;
+
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+
+ // get the remote office service manager
+ xMCF = xContext.getServiceManager();
+ if( xMCF != null ) {
+ System.out.println("Connected to a running office ...");
+
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext);
+ xDesktop = UnoRuntime.queryInterface(
+ XDesktop.class, oDesktop);
+ }
+ else
+ System.out.println( "Can't create a desktop. No connection, no remote servicemanager available!" );
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+
+ return xDesktop;
+ }
+
+
+ public static XSpreadsheetDocument createSheetdocument( XDesktop xDesktop ) {
+ XSpreadsheetDocument aSheetDocument = null;
+
+ try {
+ XComponent xComponent = null;
+ xComponent = CreateNewDocument( xDesktop, "scalc" );
+
+ aSheetDocument = UnoRuntime.queryInterface(
+ XSpreadsheetDocument.class, xComponent);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return aSheetDocument;
+ }
+
+ protected static XComponent CreateNewDocument( XDesktop xDesktop,
+ String sDocumentType ) {
+ String sURL = "private:factory/" + sDocumentType;
+
+ XComponent xComponent = null;
+ XComponentLoader xComponentLoader = null;
+ PropertyValue xEmptyArgs[] = new PropertyValue[0];
+
+ try {
+ xComponentLoader = UnoRuntime.queryInterface(
+ XComponentLoader.class, xDesktop );
+
+ xComponent = xComponentLoader.loadComponentFromURL(
+ sURL, "_blank", 0, xEmptyArgs);
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+ return xComponent ;
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Spreadsheet/Makefile b/odk/examples/java/Spreadsheet/Makefile
new file mode 100644
index 000000000..f4d845be9
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/Makefile
@@ -0,0 +1,209 @@
+#*************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the Java Spreadsheet examples of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+
+# Define non-platform/compiler specific settings
+EXAMPLE_NAME=JavaSpreadsheetExamples
+OUT_COMP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+OUT_COMP_GEN = $(OUT_MISC)/$(EXAMPLE_NAME)
+
+APP1_NAME=EuroAdaption
+APP1_JAR=$(OUT_COMP_CLASS)/$(APP1_NAME).jar
+APP2_NAME=SCalc
+APP2_JAR=$(OUT_COMP_CLASS)/$(APP2_NAME).jar
+APP3_NAME=ChartTypeChange
+APP3_JAR=$(OUT_COMP_CLASS)/$(APP3_NAME).jar
+
+COMP_NAME=CalcAddins
+COMP_RDB_NAME=$(COMP_NAME).uno.rdb
+COMP_RDB=$(OUT_COMP_GEN)/$(COMP_RDB_NAME)
+COMP_PACKAGE=$(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
+COMP_PACKAGE_URL=$(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
+COMP_JAR_NAME=$(COMP_NAME).uno.jar
+COMP_JAR=$(OUT_COMP_CLASS)/$(COMP_JAR_NAME)
+COMP_MANIFESTFILE=$(OUT_COMP_CLASS)/$(COMP_NAME).uno.Manifest
+COMP_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMP_NAME)/META-INF/manifest.xml
+COMP_REGISTERFLAG=$(OUT_MISC)$(PS)java_$(COMP_NAME)_register_component.flag
+COMP_COMPONENTS=$(COMP_NAME).components
+
+IDLFILES = XCalcAddins.idl
+
+# normally the idl file should be stored in a directory tree fitting the module structure,
+# for the example we know the module structure
+PACKAGE = org/openoffice/sheet/addin
+
+COMPJAVAFILES = CalcAddins.java
+
+#GENJAVAFILES = $(patsubst %.idl,$(OUT_COMP_GEN)/$(PACKAGE)/%.java,$(IDLFILES))
+GENCLASSFILES = $(patsubst %.idl,$(OUT_COMP_CLASS)/$(PACKAGE)/%.class,$(IDLFILES))
+GENTYPELIST = $(subst /,.,$(patsubst %.idl,-T$(PACKAGE)/% ,$(IDLFILES)))
+
+COMPCLASSFILES = $(patsubst %.java,$(OUT_COMP_CLASS)/%.class,$(COMPJAVAFILES))
+#COMPCLASSFILES += $(subst $(OUT_COMP_GEN),$(OUT_COMP_CLASS),$(GENJAVAFILES:.java=.class))
+
+$(COMP_NAME)_CLASSFILES = $(COMP_NAME).class \
+ $(COMP_NAME)$(QUOTE)$$_$(COMP_NAME).class
+
+#$(COMP_NAME)_CLASSFILES += $(subst $(OUT_COMP_GEN)/,,$(GENJAVAFILES:.java=.class))
+$(COMP_NAME)_CLASSFILES += $(subst $(OUT_COMP_CLASS)/,,$(GENCLASSFILES))
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_COMP_CLASS))
+
+# Targets
+.PHONY: ALL
+ALL : $(EXAMPLE_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+# rule for a component manifest file
+$(OUT_COMP_CLASS)/%.Manifest :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo UNO-Type-Path: $(basename $*).uno.jar> $@
+ @echo RegistrationClassName: $(basename $*)>> $@
+
+$(OUT_COMP_GEN)/%.rdb : $(IDLFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(UNOIDLWRITE) $(URE_TYPES) $(OFFICE_TYPES) $< $@
+
+#$(OUT_COMP_GEN)/%.java : $(COMP_RDB)
+$(GENCLASSFILES) : $(COMP_RDB)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(JAVAMAKER) -nD $(GENTYPELIST) -O$(OUT_COMP_CLASS) $(COMP_RDB) -X$(URE_TYPES) -X$(OFFICE_TYPES)
+
+$(OUT_COMP_CLASS)/%.class : %.java
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $<
+
+# only the component depends on the generated types
+$(COMPCLASSFILES) : $(JAVAFILES) $(GENCLASSFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $(COMPJAVAFILES)
+
+# rule for client/example application manifest file
+$(OUT_COMP_CLASS)/%.mf :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo Main-Class: com.sun.star.lib.loader.Loader> $@
+ $(ECHOLINE)>> $@
+ @echo Name: com/sun/star/lib/loader/Loader.class>> $@
+ @echo Application-Class: $*>> $@
+
+# rule for client/example application jar file
+$(OUT_COMP_CLASS)/%.jar : $(OUT_COMP_CLASS)/%.mf $(OUT_COMP_CLASS)/%.class
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $*.mf $*.class
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+# rule for component jar file
+$(COMP_JAR) : $(COMP_MANIFESTFILE) $(COMPCLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(<F) $($(basename $(basename $(@F)))_CLASSFILES)
+
+# rule for component package manifest
+$(OUT_COMP_CLASS)/%/manifest.xml :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
+ @echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
+ @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-typelibrary;type=RDB$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_COMP_CLASS)/,,$(@D))).uno.rdb$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components$(QM)">> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(COMP_NAME).components$(QM)"/$(CSEP)>> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMP_PACKAGE) : $(COMP_RDB) $(COMP_JAR) $(COMP_UNOPKG_MANIFEST) $(COMP_NAME).components description.xml
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(COPY) $(subst /,$(PS),$<) $(subst /,$(PS),$(OUT_COMP_CLASS))
+ $(SDK_ZIP) $@ -u $(COMP_NAME).components description.xml
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_ZIP) -u ../../bin/$(@F) $(COMP_RDB_NAME) $(COMP_JAR_NAME)
+ cd $(subst /,$(PS),$(OUT_COMP_CLASS)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
+ $(DEL) $(subst \\,\,$(subst /,$(PS),$(OUT_COMP_CLASS)/$(<F)))
+
+$(COMP_REGISTERFLAG) : $(COMP_PACKAGE)
+ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(DEPLOYTOOL) $(COMP_PACKAGE_URL)
+ @echo flagged > $(subst /,$(PS),$@)
+else
+ @echo --------------------------------------------------------------------------------
+ @echo If you want to install your component automatically, please set the environment
+ @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
+ @echo possible if no office instance is running.
+ @echo --------------------------------------------------------------------------------
+endif
+
+$(APP1_JAR) : $(OUT_COMP_CLASS)/$(APP1_NAME).mf $(OUT_COMP_CLASS)/$(APP1_NAME).class
+$(APP2_JAR) : $(OUT_COMP_CLASS)/$(APP2_NAME).mf $(OUT_COMP_CLASS)/$(APP2_NAME).class
+$(APP3_JAR) : $(OUT_COMP_CLASS)/$(APP3_NAME).mf $(OUT_COMP_CLASS)/$(APP3_NAME).class
+
+$(EXAMPLE_NAME) : $(COMP_REGISTERFLAG) $(APP1_JAR) $(APP2_JAR) $(APP3_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo Please use the following command to execute the examples!
+ @echo -
+ @echo $(MAKE) EuroAdaption.run
+ @echo $(MAKE) SCalc.run
+ @echo $(MAKE) ChartTypeChange.run
+ @echo --------------------------------------------------------------------------------
+ @echo The Calc add-in component was installed if SDK_AUTO_DEPLOYMENT = YES.
+ @echo You can use this component inside your office installation, see the example
+ @echo description. You can also load the "$(QM)CalcAddins.ods$(QM)" document to see
+ @echo how the add-in functions works.
+ @echo -
+ @echo $(MAKE) CalcAddins.ods.load
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_COMP_CLASS)/%.jar
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
+
+CalcAddins.ods.load : $(COMP_REGISTERFLAG)
+ "$(OFFICE_PROGRAM_PATH)$(PS)soffice" $(basename $@)
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_CLASS))
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL)))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_REGISTERFLAG)))
diff --git a/odk/examples/java/Spreadsheet/SCalc.java b/odk/examples/java/Spreadsheet/SCalc.java
new file mode 100644
index 000000000..90c5ce00f
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/SCalc.java
@@ -0,0 +1,408 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+// comment: Step 1: get the remote component context from the office
+// Step 2: open an empty calc document
+// Step 3: create cell styles
+// Step 4: get the sheet an insert some data
+// Step 5: apply the created cell styles
+// Step 6: insert a 3D Chart
+
+
+import com.sun.star.awt.Rectangle;
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.XPropertySet;
+
+import com.sun.star.chart.XDiagram;
+import com.sun.star.chart.XChartDocument;
+
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.container.XNameContainer;
+
+import com.sun.star.document.XEmbeddedObjectSupplier;
+
+import com.sun.star.frame.XComponentLoader;
+
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XMultiComponentFactory;
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+import com.sun.star.uno.XComponentContext;
+
+import com.sun.star.sheet.XCellRangeAddressable;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheets;
+import com.sun.star.sheet.XSpreadsheetDocument;
+
+import com.sun.star.style.XStyleFamiliesSupplier;
+
+import com.sun.star.table.CellRangeAddress;
+import com.sun.star.table.XCell;
+import com.sun.star.table.XCellRange;
+import com.sun.star.table.XTableChart;
+import com.sun.star.table.XTableCharts;
+import com.sun.star.table.XTableChartsSupplier;
+
+
+public class SCalc {
+
+ public static void main(String args[]) {
+
+ //oooooooooooooooooooooooooooStep 1oooooooooooooooooooooooooooooooooooooooooo
+ // call UNO bootstrap method and get the remote component context form
+ // the a running office (office will be started if necessary)
+
+ XComponentContext xContext = null;
+
+ // get the remote office component context
+ try {
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+ } catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+ //oooooooooooooooooooooooooooStep 2oooooooooooooooooooooooooooooooooooooooooo
+ // open an empty document. In this case it's a calc document.
+ // For this purpose an instance of com.sun.star.frame.Desktop
+ // is created. The desktop provides the XComponentLoader interface,
+ // which is used to open the document via loadComponentFromURL
+
+
+ //Open document
+
+ //Calc
+ XSpreadsheetDocument myDoc = null;
+// XCell oCell = null;
+
+ System.out.println("Opening an empty Calc document");
+ myDoc = openCalc(xContext);
+
+
+
+
+ //oooooooooooooooooooooooooooStep 3oooooooooooooooooooooooooooooooooooooooooo
+ // create cell styles.
+ // For this purpose get the StyleFamiliesSupplier and the family
+ // CellStyle. Create an instance of com.sun.star.style.CellStyle and
+ // add it to the family. Now change some properties
+
+
+ try {
+ XStyleFamiliesSupplier xSFS = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, myDoc);
+ XNameAccess xSF = xSFS.getStyleFamilies();
+ XNameAccess xCS = UnoRuntime.queryInterface(
+ XNameAccess.class, xSF.getByName("CellStyles"));
+ XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, myDoc );
+ XNameContainer oStyleFamilyNameContainer = UnoRuntime.queryInterface(
+ XNameContainer.class, xCS);
+ XInterface oInt1 = (XInterface) oDocMSF.createInstance(
+ "com.sun.star.style.CellStyle");
+ oStyleFamilyNameContainer.insertByName("My Style", oInt1);
+ XPropertySet oCPS1 = UnoRuntime.queryInterface(
+ XPropertySet.class, oInt1 );
+ oCPS1.setPropertyValue("IsCellBackgroundTransparent", Boolean.FALSE);
+ oCPS1.setPropertyValue("CellBackColor",Integer.valueOf(6710932));
+ oCPS1.setPropertyValue("CharColor",Integer.valueOf(16777215));
+ XInterface oInt2 = (XInterface) oDocMSF.createInstance(
+ "com.sun.star.style.CellStyle");
+ oStyleFamilyNameContainer.insertByName("My Style2", oInt2);
+ XPropertySet oCPS2 = UnoRuntime.queryInterface(
+ XPropertySet.class, oInt2 );
+ oCPS2.setPropertyValue("IsCellBackgroundTransparent", Boolean.FALSE);
+ oCPS2.setPropertyValue("CellBackColor",Integer.valueOf(13421823));
+ } catch (Exception e) {
+ e.printStackTrace(System.err);
+ }
+
+
+
+ //oooooooooooooooooooooooooooStep 4oooooooooooooooooooooooooooooooooooooooooo
+ // get the sheet an insert some data.
+ // Get the sheets from the document and then the first from this container.
+ // Now some data can be inserted. For this purpose get a Cell via
+ // getCellByPosition and insert into this cell via setValue() (for floats)
+ // or setFormula() for formulas and Strings
+
+
+
+ XSpreadsheet xSheet=null;
+
+ try {
+ System.out.println("Getting spreadsheet") ;
+ XSpreadsheets xSheets = myDoc.getSheets() ;
+ XIndexAccess oIndexSheets = UnoRuntime.queryInterface(
+ XIndexAccess.class, xSheets);
+ xSheet = UnoRuntime.queryInterface(
+ XSpreadsheet.class, oIndexSheets.getByIndex(0));
+
+ } catch (Exception e) {
+ System.out.println("Couldn't get Sheet " +e);
+ e.printStackTrace(System.err);
+ }
+
+
+
+ System.out.println("Creating the Header") ;
+
+ insertIntoCell(1,0,"JAN",xSheet,"");
+ insertIntoCell(2,0,"FEB",xSheet,"");
+ insertIntoCell(3,0,"MAR",xSheet,"");
+ insertIntoCell(4,0,"APR",xSheet,"");
+ insertIntoCell(5,0,"MAI",xSheet,"");
+ insertIntoCell(6,0,"JUN",xSheet,"");
+ insertIntoCell(7,0,"JUL",xSheet,"");
+ insertIntoCell(8,0,"AUG",xSheet,"");
+ insertIntoCell(9,0,"SEP",xSheet,"");
+ insertIntoCell(10,0,"OCT",xSheet,"");
+ insertIntoCell(11,0,"NOV",xSheet,"");
+ insertIntoCell(12,0,"DEC",xSheet,"");
+ insertIntoCell(13,0,"SUM",xSheet,"");
+
+
+ System.out.println("Fill the lines");
+
+ insertIntoCell(0,1,"Smith",xSheet,"");
+ insertIntoCell(1,1,"42",xSheet,"V");
+ insertIntoCell(2,1,"58.9",xSheet,"V");
+ insertIntoCell(3,1,"-66.5",xSheet,"V");
+ insertIntoCell(4,1,"43.4",xSheet,"V");
+ insertIntoCell(5,1,"44.5",xSheet,"V");
+ insertIntoCell(6,1,"45.3",xSheet,"V");
+ insertIntoCell(7,1,"-67.3",xSheet,"V");
+ insertIntoCell(8,1,"30.5",xSheet,"V");
+ insertIntoCell(9,1,"23.2",xSheet,"V");
+ insertIntoCell(10,1,"-97.3",xSheet,"V");
+ insertIntoCell(11,1,"22.4",xSheet,"V");
+ insertIntoCell(12,1,"23.5",xSheet,"V");
+ insertIntoCell(13,1,"=SUM(B2:M2)",xSheet,"");
+
+
+ insertIntoCell(0,2,"Jones",xSheet,"");
+ insertIntoCell(1,2,"21",xSheet,"V");
+ insertIntoCell(2,2,"40.9",xSheet,"V");
+ insertIntoCell(3,2,"-57.5",xSheet,"V");
+ insertIntoCell(4,2,"-23.4",xSheet,"V");
+ insertIntoCell(5,2,"34.5",xSheet,"V");
+ insertIntoCell(6,2,"59.3",xSheet,"V");
+ insertIntoCell(7,2,"27.3",xSheet,"V");
+ insertIntoCell(8,2,"-38.5",xSheet,"V");
+ insertIntoCell(9,2,"43.2",xSheet,"V");
+ insertIntoCell(10,2,"57.3",xSheet,"V");
+ insertIntoCell(11,2,"25.4",xSheet,"V");
+ insertIntoCell(12,2,"28.5",xSheet,"V");
+ insertIntoCell(13,2,"=SUM(B3:M3)",xSheet,"");
+
+ insertIntoCell(0,3,"Brown",xSheet,"");
+ insertIntoCell(1,3,"31.45",xSheet,"V");
+ insertIntoCell(2,3,"-20.9",xSheet,"V");
+ insertIntoCell(3,3,"-117.5",xSheet,"V");
+ insertIntoCell(4,3,"23.4",xSheet,"V");
+ insertIntoCell(5,3,"-114.5",xSheet,"V");
+ insertIntoCell(6,3,"115.3",xSheet,"V");
+ insertIntoCell(7,3,"-171.3",xSheet,"V");
+ insertIntoCell(8,3,"89.5",xSheet,"V");
+ insertIntoCell(9,3,"41.2",xSheet,"V");
+ insertIntoCell(10,3,"71.3",xSheet,"V");
+ insertIntoCell(11,3,"25.4",xSheet,"V");
+ insertIntoCell(12,3,"38.5",xSheet,"V");
+ insertIntoCell(13,3,"=SUM(A4:L4)",xSheet,"");
+
+
+
+ //oooooooooooooooooooooooooooStep 5oooooooooooooooooooooooooooooooooooooooooo
+ // apply the created cell style.
+ // For this purpose get the PropertySet of the Cell and change the
+ // property CellStyle to the appropriate value.
+
+
+ // change backcolor
+ chgbColor( 1 , 0, 13, 0, "My Style", xSheet );
+ chgbColor( 0 , 1, 0, 3, "My Style", xSheet );
+ chgbColor( 1 , 1, 13, 3, "My Style2", xSheet );
+
+
+
+ //oooooooooooooooooooooooooooStep 6oooooooooooooooooooooooooooooooooooooooooo
+ // insert a 3D chart.
+ // get the CellRange which holds the data for the chart and its RangeAddress
+ // get the TableChartSupplier from the sheet and then the TableCharts from it.
+ // add a new chart based on the data to the TableCharts.
+ // get the ChartDocument, which provide the Diagram. Change the properties
+ // Dim3D (3 dimension) and String (the title) of the diagram.
+
+
+ // insert a chart
+
+ Rectangle oRect = new Rectangle();
+ oRect.X = 500;
+ oRect.Y = 3000;
+ oRect.Width = 25000;
+ oRect.Height = 11000;
+
+ XCellRange oRange = UnoRuntime.queryInterface(
+ XCellRange.class, xSheet);
+ XCellRange myRange = oRange.getCellRangeByName("A1:N4");
+ XCellRangeAddressable oRangeAddr = UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange);
+ CellRangeAddress myAddr = oRangeAddr.getRangeAddress();
+
+ CellRangeAddress[] oAddr = new CellRangeAddress[1];
+ oAddr[0] = myAddr;
+ XTableChartsSupplier oSupp = UnoRuntime.queryInterface(
+ XTableChartsSupplier.class, xSheet);
+
+ XTableChart oChart = null;
+
+ System.out.println("Insert Chart");
+
+ XTableCharts oCharts = oSupp.getCharts();
+ oCharts.addNewByName("Example", oRect, oAddr, true, true);
+
+ // get the diagram and change some of the properties
+
+ try {
+ oChart = (UnoRuntime.queryInterface(
+ XTableChart.class, UnoRuntime.queryInterface(
+ XNameAccess.class, oCharts).getByName("Example")));
+ XEmbeddedObjectSupplier oEOS = UnoRuntime.queryInterface(XEmbeddedObjectSupplier.class, oChart);
+ XInterface oInt = oEOS.getEmbeddedObject();
+ XChartDocument xChart = UnoRuntime.queryInterface(
+ XChartDocument.class,oInt);
+ XDiagram oDiag = xChart.getDiagram();
+ System.out.println("Change Diagram to 3D");
+ XPropertySet oCPS = UnoRuntime.queryInterface(
+ XPropertySet.class, oDiag );
+ oCPS.setPropertyValue("Dim3D", Boolean.TRUE);
+ System.out.println("Change the title");
+ Thread.sleep(200);
+ XPropertySet oTPS = UnoRuntime.queryInterface(
+ XPropertySet.class, xChart.getTitle() );
+ oTPS.setPropertyValue("String","The new title");
+ } catch (Exception e){
+ System.err.println("Changing Properties failed "+e);
+ e.printStackTrace(System.err);
+ }
+
+ System.out.println("done");
+ System.exit(0);
+ }
+
+ public static XSpreadsheetDocument openCalc(XComponentContext xContext)
+ {
+ //define variables
+ XMultiComponentFactory xMCF = null;
+ XComponentLoader xCLoader;
+ XSpreadsheetDocument xSpreadSheetDoc = null;
+ XComponent xComp = null;
+
+ try {
+ // get the service manager from the office
+ xMCF = xContext.getServiceManager();
+
+ // create a new instance of the desktop
+ Object oDesktop = xMCF.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xContext );
+
+ // query the desktop object for the XComponentLoader
+ xCLoader = UnoRuntime.queryInterface(
+ XComponentLoader.class, oDesktop );
+
+ PropertyValue [] szEmptyArgs = new PropertyValue [0];
+ String strDoc = "private:factory/scalc";
+
+ xComp = xCLoader.loadComponentFromURL(strDoc, "_blank", 0, szEmptyArgs );
+ xSpreadSheetDoc = UnoRuntime.queryInterface(
+ XSpreadsheetDocument.class, xComp);
+
+ } catch(Exception e){
+ System.err.println(" Exception " + e);
+ e.printStackTrace(System.err);
+ }
+
+ return xSpreadSheetDoc;
+ }
+
+
+ public static void insertIntoCell(int CellX, int CellY, String theValue,
+ XSpreadsheet TT1, String flag)
+ {
+ XCell xCell = null;
+
+ try {
+ xCell = TT1.getCellByPosition(CellX, CellY);
+ } catch (com.sun.star.lang.IndexOutOfBoundsException ex) {
+ System.err.println("Could not get Cell");
+ ex.printStackTrace(System.err);
+ }
+
+ if (flag.equals("V")) {
+ xCell.setValue((new Float(theValue)).floatValue());
+ } else {
+ xCell.setFormula(theValue);
+ }
+
+ }
+
+ public static void chgbColor( int x1, int y1, int x2, int y2,
+ String template, XSpreadsheet TT )
+ {
+ XCellRange xCR = null;
+ try {
+ xCR = TT.getCellRangeByPosition(x1,y1,x2,y2);
+ } catch (com.sun.star.lang.IndexOutOfBoundsException ex) {
+ System.err.println("Could not get CellRange");
+ ex.printStackTrace(System.err);
+ }
+
+ XPropertySet xCPS = UnoRuntime.queryInterface(
+ XPropertySet.class, xCR );
+
+ try {
+ xCPS.setPropertyValue("CellStyle", template);
+ } catch (Exception e) {
+ System.err.println("Can't change colors chgbColor" + e);
+ e.printStackTrace(System.err);
+ }
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Spreadsheet/XCalcAddins.idl b/odk/examples/java/Spreadsheet/XCalcAddins.idl
new file mode 100644
index 000000000..79767b12c
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/XCalcAddins.idl
@@ -0,0 +1,103 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+#ifndef INCLUDED_ORG_OPENOFFICE_SHEET_ADDIN_XCALCADDIN_IDL
+#define INCLUDED_ORG_OPENOFFICE_SHEET_ADDIN_XCALCADDIN_IDL
+
+#include <com/sun/star/beans/XPropertySet.idl>
+#include <com/sun/star/sheet/AddIn.idl>
+
+
+module org {
+ module openoffice {
+ module sheet {
+ module addin {
+ /** Interface with your additional methods.
+
+ You may declare several methods. Each method may have
+ any number of arguments after xOptions.
+ Furthermore, you could replace the name of the service and
+ the interface, but only if you want to replace this name in all
+ your project files. This example will work with the necessary default
+ names.
+ Interface names should start with an X prefix.
+ */
+ interface XCalcAddins
+ {
+ /** Declare your methods:
+ This is where you could add the declarations of your methods.
+ If you want to learn more about
+ the IDL syntax including the base types, you could
+ visit the following web page:
+ http://www.openoffice.org/project/udk/common/man/idl_syntax.html .
+ */
+ long getMyFirstValue(
+ /** Parameters:
+ You could insert further arguments after the
+ parameter xOptions.
+ */
+ [in] com::sun::star::beans::XPropertySet xOptions
+ );
+
+ long getMySecondValue(
+ /** Parameters:
+ You could insert further arguments after the
+ parameter xOptions.
+ */
+ [in] com::sun::star::beans::XPropertySet xOptions,
+ [in] long intDummy
+ );
+ };
+
+ service CalcAddins
+ {
+ /** Exported interfaces:
+ This is where you put all interfaces that this service exports. The service
+ supports its main interface only.
+ */
+ interface XCalcAddins;
+
+ /** Necessary base service.
+ All add-ins must implement this service
+ */
+ service com::sun::star::sheet::AddIn;
+ };
+ };
+ };
+ };
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Spreadsheet/description.xml b/odk/examples/java/Spreadsheet/description.xml
new file mode 100644
index 000000000..6c4e2396b
--- /dev/null
+++ b/odk/examples/java/Spreadsheet/description.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+-->
+<d:description xmlns:d="http://openoffice.org/extensions/description/2006">
+ <d:dependencies>
+ <l:LibreOffice-minimal-version value="4.1" d:name="LibreOffice 4.1"
+ xmlns:l="http://libreoffice.org/extensions/description/2011"/>
+ </d:dependencies>
+</d:description>