1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SpreadsheetDocument.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 import com
.sun
.star
.uno
.*;
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
33 import com
.sun
.star
.lang
.XComponent
;
34 import com
.sun
.star
.table
.XCellRange
;
35 import com
.sun
.star
.table
.CellAddress
;
36 import com
.sun
.star
.table
.CellRangeAddress
;
37 import com
.sun
.star
.container
.XIndexAccess
;
38 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
39 import com
.sun
.star
.beans
.NamedValue
;
45 public class SpreadsheetDocument
extends DocumentHelper
47 /** Creates a new blank spreadsheet document */
48 public SpreadsheetDocument( XComponentContext xCtx
) throws com
.sun
.star
.uno
.Exception
50 super( xCtx
, implCreateBlankDocument( xCtx
, "private:factory/scalc" ) );
53 public SpreadsheetDocument( XComponentContext xCtx
, XComponent document
) throws com
.sun
.star
.uno
.Exception
55 super( xCtx
, document
);
58 public XCellRange
getSheet( int index
) throws com
.sun
.star
.uno
.Exception
60 XSpreadsheetDocument spreadsheetDoc
= (XSpreadsheetDocument
)UnoRuntime
.queryInterface( XSpreadsheetDocument
.class,
63 XIndexAccess sheets
= (XIndexAccess
)UnoRuntime
.queryInterface( XIndexAccess
.class,
64 spreadsheetDoc
.getSheets()
66 return (XCellRange
)UnoRuntime
.queryInterface( XCellRange
.class,
67 sheets
.getByIndex( index
)
71 /** creates a value binding for a given cell
73 public com
.sun
.star
.form
.binding
.XValueBinding
createCellBinding( short sheet
, short column
, short row
)
75 return createCellBinding( sheet
, column
, row
, false );
78 /** creates a value binding which can be used to exchange a list box selection <em>index</em> with a cell
80 public com
.sun
.star
.form
.binding
.XValueBinding
createListIndexBinding( short sheet
, short column
, short row
)
82 return createCellBinding( sheet
, column
, row
, true );
85 /** creates a value binding for a given cell, with or without support for integer value exchange
87 private com
.sun
.star
.form
.binding
.XValueBinding
createCellBinding( short sheet
, short column
, short row
, boolean supportIntegerValues
)
89 com
.sun
.star
.form
.binding
.XValueBinding cellBinding
= null;
92 CellAddress address
= new CellAddress( sheet
, column
, row
);
93 Object
[] initParam
= new Object
[] { new NamedValue( "BoundCell", address
) };
94 cellBinding
= (com
.sun
.star
.form
.binding
.XValueBinding
)UnoRuntime
.queryInterface(
95 com
.sun
.star
.form
.binding
.XValueBinding
.class,
96 createInstanceWithArguments(
97 supportIntegerValues ?
"com.sun.star.table.ListPositionCellBinding"
98 : "com.sun.star.table.CellValueBinding",
103 catch( com
.sun
.star
.uno
.Exception e
)
105 System
.err
.println( e
);
106 e
.printStackTrace( System
.err
);
111 /** creates a source of list entries associated with a (one-column) cell range
113 public com
.sun
.star
.form
.binding
.XListEntrySource
createListEntrySource( short sheet
, short column
,
114 short topRow
, short bottomRow
)
116 com
.sun
.star
.form
.binding
.XListEntrySource entrySource
= null;
119 CellRangeAddress rangeAddress
= new CellRangeAddress( sheet
, column
,
120 topRow
, column
, bottomRow
);
121 Object
[] initParam
= new Object
[] { new NamedValue( "CellRange", rangeAddress
) };
122 entrySource
= (com
.sun
.star
.form
.binding
.XListEntrySource
)UnoRuntime
.queryInterface(
123 com
.sun
.star
.form
.binding
.XListEntrySource
.class,
124 createInstanceWithArguments(
125 "com.sun.star.table.CellRangeListSource", initParam
) );
127 catch( com
.sun
.star
.uno
.Exception e
)
129 System
.err
.println( e
);
130 e
.printStackTrace( System
.err
);