1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 using System; 25 using unoidl.com.sun.star.lang; 26 using unoidl.com.sun.star.uno; 27 using unoidl.com.sun.star.frame; 28 using unoidl.com.sun.star.util; 29 30 namespace cliversion 31 { 32 public class Version 33 { Version()34 public Version() 35 { 36 try 37 { 38 // System.Diagnostics.Debugger.Launch(); 39 40 //link with cli_ure.dll 41 uno.util.WeakBase wb = new uno.util.WeakBase(); 42 using ( SpreadsheetSample aSample = new SpreadsheetSample() ) 43 { 44 aSample.doCellRangeSamples(); 45 aSample.terminate(); 46 } 47 } 48 catch (System.Exception ) 49 { 50 //This exception is thrown if we link with a library which is not 51 //available 52 throw; 53 } 54 } 55 } 56 57 class SpreadsheetSample: SpreadsheetDocHelper 58 { SpreadsheetSample()59 public SpreadsheetSample() 60 { 61 } 62 /** All samples regarding the service com.sun.star.sheet.SheetCellRange. */ doCellRangeSamples()63 public void doCellRangeSamples() 64 { 65 unoidl.com.sun.star.sheet.XSpreadsheet xSheet = getSpreadsheet( 0 ); 66 unoidl.com.sun.star.table.XCellRange xCellRange = null; 67 unoidl.com.sun.star.beans.XPropertySet xPropSet = null; 68 unoidl.com.sun.star.table.CellRangeAddress aRangeAddress = null; 69 70 // Preparation 71 setFormula( xSheet, "B5", "First cell" ); 72 setFormula( xSheet, "B6", "Second cell" ); 73 // Get cell range B5:B6 by position - (column, row, column, row) 74 xCellRange = xSheet.getCellRangeByPosition( 1, 4, 1, 5 ); 75 76 77 // --- Change cell range properties. --- 78 xPropSet = (unoidl.com.sun.star.beans.XPropertySet) xCellRange; 79 // from com.sun.star.styles.CharacterProperties 80 xPropSet.setPropertyValue( 81 "CharColor", new uno.Any( (Int32) 0x003399 ) ); 82 xPropSet.setPropertyValue( 83 "CharHeight", new uno.Any( (Single) 20.0 ) ); 84 // from com.sun.star.styles.ParagraphProperties 85 xPropSet.setPropertyValue( 86 "ParaLeftMargin", new uno.Any( (Int32) 500 ) ); 87 // from com.sun.star.table.CellProperties 88 xPropSet.setPropertyValue( 89 "IsCellBackgroundTransparent", new uno.Any( false ) ); 90 xPropSet.setPropertyValue( 91 "CellBackColor", new uno.Any( (Int32) 0x99CCFF ) ); 92 93 94 // --- Replace text in all cells. --- 95 unoidl.com.sun.star.util.XReplaceable xReplace = 96 (unoidl.com.sun.star.util.XReplaceable) xCellRange; 97 unoidl.com.sun.star.util.XReplaceDescriptor xReplaceDesc = 98 xReplace.createReplaceDescriptor(); 99 xReplaceDesc.setSearchString( "cell" ); 100 xReplaceDesc.setReplaceString( "text" ); 101 // property SearchWords searches for whole cells! 102 xReplaceDesc.setPropertyValue( "SearchWords", new uno.Any( false ) ); 103 int nCount = xReplace.replaceAll( xReplaceDesc ); 104 105 // --- Merge cells. --- 106 xCellRange = xSheet.getCellRangeByName( "F3:G6" ); 107 prepareRange( xSheet, "E1:H7", "XMergeable" ); 108 unoidl.com.sun.star.util.XMergeable xMerge = 109 (unoidl.com.sun.star.util.XMergeable) xCellRange; 110 xMerge.merge( true ); 111 112 113 // --- Column properties. --- 114 xCellRange = xSheet.getCellRangeByName( "B1" ); 115 unoidl.com.sun.star.table.XColumnRowRange xColRowRange = 116 (unoidl.com.sun.star.table.XColumnRowRange) xCellRange; 117 unoidl.com.sun.star.table.XTableColumns xColumns = 118 xColRowRange.getColumns(); 119 120 uno.Any aColumnObj = xColumns.getByIndex( 0 ); 121 xPropSet = (unoidl.com.sun.star.beans.XPropertySet) aColumnObj.Value; 122 xPropSet.setPropertyValue( "Width", new uno.Any( (Int32) 6000 ) ); 123 124 unoidl.com.sun.star.container.XNamed xNamed = 125 (unoidl.com.sun.star.container.XNamed) aColumnObj.Value; 126 127 // --- Cell range data --- 128 prepareRange( xSheet, "A9:C30", "XCellRangeData" ); 129 130 xCellRange = xSheet.getCellRangeByName( "A10:C30" ); 131 unoidl.com.sun.star.sheet.XCellRangeData xData = 132 (unoidl.com.sun.star.sheet.XCellRangeData) xCellRange; 133 uno.Any [][] aValues = 134 { 135 new uno.Any [] { new uno.Any( "Name" ), 136 new uno.Any( "Fruit" ), 137 new uno.Any( "Quantity" ) }, 138 new uno.Any [] { new uno.Any( "Alice" ), 139 new uno.Any( "Apples" ), 140 new uno.Any( (Double) 3.0 ) }, 141 new uno.Any [] { new uno.Any( "Alice" ), 142 new uno.Any( "Oranges" ), 143 new uno.Any( (Double) 7.0 ) }, 144 new uno.Any [] { new uno.Any( "Bob" ), 145 new uno.Any( "Apples" ), 146 new uno.Any( (Double) 3.0 ) }, 147 new uno.Any [] { new uno.Any( "Alice" ), 148 new uno.Any( "Apples" ), 149 new uno.Any( (Double) 9.0 ) }, 150 new uno.Any [] { new uno.Any( "Bob" ), 151 new uno.Any( "Apples" ), 152 new uno.Any( (Double) 5.0 ) }, 153 new uno.Any [] { new uno.Any( "Bob" ), 154 new uno.Any( "Oranges" ), 155 new uno.Any( (Double) 6.0 ) }, 156 new uno.Any [] { new uno.Any( "Alice" ), 157 new uno.Any( "Oranges" ), 158 new uno.Any( (Double) 3.0 ) }, 159 new uno.Any [] { new uno.Any( "Alice" ), 160 new uno.Any( "Apples" ), 161 new uno.Any( (Double) 8.0 ) }, 162 new uno.Any [] { new uno.Any( "Alice" ), 163 new uno.Any( "Oranges" ), 164 new uno.Any( (Double) 1.0 ) }, 165 new uno.Any [] { new uno.Any( "Bob" ), 166 new uno.Any( "Oranges" ), 167 new uno.Any( (Double) 2.0 ) }, 168 new uno.Any [] { new uno.Any( "Bob" ), 169 new uno.Any( "Oranges" ), 170 new uno.Any( (Double) 7.0 ) }, 171 new uno.Any [] { new uno.Any( "Bob" ), 172 new uno.Any( "Apples" ), 173 new uno.Any( (Double) 1.0 ) }, 174 new uno.Any [] { new uno.Any( "Alice" ), 175 new uno.Any( "Apples" ), 176 new uno.Any( (Double) 8.0 ) }, 177 new uno.Any [] { new uno.Any( "Alice" ), 178 new uno.Any( "Oranges" ), 179 new uno.Any( (Double) 8.0 ) }, 180 new uno.Any [] { new uno.Any( "Alice" ), 181 new uno.Any( "Apples" ), 182 new uno.Any( (Double) 7.0 ) }, 183 new uno.Any [] { new uno.Any( "Bob" ), 184 new uno.Any( "Apples" ), 185 new uno.Any( (Double) 1.0 ) }, 186 new uno.Any [] { new uno.Any( "Bob" ), 187 new uno.Any( "Oranges" ), 188 new uno.Any( (Double) 9.0 ) }, 189 new uno.Any [] { new uno.Any( "Bob" ), 190 new uno.Any( "Oranges" ), 191 new uno.Any( (Double) 3.0 ) }, 192 new uno.Any [] { new uno.Any( "Alice" ), 193 new uno.Any( "Oranges" ), 194 new uno.Any( (Double) 4.0 ) }, 195 new uno.Any [] { new uno.Any( "Alice" ), 196 new uno.Any( "Apples" ), 197 new uno.Any( (Double) 9.0 ) } 198 }; 199 xData.setDataArray( aValues ); 200 201 202 // --- Get cell range address. --- 203 unoidl.com.sun.star.sheet.XCellRangeAddressable xRangeAddr = 204 (unoidl.com.sun.star.sheet.XCellRangeAddressable) xCellRange; 205 aRangeAddress = xRangeAddr.getRangeAddress(); 206 207 // --- Sheet operation. --- 208 // uses the range filled with XCellRangeData 209 unoidl.com.sun.star.sheet.XSheetOperation xSheetOp = 210 (unoidl.com.sun.star.sheet.XSheetOperation) xData; 211 double fResult = xSheetOp.computeFunction( 212 unoidl.com.sun.star.sheet.GeneralFunction.AVERAGE ); 213 214 // --- Fill series --- 215 // Prepare the example 216 setValue( xSheet, "E10", 1 ); 217 setValue( xSheet, "E11", 4 ); 218 setDate( xSheet, "E12", 30, 1, 2002 ); 219 setFormula( xSheet, "I13", "Text 10" ); 220 setFormula( xSheet, "E14", "Jan" ); 221 setValue( xSheet, "K14", 10 ); 222 setValue( xSheet, "E16", 1 ); 223 setValue( xSheet, "F16", 2 ); 224 setDate( xSheet, "E17", 28, 2, 2002 ); 225 setDate( xSheet, "F17", 28, 1, 2002 ); 226 setValue( xSheet, "E18", 6 ); 227 setValue( xSheet, "F18", 4 ); 228 229 } 230 231 /** Returns the XCellSeries interface of a cell range. 232 @param xSheet The spreadsheet containing the cell range. 233 @param aRange The address of the cell range. 234 @return The XCellSeries interface. */ getCellSeries( unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aRange )235 private unoidl.com.sun.star.sheet.XCellSeries getCellSeries( 236 unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aRange ) 237 { 238 return (unoidl.com.sun.star.sheet.XCellSeries) 239 xSheet.getCellRangeByName( aRange ); 240 } 241 242 } 243 244 /** This is a helper class for the spreadsheet and table samples. 245 It connects to a running office and creates a spreadsheet document. 246 Additionally it contains various helper functions. 247 */ 248 class SpreadsheetDocHelper : System.IDisposable 249 { 250 251 // __ private members ___________________________________________ 252 253 private const String msDataSheetName = "Data"; 254 255 private unoidl.com.sun.star.uno.XComponentContext m_xContext; 256 private unoidl.com.sun.star.lang.XMultiServiceFactory mxMSFactory; 257 private unoidl.com.sun.star.sheet.XSpreadsheetDocument mxDocument; 258 259 // ________________________________________________________________ 260 SpreadsheetDocHelper()261 public SpreadsheetDocHelper() 262 { 263 // System.Diagnostics.Debugger.Launch(); 264 // Connect to a running office and get the service manager 265 mxMSFactory = connect(); 266 // Create a new spreadsheet document 267 mxDocument = initDocument(); 268 } 269 270 // __ helper methods ____________________________________________ 271 272 /** Returns the service manager. 273 @return XMultiServiceFactory interface of the service manager. */ getServiceManager()274 public unoidl.com.sun.star.lang.XMultiServiceFactory getServiceManager() 275 { 276 return mxMSFactory; 277 } 278 279 /** Returns the whole spreadsheet document. 280 @return XSpreadsheetDocument interface of the document. */ getDocument()281 public unoidl.com.sun.star.sheet.XSpreadsheetDocument getDocument() 282 { 283 return mxDocument; 284 } 285 286 /** Returns the spreadsheet with the specified index (0-based). 287 @param nIndex The index of the sheet. 288 @return XSpreadsheet interface of the sheet. */ getSpreadsheet( int nIndex )289 public unoidl.com.sun.star.sheet.XSpreadsheet getSpreadsheet( int nIndex ) 290 { 291 // Collection of sheets 292 unoidl.com.sun.star.sheet.XSpreadsheets xSheets = 293 mxDocument.getSheets(); 294 295 unoidl.com.sun.star.container.XIndexAccess xSheetsIA = 296 (unoidl.com.sun.star.container.XIndexAccess) xSheets; 297 298 unoidl.com.sun.star.sheet.XSpreadsheet xSheet = 299 (unoidl.com.sun.star.sheet.XSpreadsheet) 300 xSheetsIA.getByIndex( nIndex ).Value; 301 302 return xSheet; 303 } 304 305 /** Inserts a new empty spreadsheet with the specified name. 306 @param aName The name of the new sheet. 307 @param nIndex The insertion index. 308 @return The XSpreadsheet interface of the new sheet. */ insertSpreadsheet( String aName, short nIndex )309 public unoidl.com.sun.star.sheet.XSpreadsheet insertSpreadsheet( 310 String aName, short nIndex ) 311 { 312 // Collection of sheets 313 unoidl.com.sun.star.sheet.XSpreadsheets xSheets = 314 mxDocument.getSheets(); 315 316 xSheets.insertNewByName( aName, nIndex ); 317 unoidl.com.sun.star.sheet.XSpreadsheet xSheet = 318 (unoidl.com.sun.star.sheet.XSpreadsheet) 319 xSheets.getByName( aName ).Value; 320 321 return xSheet; 322 } 323 324 // ________________________________________________________________ 325 // Methods to fill values into cells. 326 327 /** Writes a double value into a spreadsheet. 328 @param xSheet The XSpreadsheet interface of the spreadsheet. 329 @param aCellName The address of the cell (or a named range). 330 @param fValue The value to write into the cell. */ setValue( unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aCellName, double fValue )331 public void setValue( 332 unoidl.com.sun.star.sheet.XSpreadsheet xSheet, 333 String aCellName, 334 double fValue ) 335 { 336 xSheet.getCellRangeByName( aCellName ).getCellByPosition( 337 0, 0 ).setValue( fValue ); 338 } 339 340 /** Writes a formula into a spreadsheet. 341 @param xSheet The XSpreadsheet interface of the spreadsheet. 342 @param aCellName The address of the cell (or a named range). 343 @param aFormula The formula to write into the cell. */ setFormula( unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aCellName, String aFormula )344 public void setFormula( 345 unoidl.com.sun.star.sheet.XSpreadsheet xSheet, 346 String aCellName, 347 String aFormula ) 348 { 349 xSheet.getCellRangeByName( aCellName ).getCellByPosition( 350 0, 0 ).setFormula( aFormula ); 351 } 352 353 /** Writes a date with standard date format into a spreadsheet. 354 @param xSheet The XSpreadsheet interface of the spreadsheet. 355 @param aCellName The address of the cell (or a named range). 356 @param nDay The day of the date. 357 @param nMonth The month of the date. 358 @param nYear The year of the date. */ setDate( unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aCellName, int nDay, int nMonth, int nYear )359 public void setDate( 360 unoidl.com.sun.star.sheet.XSpreadsheet xSheet, 361 String aCellName, 362 int nDay, int nMonth, int nYear ) 363 { 364 // Set the date value. 365 unoidl.com.sun.star.table.XCell xCell = 366 xSheet.getCellRangeByName( aCellName ).getCellByPosition( 0, 0 ); 367 String aDateStr = nMonth + "/" + nDay + "/" + nYear; 368 xCell.setFormula( aDateStr ); 369 370 // Set standard date format. 371 unoidl.com.sun.star.util.XNumberFormatsSupplier xFormatsSupplier = 372 (unoidl.com.sun.star.util.XNumberFormatsSupplier) getDocument(); 373 unoidl.com.sun.star.util.XNumberFormatTypes xFormatTypes = 374 (unoidl.com.sun.star.util.XNumberFormatTypes) 375 xFormatsSupplier.getNumberFormats(); 376 int nFormat = xFormatTypes.getStandardFormat( 377 unoidl.com.sun.star.util.NumberFormat.DATE, 378 new unoidl.com.sun.star.lang.Locale() ); 379 380 unoidl.com.sun.star.beans.XPropertySet xPropSet = 381 (unoidl.com.sun.star.beans.XPropertySet) xCell; 382 xPropSet.setPropertyValue( 383 "NumberFormat", 384 new uno.Any( (Int32) nFormat ) ); 385 } 386 387 /** Draws a colored border around the range and writes the headline 388 in the first cell. 389 390 @param xSheet The XSpreadsheet interface of the spreadsheet. 391 @param aRange The address of the cell range (or a named range). 392 @param aHeadline The headline text. */ prepareRange( unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aRange, String aHeadline )393 public void prepareRange( 394 unoidl.com.sun.star.sheet.XSpreadsheet xSheet, 395 String aRange, String aHeadline ) 396 { 397 unoidl.com.sun.star.beans.XPropertySet xPropSet = null; 398 unoidl.com.sun.star.table.XCellRange xCellRange = null; 399 400 // draw border 401 xCellRange = xSheet.getCellRangeByName( aRange ); 402 xPropSet = (unoidl.com.sun.star.beans.XPropertySet) xCellRange; 403 unoidl.com.sun.star.table.BorderLine aLine = 404 new unoidl.com.sun.star.table.BorderLine(); 405 aLine.Color = 0x99CCFF; 406 aLine.InnerLineWidth = aLine.LineDistance = 0; 407 aLine.OuterLineWidth = 100; 408 unoidl.com.sun.star.table.TableBorder aBorder = 409 new unoidl.com.sun.star.table.TableBorder(); 410 aBorder.TopLine = aBorder.BottomLine = aBorder.LeftLine = 411 aBorder.RightLine = aLine; 412 aBorder.IsTopLineValid = aBorder.IsBottomLineValid = true; 413 aBorder.IsLeftLineValid = aBorder.IsRightLineValid = true; 414 xPropSet.setPropertyValue( 415 "TableBorder", 416 new uno.Any( 417 typeof (unoidl.com.sun.star.table.TableBorder), aBorder ) ); 418 419 // draw headline 420 unoidl.com.sun.star.sheet.XCellRangeAddressable xAddr = 421 (unoidl.com.sun.star.sheet.XCellRangeAddressable) xCellRange; 422 unoidl.com.sun.star.table.CellRangeAddress aAddr = 423 xAddr.getRangeAddress(); 424 425 xCellRange = xSheet.getCellRangeByPosition( 426 aAddr.StartColumn, 427 aAddr.StartRow, aAddr.EndColumn, aAddr.StartRow ); 428 429 xPropSet = (unoidl.com.sun.star.beans.XPropertySet) xCellRange; 430 xPropSet.setPropertyValue( 431 "CellBackColor", new uno.Any( (Int32) 0x99CCFF ) ); 432 // write headline 433 unoidl.com.sun.star.table.XCell xCell = 434 xCellRange.getCellByPosition( 0, 0 ); 435 xCell.setFormula( aHeadline ); 436 xPropSet = (unoidl.com.sun.star.beans.XPropertySet) xCell; 437 xPropSet.setPropertyValue( 438 "CharColor", new uno.Any( (Int32) 0x003399 ) ); 439 xPropSet.setPropertyValue( 440 "CharWeight", 441 new uno.Any( (Single) unoidl.com.sun.star.awt.FontWeight.BOLD ) ); 442 } 443 444 // ________________________________________________________________ 445 // Methods to create cell addresses and range addresses. 446 447 /** Creates a unoidl.com.sun.star.table.CellAddress and initializes it 448 with the given range. 449 @param xSheet The XSpreadsheet interface of the spreadsheet. 450 @param aCell The address of the cell (or a named cell). */ createCellAddress( unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aCell )451 public unoidl.com.sun.star.table.CellAddress createCellAddress( 452 unoidl.com.sun.star.sheet.XSpreadsheet xSheet, 453 String aCell ) 454 { 455 unoidl.com.sun.star.sheet.XCellAddressable xAddr = 456 (unoidl.com.sun.star.sheet.XCellAddressable) 457 xSheet.getCellRangeByName( aCell ).getCellByPosition( 0, 0 ); 458 return xAddr.getCellAddress(); 459 } 460 461 /** Creates a unoidl.com.sun.star.table.CellRangeAddress and initializes 462 it with the given range. 463 @param xSheet The XSpreadsheet interface of the spreadsheet. 464 @param aRange The address of the cell range (or a named range). */ createCellRangeAddress( unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aRange )465 public unoidl.com.sun.star.table.CellRangeAddress createCellRangeAddress( 466 unoidl.com.sun.star.sheet.XSpreadsheet xSheet, String aRange ) 467 { 468 unoidl.com.sun.star.sheet.XCellRangeAddressable xAddr = 469 (unoidl.com.sun.star.sheet.XCellRangeAddressable) 470 xSheet.getCellRangeByName( aRange ); 471 return xAddr.getRangeAddress(); 472 } 473 474 // ________________________________________________________________ 475 // Methods to convert cell addresses and range addresses to strings. 476 477 /** Returns the text address of the cell. 478 @param nColumn The column index. 479 @param nRow The row index. 480 @return A string containing the cell address. */ getCellAddressString( int nColumn, int nRow )481 public String getCellAddressString( int nColumn, int nRow ) 482 { 483 String aStr = ""; 484 if (nColumn > 25) 485 aStr += (char) ('A' + nColumn / 26 - 1); 486 aStr += (char) ('A' + nColumn % 26); 487 aStr += (nRow + 1); 488 return aStr; 489 } 490 491 /** Returns the text address of the cell range. 492 @param aCellRange The cell range address. 493 @return A string containing the cell range address. */ getCellRangeAddressString( unoidl.com.sun.star.table.CellRangeAddress aCellRange )494 public String getCellRangeAddressString( 495 unoidl.com.sun.star.table.CellRangeAddress aCellRange ) 496 { 497 return 498 getCellAddressString( aCellRange.StartColumn, aCellRange.StartRow ) 499 + ":" 500 + getCellAddressString( aCellRange.EndColumn, aCellRange.EndRow ); 501 } 502 503 /** Returns the text address of the cell range. 504 @param xCellRange The XSheetCellRange interface of the cell range. 505 @param bWithSheet true = Include sheet name. 506 @return A string containing the cell range address. */ getCellRangeAddressString( unoidl.com.sun.star.sheet.XSheetCellRange xCellRange, bool bWithSheet )507 public String getCellRangeAddressString( 508 unoidl.com.sun.star.sheet.XSheetCellRange xCellRange, bool bWithSheet ) 509 { 510 String aStr = ""; 511 if (bWithSheet) 512 { 513 unoidl.com.sun.star.sheet.XSpreadsheet xSheet = 514 xCellRange.getSpreadsheet(); 515 unoidl.com.sun.star.container.XNamed xNamed = 516 (unoidl.com.sun.star.container.XNamed) xSheet; 517 aStr += xNamed.getName() + "."; 518 } 519 unoidl.com.sun.star.sheet.XCellRangeAddressable xAddr = 520 (unoidl.com.sun.star.sheet.XCellRangeAddressable) xCellRange; 521 aStr += getCellRangeAddressString( xAddr.getRangeAddress() ); 522 return aStr; 523 } 524 525 /** Returns a list of addresses of all cell ranges contained in the 526 collection. 527 528 @param xRangesIA The XIndexAccess interface of the collection. 529 @return A string containing the cell range address list. */ getCellRangeListString( unoidl.com.sun.star.container.XIndexAccess xRangesIA )530 public String getCellRangeListString( 531 unoidl.com.sun.star.container.XIndexAccess xRangesIA ) 532 { 533 String aStr = ""; 534 int nCount = xRangesIA.getCount(); 535 for (int nIndex = 0; nIndex < nCount; ++nIndex) 536 { 537 if (nIndex > 0) 538 aStr += " "; 539 uno.Any aRangeObj = xRangesIA.getByIndex( nIndex ); 540 unoidl.com.sun.star.sheet.XSheetCellRange xCellRange = 541 (unoidl.com.sun.star.sheet.XSheetCellRange) aRangeObj.Value; 542 aStr += getCellRangeAddressString( xCellRange, false ); 543 } 544 return aStr; 545 } 546 547 // ________________________________________________________________ 548 549 /** Connect to a running office that is accepting connections. 550 @return The ServiceManager to instantiate office components. */ connect()551 private XMultiServiceFactory connect() 552 { 553 554 m_xContext = uno.util.Bootstrap.bootstrap(); 555 556 return (XMultiServiceFactory) m_xContext.getServiceManager(); 557 } 558 Dispose()559 public void Dispose() 560 { 561 562 } 563 564 /** Creates an empty spreadsheet document. 565 @return The XSpreadsheetDocument interface of the document. */ initDocument()566 private unoidl.com.sun.star.sheet.XSpreadsheetDocument initDocument() 567 { 568 XComponentLoader aLoader = (XComponentLoader) 569 mxMSFactory.createInstance( "com.sun.star.frame.Desktop" ); 570 571 XComponent xComponent = aLoader.loadComponentFromURL( 572 "private:factory/scalc", "_blank", 0, 573 new unoidl.com.sun.star.beans.PropertyValue[0] ); 574 575 return (unoidl.com.sun.star.sheet.XSpreadsheetDocument) xComponent; 576 } 577 578 terminate()579 public void terminate() 580 { 581 XModifiable xMod = (XModifiable) mxDocument; 582 if (xMod != null) 583 xMod.setModified(false); 584 XDesktop aDesktop = (XDesktop) 585 mxMSFactory.createInstance( "com.sun.star.frame.Desktop" ); 586 if (aDesktop != null) 587 { 588 try 589 { 590 aDesktop.terminate(); 591 } 592 catch (DisposedException d) 593 { 594 //This exception may be thrown because shutting down OOo using 595 //XDesktop terminate does not really work. In the case of the 596 //Exception OOo will still terminate. 597 } 598 } 599 } 600 601 // ________________________________________________________________ 602 } 603 604 } 605