1*cf279e26SAndrew Rist /**************************************************************
2*cf279e26SAndrew Rist  *
3*cf279e26SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*cf279e26SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*cf279e26SAndrew Rist  * distributed with this work for additional information
6*cf279e26SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*cf279e26SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*cf279e26SAndrew Rist  * "License"); you may not use this file except in compliance
9*cf279e26SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*cf279e26SAndrew Rist  *
11*cf279e26SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*cf279e26SAndrew Rist  *
13*cf279e26SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*cf279e26SAndrew Rist  * software distributed under the License is distributed on an
15*cf279e26SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cf279e26SAndrew Rist  * KIND, either express or implied.  See the License for the
17*cf279e26SAndrew Rist  * specific language governing permissions and limitations
18*cf279e26SAndrew Rist  * under the License.
19*cf279e26SAndrew Rist  *
20*cf279e26SAndrew Rist  *************************************************************/
21*cf279e26SAndrew Rist 
22cdf0e10cSrcweir 
23cdf0e10cSrcweir using System;
24cdf0e10cSrcweir using unoidl.com.sun.star.lang;
25cdf0e10cSrcweir using unoidl.com.sun.star.uno;
26cdf0e10cSrcweir using unoidl.com.sun.star.bridge;
27cdf0e10cSrcweir using unoidl.com.sun.star.frame;
28cdf0e10cSrcweir 
29cdf0e10cSrcweir // __________  implementation  ____________________________________
30cdf0e10cSrcweir 
31cdf0e10cSrcweir /** This is a helper class for the spreadsheet and table samples.
32cdf0e10cSrcweir     It connects to a running office and creates a spreadsheet document.
33cdf0e10cSrcweir     Additionally it contains various helper functions.
34cdf0e10cSrcweir  */
35cdf0e10cSrcweir public class SpreadsheetDocHelper : System.IDisposable
36cdf0e10cSrcweir {
37cdf0e10cSrcweir 
38cdf0e10cSrcweir // __  private members  ___________________________________________
39cdf0e10cSrcweir 
40cdf0e10cSrcweir     private const String  msDataSheetName  = "Data";
41cdf0e10cSrcweir 
42cdf0e10cSrcweir     private unoidl.com.sun.star.uno.XComponentContext m_xContext;
43cdf0e10cSrcweir     private unoidl.com.sun.star.lang.XMultiServiceFactory  mxMSFactory;
44cdf0e10cSrcweir     private unoidl.com.sun.star.sheet.XSpreadsheetDocument mxDocument;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // ________________________________________________________________
47cdf0e10cSrcweir 
SpreadsheetDocHelper( String[] args )48cdf0e10cSrcweir     public SpreadsheetDocHelper( String[] args )
49cdf0e10cSrcweir     {
50cdf0e10cSrcweir         // Connect to a running office and get the service manager
51cdf0e10cSrcweir         mxMSFactory = connect( args );
52cdf0e10cSrcweir         // Create a new spreadsheet document
53cdf0e10cSrcweir         mxDocument = initDocument();
54cdf0e10cSrcweir     }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir // __  helper methods  ____________________________________________
57cdf0e10cSrcweir 
58cdf0e10cSrcweir     /** Returns the service manager.
59cdf0e10cSrcweir         @return  XMultiServiceFactory interface of the service manager. */
getServiceManager()60cdf0e10cSrcweir     public unoidl.com.sun.star.lang.XMultiServiceFactory getServiceManager()
61cdf0e10cSrcweir     {
62cdf0e10cSrcweir         return mxMSFactory;
63cdf0e10cSrcweir     }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     /** Returns the whole spreadsheet document.
66cdf0e10cSrcweir         @return  XSpreadsheetDocument interface of the document. */
getDocument()67cdf0e10cSrcweir     public unoidl.com.sun.star.sheet.XSpreadsheetDocument getDocument()
68cdf0e10cSrcweir     {
69cdf0e10cSrcweir         return mxDocument;
70cdf0e10cSrcweir     }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     /** Returns the spreadsheet with the specified index (0-based).
73cdf0e10cSrcweir         @param nIndex  The index of the sheet.
74cdf0e10cSrcweir         @return  XSpreadsheet interface of the sheet. */
getSpreadsheet( int nIndex )75cdf0e10cSrcweir     public unoidl.com.sun.star.sheet.XSpreadsheet getSpreadsheet( int nIndex )
76cdf0e10cSrcweir     {
77cdf0e10cSrcweir         // Collection of sheets
78cdf0e10cSrcweir         unoidl.com.sun.star.sheet.XSpreadsheets xSheets =
79cdf0e10cSrcweir             mxDocument.getSheets();
80cdf0e10cSrcweir 
81cdf0e10cSrcweir         unoidl.com.sun.star.container.XIndexAccess xSheetsIA =
82cdf0e10cSrcweir             (unoidl.com.sun.star.container.XIndexAccess) xSheets;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir         unoidl.com.sun.star.sheet.XSpreadsheet xSheet =
85cdf0e10cSrcweir             (unoidl.com.sun.star.sheet.XSpreadsheet)
86cdf0e10cSrcweir               xSheetsIA.getByIndex( nIndex ).Value;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir         return xSheet;
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     /** Inserts a new empty spreadsheet with the specified name.
92cdf0e10cSrcweir         @param aName  The name of the new sheet.
93cdf0e10cSrcweir         @param nIndex  The insertion index.
94cdf0e10cSrcweir         @return  The XSpreadsheet interface of the new sheet. */
insertSpreadsheet( String aName, short nIndex )95cdf0e10cSrcweir     public unoidl.com.sun.star.sheet.XSpreadsheet insertSpreadsheet(
96cdf0e10cSrcweir         String aName, short nIndex )
97cdf0e10cSrcweir     {
98cdf0e10cSrcweir         // Collection of sheets
99cdf0e10cSrcweir         unoidl.com.sun.star.sheet.XSpreadsheets xSheets =
100cdf0e10cSrcweir             mxDocument.getSheets();
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         xSheets.insertNewByName( aName, nIndex );
103cdf0e10cSrcweir         unoidl.com.sun.star.sheet.XSpreadsheet xSheet =
104cdf0e10cSrcweir             (unoidl.com.sun.star.sheet.XSpreadsheet)
105cdf0e10cSrcweir               xSheets.getByName( aName ).Value;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir         return xSheet;
108cdf0e10cSrcweir     }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir // ________________________________________________________________
111cdf0e10cSrcweir // Methods to fill values into cells.
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     /** Writes a double value into a spreadsheet.
114cdf0e10cSrcweir         @param xSheet  The XSpreadsheet interface of the spreadsheet.
115cdf0e10cSrcweir         @param aCellName  The address of the cell (or a named range).
116cdf0e10cSrcweir         @param fValue  The value to write into the cell. */
setValue( unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aCellName, double fValue )117cdf0e10cSrcweir     public void setValue(
118cdf0e10cSrcweir         unoidl.com.sun.star.sheet.XSpreadsheet xSheet,
119cdf0e10cSrcweir         String aCellName,
120cdf0e10cSrcweir         double fValue )
121cdf0e10cSrcweir     {
122cdf0e10cSrcweir         xSheet.getCellRangeByName( aCellName ).getCellByPosition(
123cdf0e10cSrcweir             0, 0 ).setValue( fValue );
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     /** Writes a formula into a spreadsheet.
127cdf0e10cSrcweir         @param xSheet  The XSpreadsheet interface of the spreadsheet.
128cdf0e10cSrcweir         @param aCellName  The address of the cell (or a named range).
129cdf0e10cSrcweir         @param aFormula  The formula to write into the cell. */
setFormula( unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aCellName, String aFormula )130cdf0e10cSrcweir     public void setFormula(
131cdf0e10cSrcweir         unoidl.com.sun.star.sheet.XSpreadsheet xSheet,
132cdf0e10cSrcweir         String aCellName,
133cdf0e10cSrcweir         String aFormula )
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         xSheet.getCellRangeByName( aCellName ).getCellByPosition(
136cdf0e10cSrcweir             0, 0 ).setFormula( aFormula );
137cdf0e10cSrcweir     }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     /** Writes a date with standard date format into a spreadsheet.
140cdf0e10cSrcweir         @param xSheet  The XSpreadsheet interface of the spreadsheet.
141cdf0e10cSrcweir         @param aCellName  The address of the cell (or a named range).
142cdf0e10cSrcweir         @param nDay  The day of the date.
143cdf0e10cSrcweir         @param nMonth  The month of the date.
144cdf0e10cSrcweir         @param nYear  The year of the date. */
setDate( unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aCellName, int nDay, int nMonth, int nYear )145cdf0e10cSrcweir     public void setDate(
146cdf0e10cSrcweir         unoidl.com.sun.star.sheet.XSpreadsheet xSheet,
147cdf0e10cSrcweir         String aCellName,
148cdf0e10cSrcweir         int nDay, int nMonth, int nYear )
149cdf0e10cSrcweir     {
150cdf0e10cSrcweir         // Set the date value.
151cdf0e10cSrcweir         unoidl.com.sun.star.table.XCell xCell =
152cdf0e10cSrcweir             xSheet.getCellRangeByName( aCellName ).getCellByPosition( 0, 0 );
153cdf0e10cSrcweir         String aDateStr = nMonth + "/" + nDay + "/" + nYear;
154cdf0e10cSrcweir         xCell.setFormula( aDateStr );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir         // Set standard date format.
157cdf0e10cSrcweir         unoidl.com.sun.star.util.XNumberFormatsSupplier xFormatsSupplier =
158cdf0e10cSrcweir             (unoidl.com.sun.star.util.XNumberFormatsSupplier) getDocument();
159cdf0e10cSrcweir         unoidl.com.sun.star.util.XNumberFormatTypes xFormatTypes =
160cdf0e10cSrcweir             (unoidl.com.sun.star.util.XNumberFormatTypes)
161cdf0e10cSrcweir               xFormatsSupplier.getNumberFormats();
162cdf0e10cSrcweir         int nFormat = xFormatTypes.getStandardFormat(
163cdf0e10cSrcweir             unoidl.com.sun.star.util.NumberFormat.DATE,
164cdf0e10cSrcweir             new unoidl.com.sun.star.lang.Locale() );
165cdf0e10cSrcweir 
166cdf0e10cSrcweir         unoidl.com.sun.star.beans.XPropertySet xPropSet =
167cdf0e10cSrcweir             (unoidl.com.sun.star.beans.XPropertySet) xCell;
168cdf0e10cSrcweir         xPropSet.setPropertyValue(
169cdf0e10cSrcweir             "NumberFormat",
170cdf0e10cSrcweir             new uno.Any( (Int32) nFormat ) );
171cdf0e10cSrcweir     }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     /** Draws a colored border around the range and writes the headline
174cdf0e10cSrcweir         in the first cell.
175cdf0e10cSrcweir 
176cdf0e10cSrcweir         @param xSheet  The XSpreadsheet interface of the spreadsheet.
177cdf0e10cSrcweir         @param aRange  The address of the cell range (or a named range).
178cdf0e10cSrcweir         @param aHeadline  The headline text. */
prepareRange( unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aRange, String aHeadline )179cdf0e10cSrcweir     public void prepareRange(
180cdf0e10cSrcweir         unoidl.com.sun.star.sheet.XSpreadsheet xSheet,
181cdf0e10cSrcweir         String aRange, String aHeadline )
182cdf0e10cSrcweir     {
183cdf0e10cSrcweir         unoidl.com.sun.star.beans.XPropertySet xPropSet = null;
184cdf0e10cSrcweir         unoidl.com.sun.star.table.XCellRange xCellRange = null;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir         // draw border
187cdf0e10cSrcweir         xCellRange = xSheet.getCellRangeByName( aRange );
188cdf0e10cSrcweir         xPropSet = (unoidl.com.sun.star.beans.XPropertySet) xCellRange;
189cdf0e10cSrcweir         unoidl.com.sun.star.table.BorderLine aLine =
190cdf0e10cSrcweir             new unoidl.com.sun.star.table.BorderLine();
191cdf0e10cSrcweir         aLine.Color = 0x99CCFF;
192cdf0e10cSrcweir         aLine.InnerLineWidth = aLine.LineDistance = 0;
193cdf0e10cSrcweir         aLine.OuterLineWidth = 100;
194cdf0e10cSrcweir         unoidl.com.sun.star.table.TableBorder aBorder =
195cdf0e10cSrcweir             new unoidl.com.sun.star.table.TableBorder();
196cdf0e10cSrcweir         aBorder.TopLine = aBorder.BottomLine = aBorder.LeftLine =
197cdf0e10cSrcweir             aBorder.RightLine = aLine;
198cdf0e10cSrcweir         aBorder.IsTopLineValid = aBorder.IsBottomLineValid = true;
199cdf0e10cSrcweir         aBorder.IsLeftLineValid = aBorder.IsRightLineValid = true;
200cdf0e10cSrcweir         xPropSet.setPropertyValue(
201cdf0e10cSrcweir             "TableBorder",
202cdf0e10cSrcweir             new uno.Any(
203cdf0e10cSrcweir                 typeof (unoidl.com.sun.star.table.TableBorder), aBorder ) );
204cdf0e10cSrcweir 
205cdf0e10cSrcweir         // draw headline
206cdf0e10cSrcweir         unoidl.com.sun.star.sheet.XCellRangeAddressable xAddr =
207cdf0e10cSrcweir             (unoidl.com.sun.star.sheet.XCellRangeAddressable) xCellRange;
208cdf0e10cSrcweir         unoidl.com.sun.star.table.CellRangeAddress aAddr =
209cdf0e10cSrcweir             xAddr.getRangeAddress();
210cdf0e10cSrcweir 
211cdf0e10cSrcweir         xCellRange = xSheet.getCellRangeByPosition(
212cdf0e10cSrcweir             aAddr.StartColumn,
213cdf0e10cSrcweir             aAddr.StartRow, aAddr.EndColumn, aAddr.StartRow );
214cdf0e10cSrcweir 
215cdf0e10cSrcweir         xPropSet = (unoidl.com.sun.star.beans.XPropertySet) xCellRange;
216cdf0e10cSrcweir         xPropSet.setPropertyValue(
217cdf0e10cSrcweir             "CellBackColor", new uno.Any( (Int32) 0x99CCFF ) );
218cdf0e10cSrcweir         // write headline
219cdf0e10cSrcweir         unoidl.com.sun.star.table.XCell xCell =
220cdf0e10cSrcweir             xCellRange.getCellByPosition( 0, 0 );
221cdf0e10cSrcweir         xCell.setFormula( aHeadline );
222cdf0e10cSrcweir         xPropSet = (unoidl.com.sun.star.beans.XPropertySet) xCell;
223cdf0e10cSrcweir         xPropSet.setPropertyValue(
224cdf0e10cSrcweir             "CharColor", new uno.Any( (Int32) 0x003399 ) );
225cdf0e10cSrcweir         xPropSet.setPropertyValue(
226cdf0e10cSrcweir             "CharWeight",
227cdf0e10cSrcweir             new uno.Any( (Single) unoidl.com.sun.star.awt.FontWeight.BOLD ) );
228cdf0e10cSrcweir     }
229cdf0e10cSrcweir 
230cdf0e10cSrcweir // ________________________________________________________________
231cdf0e10cSrcweir // Methods to create cell addresses and range addresses.
232cdf0e10cSrcweir 
233cdf0e10cSrcweir     /** Creates a unoidl.com.sun.star.table.CellAddress and initializes it
234cdf0e10cSrcweir         with the given range.
235cdf0e10cSrcweir         @param xSheet  The XSpreadsheet interface of the spreadsheet.
236cdf0e10cSrcweir         @param aCell  The address of the cell (or a named cell). */
createCellAddress( unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aCell )237cdf0e10cSrcweir     public unoidl.com.sun.star.table.CellAddress createCellAddress(
238cdf0e10cSrcweir         unoidl.com.sun.star.sheet.XSpreadsheet xSheet,
239cdf0e10cSrcweir         String aCell )
240cdf0e10cSrcweir     {
241cdf0e10cSrcweir         unoidl.com.sun.star.sheet.XCellAddressable xAddr =
242cdf0e10cSrcweir         (unoidl.com.sun.star.sheet.XCellAddressable)
243cdf0e10cSrcweir             xSheet.getCellRangeByName( aCell ).getCellByPosition( 0, 0 );
244cdf0e10cSrcweir         return xAddr.getCellAddress();
245cdf0e10cSrcweir     }
246cdf0e10cSrcweir 
247cdf0e10cSrcweir     /** Creates a unoidl.com.sun.star.table.CellRangeAddress and initializes
248cdf0e10cSrcweir         it with the given range.
249cdf0e10cSrcweir         @param xSheet  The XSpreadsheet interface of the spreadsheet.
250cdf0e10cSrcweir         @param aRange  The address of the cell range (or a named range). */
createCellRangeAddress( unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aRange )251cdf0e10cSrcweir     public unoidl.com.sun.star.table.CellRangeAddress createCellRangeAddress(
252cdf0e10cSrcweir         unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aRange )
253cdf0e10cSrcweir     {
254cdf0e10cSrcweir         unoidl.com.sun.star.sheet.XCellRangeAddressable xAddr =
255cdf0e10cSrcweir             (unoidl.com.sun.star.sheet.XCellRangeAddressable)
256cdf0e10cSrcweir             xSheet.getCellRangeByName( aRange );
257cdf0e10cSrcweir         return xAddr.getRangeAddress();
258cdf0e10cSrcweir     }
259cdf0e10cSrcweir 
260cdf0e10cSrcweir // ________________________________________________________________
261cdf0e10cSrcweir // Methods to convert cell addresses and range addresses to strings.
262cdf0e10cSrcweir 
263cdf0e10cSrcweir     /** Returns the text address of the cell.
264cdf0e10cSrcweir         @param nColumn  The column index.
265cdf0e10cSrcweir         @param nRow  The row index.
266cdf0e10cSrcweir         @return  A string containing the cell address. */
getCellAddressString( int nColumn, int nRow )267cdf0e10cSrcweir     public String getCellAddressString( int nColumn, int nRow )
268cdf0e10cSrcweir     {
269cdf0e10cSrcweir         String aStr = "";
270cdf0e10cSrcweir         if (nColumn > 25)
271cdf0e10cSrcweir             aStr += (char) ('A' + nColumn / 26 - 1);
272cdf0e10cSrcweir         aStr += (char) ('A' + nColumn % 26);
273cdf0e10cSrcweir         aStr += (nRow + 1);
274cdf0e10cSrcweir         return aStr;
275cdf0e10cSrcweir     }
276cdf0e10cSrcweir 
277cdf0e10cSrcweir     /** Returns the text address of the cell range.
278cdf0e10cSrcweir         @param aCellRange  The cell range address.
279cdf0e10cSrcweir         @return  A string containing the cell range address. */
getCellRangeAddressString( unoidl.com.sun.star.table.CellRangeAddress aCellRange )280cdf0e10cSrcweir     public String getCellRangeAddressString(
281cdf0e10cSrcweir         unoidl.com.sun.star.table.CellRangeAddress aCellRange )
282cdf0e10cSrcweir     {
283cdf0e10cSrcweir         return
284cdf0e10cSrcweir             getCellAddressString( aCellRange.StartColumn, aCellRange.StartRow )
285cdf0e10cSrcweir             + ":"
286cdf0e10cSrcweir             + getCellAddressString( aCellRange.EndColumn, aCellRange.EndRow );
287cdf0e10cSrcweir     }
288cdf0e10cSrcweir 
289cdf0e10cSrcweir     /** Returns the text address of the cell range.
290cdf0e10cSrcweir         @param xCellRange  The XSheetCellRange interface of the cell range.
291cdf0e10cSrcweir         @param bWithSheet  true = Include sheet name.
292cdf0e10cSrcweir         @return  A string containing the cell range address. */
getCellRangeAddressString( unoidl.com.sun.star.sheet.XSheetCellRange xCellRange, bool bWithSheet )293cdf0e10cSrcweir     public String getCellRangeAddressString(
294cdf0e10cSrcweir         unoidl.com.sun.star.sheet.XSheetCellRange xCellRange, bool bWithSheet )
295cdf0e10cSrcweir     {
296cdf0e10cSrcweir         String aStr = "";
297cdf0e10cSrcweir         if (bWithSheet)
298cdf0e10cSrcweir         {
299cdf0e10cSrcweir             unoidl.com.sun.star.sheet.XSpreadsheet xSheet =
300cdf0e10cSrcweir                 xCellRange.getSpreadsheet();
301cdf0e10cSrcweir             unoidl.com.sun.star.container.XNamed xNamed =
302cdf0e10cSrcweir                 (unoidl.com.sun.star.container.XNamed) xSheet;
303cdf0e10cSrcweir             aStr += xNamed.getName() + ".";
304cdf0e10cSrcweir         }
305cdf0e10cSrcweir         unoidl.com.sun.star.sheet.XCellRangeAddressable xAddr =
306cdf0e10cSrcweir             (unoidl.com.sun.star.sheet.XCellRangeAddressable) xCellRange;
307cdf0e10cSrcweir         aStr += getCellRangeAddressString( xAddr.getRangeAddress() );
308cdf0e10cSrcweir         return aStr;
309cdf0e10cSrcweir     }
310cdf0e10cSrcweir 
311cdf0e10cSrcweir     /** Returns a list of addresses of all cell ranges contained in the
312cdf0e10cSrcweir         collection.
313cdf0e10cSrcweir 
314cdf0e10cSrcweir         @param xRangesIA  The XIndexAccess interface of the collection.
315cdf0e10cSrcweir         @return  A string containing the cell range address list. */
getCellRangeListString( unoidl.com.sun.star.container.XIndexAccess xRangesIA )316cdf0e10cSrcweir     public String getCellRangeListString(
317cdf0e10cSrcweir         unoidl.com.sun.star.container.XIndexAccess xRangesIA )
318cdf0e10cSrcweir     {
319cdf0e10cSrcweir         String aStr = "";
320cdf0e10cSrcweir         int nCount = xRangesIA.getCount();
321cdf0e10cSrcweir         for (int nIndex = 0; nIndex < nCount; ++nIndex)
322cdf0e10cSrcweir         {
323cdf0e10cSrcweir             if (nIndex > 0)
324cdf0e10cSrcweir                 aStr += " ";
325cdf0e10cSrcweir             uno.Any aRangeObj = xRangesIA.getByIndex( nIndex );
326cdf0e10cSrcweir             unoidl.com.sun.star.sheet.XSheetCellRange xCellRange =
327cdf0e10cSrcweir                 (unoidl.com.sun.star.sheet.XSheetCellRange) aRangeObj.Value;
328cdf0e10cSrcweir             aStr += getCellRangeAddressString( xCellRange, false );
329cdf0e10cSrcweir         }
330cdf0e10cSrcweir         return aStr;
331cdf0e10cSrcweir     }
332cdf0e10cSrcweir 
333cdf0e10cSrcweir // ________________________________________________________________
334cdf0e10cSrcweir 
335cdf0e10cSrcweir     /** Connect to a running office that is accepting connections.
336cdf0e10cSrcweir         @return  The ServiceManager to instantiate office components. */
connect( String [] args )337cdf0e10cSrcweir     private XMultiServiceFactory connect( String [] args )
338cdf0e10cSrcweir     {
339cdf0e10cSrcweir 
340cdf0e10cSrcweir         m_xContext = uno.util.Bootstrap.bootstrap();
341cdf0e10cSrcweir 
342cdf0e10cSrcweir         return (XMultiServiceFactory) m_xContext.getServiceManager();
343cdf0e10cSrcweir     }
344cdf0e10cSrcweir 
Dispose()345cdf0e10cSrcweir     public void Dispose()
346cdf0e10cSrcweir     {
347cdf0e10cSrcweir 
348cdf0e10cSrcweir     }
349cdf0e10cSrcweir 
350cdf0e10cSrcweir     /** Creates an empty spreadsheet document.
351cdf0e10cSrcweir         @return  The XSpreadsheetDocument interface of the document. */
initDocument()352cdf0e10cSrcweir     private unoidl.com.sun.star.sheet.XSpreadsheetDocument initDocument()
353cdf0e10cSrcweir     {
354cdf0e10cSrcweir         XComponentLoader aLoader = (XComponentLoader)
355cdf0e10cSrcweir             mxMSFactory.createInstance( "com.sun.star.frame.Desktop" );
356cdf0e10cSrcweir 
357cdf0e10cSrcweir         XComponent xComponent = aLoader.loadComponentFromURL(
358cdf0e10cSrcweir             "private:factory/scalc", "_blank", 0,
359cdf0e10cSrcweir             new unoidl.com.sun.star.beans.PropertyValue[0] );
360cdf0e10cSrcweir 
361cdf0e10cSrcweir         return (unoidl.com.sun.star.sheet.XSpreadsheetDocument) xComponent;
362cdf0e10cSrcweir     }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir // ________________________________________________________________
365cdf0e10cSrcweir }
366