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 #include <vbahelper/helperdecl.hxx>
25 #include <cppuhelper/queryinterface.hxx>
26
27 #include "vbaworksheet.hxx"
28
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/beans/XIntrospectionAccess.hpp>
31 #include <com/sun/star/beans/XIntrospection.hpp>
32 #include <com/sun/star/container/XNamed.hpp>
33 #include <com/sun/star/util/XProtectable.hpp>
34 #include <com/sun/star/table/XCellRange.hpp>
35 #include <com/sun/star/sheet/XSpreadsheetView.hpp>
36 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
37 #include <com/sun/star/sheet/XCalculatable.hpp>
38 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
39 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
40 #include <com/sun/star/sheet/XSheetCellRange.hpp>
41 #include <com/sun/star/sheet/XSheetCellCursor.hpp>
42 #include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
43 #include <com/sun/star/sheet/XUsedAreaCursor.hpp>
44 #include <com/sun/star/sheet/XSpreadsheets.hpp>
45 #include <com/sun/star/sheet/XSheetPastable.hpp>
46 #include <com/sun/star/sheet/XCellAddressable.hpp>
47 #include <com/sun/star/sheet/XSheetOutline.hpp>
48 #include <com/sun/star/sheet/XSheetPageBreak.hpp>
49 #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
50 #include <com/sun/star/sheet/XNamedRanges.hpp>
51 #include <com/sun/star/util/XURLTransformer.hpp>
52 #include <com/sun/star/frame/XDispatchProvider.hpp>
53 #include <com/sun/star/frame/XComponentLoader.hpp>
54 #include <com/sun/star/table/XColumnRowRange.hpp>
55 #include <com/sun/star/table/XTableChartsSupplier.hpp>
56 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
57 #include <com/sun/star/drawing/XControlShape.hpp>
58 #include <com/sun/star/form/FormComponentType.hpp>
59 #include <com/sun/star/form/XFormsSupplier.hpp>
60 #include <ooo/vba/excel/XlEnableSelection.hpp>
61 #include <ooo/vba/excel/XlSheetVisibility.hpp>
62 #include <ooo/vba/excel/XWorkbook.hpp>
63 #include <ooo/vba/XControlProvider.hpp>
64
65 #include <comphelper/processfactory.hxx>
66 #include <vbahelper/vbashapes.hxx>
67
68 #include <tools/string.hxx>
69
70 //zhangyun showdataform
71 #include <sfx2/sfxdlg.hxx>
72 #include "scabstdlg.hxx"
73 #include "tabvwsh.hxx"
74 #include "scitems.hxx"
75
76 #include <svx/svdouno.hxx>
77 #include <svx/svdpage.hxx>
78
79 #include "cellsuno.hxx"
80 #include "drwlayer.hxx"
81
82 #include "scextopt.hxx"
83 #include "vbaoutline.hxx"
84 #include "vbarange.hxx"
85 #include "vbacomments.hxx"
86 #include "vbachartobjects.hxx"
87 #include "vbapivottables.hxx"
88 #include "vbaoleobject.hxx"
89 #include "vbaoleobjects.hxx"
90 #include "vbapagesetup.hxx"
91 #include "vbapagebreaks.hxx"
92 #include "vbaworksheets.hxx"
93 #include "vbahyperlinks.hxx"
94 #include "vbasheetobjects.hxx"
95 #include "vbanames.hxx"
96
97 #define STANDARDWIDTH 2267
98 #define STANDARDHEIGHT 427
99 #define DOESNOTEXIST -1
100
101 using namespace com::sun::star;
102 using namespace ooo::vba;
103
104 // MS Excel VBA: Internal helper - generates a unique spreadsheet name.
105 // Status: internal helper
getNewSpreadsheetName(rtl::OUString & aNewName,rtl::OUString aOldName,uno::Reference<sheet::XSpreadsheetDocument> & xSpreadDoc)106 static void getNewSpreadsheetName (rtl::OUString &aNewName, rtl::OUString aOldName, uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc )
107 {
108 if (!xSpreadDoc.is())
109 throw lang::IllegalArgumentException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "getNewSpreadsheetName() xSpreadDoc is null" ) ), uno::Reference< uno::XInterface >(), 1 );
110 static rtl::OUString aUnderScre( RTL_CONSTASCII_USTRINGPARAM( "_" ) );
111 int currentNum =2;
112 aNewName = aOldName + aUnderScre+ String::CreateFromInt32(currentNum) ;
113 SCTAB nTab = 0;
114 while ( ScVbaWorksheets::nameExists(xSpreadDoc,aNewName, nTab ) )
115 {
116 aNewName = aOldName + aUnderScre +
117 String::CreateFromInt32(++currentNum) ;
118 }
119 }
120
121 // MS Excel VBA: Internal helper - removes all sheets and optionally renames the remaining one.
122 // Status: internal helper
removeAllSheets(uno::Reference<sheet::XSpreadsheetDocument> & xSpreadDoc,rtl::OUString aSheetName)123 static void removeAllSheets( uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc, rtl::OUString aSheetName)
124 {
125 if (!xSpreadDoc.is())
126 throw lang::IllegalArgumentException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "removeAllSheets() xSpreadDoc is null" ) ), uno::Reference< uno::XInterface >(), 1 );
127 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
128 uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
129
130 if ( xIndex.is() )
131 {
132 uno::Reference<container::XNameContainer> xNameContainer(xSheets,uno::UNO_QUERY_THROW);
133 for (sal_Int32 i = xIndex->getCount() -1; i>= 1; i--)
134 {
135 uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(i), uno::UNO_QUERY);
136 uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
137 if (xNamed.is())
138 {
139 xNameContainer->removeByName(xNamed->getName());
140 }
141 }
142
143 uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(0), uno::UNO_QUERY);
144 uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
145 if (xNamed.is())
146 {
147 xNamed->setName(aSheetName);
148 }
149 }
150 }
151
152 // MS Excel VBA: Internal helper - opens a new spreadsheet document.
153 // Status: internal helper
154 static uno::Reference<frame::XModel>
openNewDoc(rtl::OUString aSheetName)155 openNewDoc(rtl::OUString aSheetName )
156 {
157 uno::Reference<frame::XModel> xModel;
158 try
159 {
160 uno::Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
161 uno::Reference< uno::XComponentContext > xContext( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW );
162 uno::Reference<lang::XMultiComponentFactory > xServiceManager(
163 xContext->getServiceManager(), uno::UNO_QUERY_THROW );
164
165 uno::Reference <frame::XComponentLoader > xComponentLoader(
166 xServiceManager->createInstanceWithContext(
167 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ),
168 xContext ), uno::UNO_QUERY_THROW );
169
170 uno::Reference<lang::XComponent > xComponent( xComponentLoader->loadComponentFromURL(
171 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:factory/scalc" ) ),
172 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" ) ), 0,
173 uno::Sequence < ::com::sun::star::beans::PropertyValue >() ) );
174 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xComponent, uno::UNO_QUERY_THROW );
175 if ( xSpreadDoc.is() )
176 {
177 removeAllSheets(xSpreadDoc,aSheetName);
178 }
179 xModel.set(xSpreadDoc,uno::UNO_QUERY_THROW);
180 }
181 catch ( uno::Exception & /*e*/ )
182 {
183 }
184 return xModel;
185 }
186
187 // MS Excel VBA: Default constructor for Worksheet.
188 // Status: implemented
ScVbaWorksheet(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext)189 ScVbaWorksheet::ScVbaWorksheet( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext ) : WorksheetImpl_BASE( xParent, xContext ), mbVeryHidden( false )
190 {
191 }
192
193 // MS Excel VBA: Constructor taking a spreadsheet and model.
194 // Status: implemented
ScVbaWorksheet(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<sheet::XSpreadsheet> & xSheet,const uno::Reference<frame::XModel> & xModel)195 ScVbaWorksheet::ScVbaWorksheet(const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext,
196 const uno::Reference< sheet::XSpreadsheet >& xSheet,
197 const uno::Reference< frame::XModel >& xModel ) : WorksheetImpl_BASE( xParent, xContext ), mxSheet( xSheet ), mxModel(xModel), mbVeryHidden( false )
198 {
199 }
200
201 // MS Excel VBA: Constructor taking arguments sequence (for UNO create).
202 // Status: implemented
ScVbaWorksheet(uno::Sequence<uno::Any> const & args,uno::Reference<uno::XComponentContext> const & xContext)203 ScVbaWorksheet::ScVbaWorksheet( uno::Sequence< uno::Any> const & args,
204 uno::Reference< uno::XComponentContext> const & xContext ) : WorksheetImpl_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext ), mxModel( getXSomethingFromArgs< frame::XModel >( args, 1 ) ), mbVeryHidden( false )
205 {
206 if ( args.getLength() < 3 )
207 throw lang::IllegalArgumentException();
208
209 rtl::OUString sSheetName;
210 args[2] >>= sSheetName;
211
212 uno::Reference< sheet::XSpreadsheetDocument > xSpreadDoc( mxModel, uno::UNO_QUERY_THROW );
213 uno::Reference< container::XNameAccess > xNameAccess( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
214 mxSheet.set( xNameAccess->getByName( sSheetName ), uno::UNO_QUERY_THROW );
215 }
216
217 // MS Excel VBA: Destructor.
218 // Status: implemented
~ScVbaWorksheet()219 ScVbaWorksheet::~ScVbaWorksheet()
220 {
221 }
222
223 ::rtl::OUString
224 // MS Excel VBA: Gets the name of the worksheet.
225 // Status: implemented
getName()226 ScVbaWorksheet::getName()
227 {
228 uno::Reference< container::XNamed > xNamed( getSheet(), uno::UNO_QUERY_THROW );
229 return xNamed->getName();
230 }
231
232 void
233 // MS Excel VBA: Sets the name of the worksheet.
234 // Status: implemented
setName(const::rtl::OUString & rName)235 ScVbaWorksheet::setName(const ::rtl::OUString &rName )
236 {
237 uno::Reference< container::XNamed > xNamed( getSheet(), uno::UNO_QUERY_THROW );
238 xNamed->setName( rName );
239 }
240
241 sal_Int32
242 // MS Excel VBA: Gets the visibility of the worksheet.
243 // Status: implemented
getVisible()244 ScVbaWorksheet::getVisible()
245 {
246 uno::Reference< beans::XPropertySet > xProps( getSheet(), uno::UNO_QUERY_THROW );
247 bool bVisible = false;
248 xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) ) ) >>= bVisible;
249 using namespace ::ooo::vba::excel::XlSheetVisibility;
250 return bVisible ? xlSheetVisible : (mbVeryHidden ? xlSheetVeryHidden : xlSheetHidden);
251 }
252
253 void
254 // MS Excel VBA: Sets the visibility of the worksheet.
255 // Status: implemented
setVisible(sal_Int32 nVisible)256 ScVbaWorksheet::setVisible( sal_Int32 nVisible )
257 {
258 using namespace ::ooo::vba::excel::XlSheetVisibility;
259 bool bVisible = true;
260 switch( nVisible )
261 {
262 case xlSheetVisible: case 1: // Excel accepts -1 and 1 for visible sheets
263 bVisible = true;
264 mbVeryHidden = false;
265 break;
266 case xlSheetHidden:
267 bVisible = false;
268 mbVeryHidden = false;
269 break;
270 case xlSheetVeryHidden:
271 bVisible = false;
272 mbVeryHidden = true;
273 break;
274 default:
275 throw uno::RuntimeException();
276 }
277 uno::Reference< beans::XPropertySet > xProps( getSheet(), uno::UNO_QUERY_THROW );
278 xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) ), uno::Any( bVisible ) );
279 }
280
281 sal_Int16
282 // MS Excel VBA: Returns the 1-based index of the worksheet.
283 // Status: implemented
getIndex()284 ScVbaWorksheet::getIndex()
285 {
286 return getSheetID() + 1;
287 }
288
289 sal_Int32
290 // MS Excel VBA: Gets the selection enabled state for the worksheet.
291 // Status: implemented
getEnableSelection()292 ScVbaWorksheet::getEnableSelection()
293 {
294 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
295 SCTAB nTab = 0;
296 if ( ScVbaWorksheets::nameExists(xSpreadDoc, getName(), nTab) )
297 {
298 uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
299 ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument();
300 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
301 sal_Bool bLockedCells = sal_False;
302 sal_Bool bUnlockedCells = sal_False;
303 if( pProtect )
304 {
305 bLockedCells = pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
306 bUnlockedCells = pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
307 }
308 if( bLockedCells )
309 return excel::XlEnableSelection::xlNoRestrictions;
310 if( bUnlockedCells )
311 return excel::XlEnableSelection::xlUnlockedCells;
312 return excel::XlEnableSelection::xlNoSelection;
313 }
314 else
315 throw uno::RuntimeException(::rtl::OUString(
316 RTL_CONSTASCII_USTRINGPARAM( "Sheet Name does not exist. ") ),
317 uno::Reference< XInterface >() );
318 return excel::XlEnableSelection::xlNoSelection;
319 }
320
321
322 void
323 // MS Excel VBA: Sets the selection enabled state for the worksheet.
324 // Status: implemented
setEnableSelection(sal_Int32 nSelection)325 ScVbaWorksheet::setEnableSelection( sal_Int32 nSelection )
326 {
327 if( (nSelection != excel::XlEnableSelection::xlNoRestrictions) &&
328 (nSelection != excel::XlEnableSelection::xlUnlockedCells) &&
329 (nSelection != excel::XlEnableSelection::xlNoSelection) )
330 {
331 DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
332 }
333
334 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
335 SCTAB nTab = 0;
336 if ( ScVbaWorksheets::nameExists(xSpreadDoc, getName(), nTab) )
337 {
338 uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
339 ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument();
340 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
341 // default is xlNoSelection
342 sal_Bool bLockedCells = sal_False;
343 sal_Bool bUnlockedCells = sal_False;
344 if( nSelection == excel::XlEnableSelection::xlNoRestrictions )
345 {
346 bLockedCells = sal_True;
347 bUnlockedCells = sal_True;
348 }
349 else if( nSelection == excel::XlEnableSelection::xlUnlockedCells )
350 {
351 bUnlockedCells = sal_True;
352 }
353 if( pProtect )
354 {
355 pProtect->setOption( ScTableProtection::SELECT_LOCKED_CELLS, bLockedCells );
356 pProtect->setOption( ScTableProtection::SELECT_UNLOCKED_CELLS, bUnlockedCells );
357 }
358 }
359 else
360 throw uno::RuntimeException(::rtl::OUString(
361 RTL_CONSTASCII_USTRINGPARAM( "Sheet Name does not exist. ") ),
362 uno::Reference< XInterface >() );
363
364 }
365
366 // MS Excel VBA: Internal helper - gets first database range properties for the sheet.
367 // Status: internal helper
getFirstDBRangeProperties()368 uno::Reference< beans::XPropertySet > ScVbaWorksheet::getFirstDBRangeProperties()
369 {
370 uno::Reference< beans::XPropertySet > xModelProps( mxModel, uno::UNO_QUERY_THROW );
371 uno::Reference< container::XIndexAccess > xDBRangesIA( xModelProps->getPropertyValue(
372 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DatabaseRanges" ) ) ), uno::UNO_QUERY_THROW );
373
374 for( sal_Int32 nIndex = 0, nCount = xDBRangesIA->getCount(); nIndex < nCount; ++nIndex )
375 {
376 uno::Reference< sheet::XCellRangeReferrer > xDBRange( xDBRangesIA->getByIndex( nIndex ), uno::UNO_QUERY_THROW );
377 // check if the database area is on this sheet
378 uno::Reference< sheet::XCellRangeAddressable > xRangeAddr( xDBRange->getReferredCells(), uno::UNO_QUERY_THROW );
379 if( getSheetID() == xRangeAddr->getRangeAddress().Sheet )
380 return uno::Reference< beans::XPropertySet >( xDBRange, uno::UNO_QUERY_THROW );
381 }
382 return uno::Reference< beans::XPropertySet >();
383 }
384
385 // MS Excel VBA: Gets whether AutoFilter mode is enabled.
386 // Status: implemented
getAutoFilterMode()387 sal_Bool SAL_CALL ScVbaWorksheet::getAutoFilterMode()
388 {
389 uno::Reference< beans::XPropertySet > xDBRangeProps = getFirstDBRangeProperties();
390 sal_Bool bAutoFilterMode = sal_False;
391 return
392 xDBRangeProps.is() &&
393 (xDBRangeProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoFilter" ) ) ) >>= bAutoFilterMode) &&
394 bAutoFilterMode;
395 }
396
397 // MS Excel VBA: Sets whether AutoFilter mode is enabled.
398 // Status: implemented
setAutoFilterMode(sal_Bool bAutoFilterMode)399 void SAL_CALL ScVbaWorksheet::setAutoFilterMode( sal_Bool bAutoFilterMode )
400 {
401 uno::Reference< beans::XPropertySet > xDBRangeProps = getFirstDBRangeProperties();
402 if( xDBRangeProps.is() )
403 xDBRangeProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoFilter" ) ), uno::Any( bAutoFilterMode ) );
404 }
405
406 uno::Reference< excel::XRange >
407 // MS Excel VBA: Returns the used range of the worksheet.
408 // Status: implemented
getUsedRange()409 ScVbaWorksheet::getUsedRange()
410 {
411 uno::Reference< sheet::XSheetCellRange > xSheetCellRange(getSheet(), uno::UNO_QUERY_THROW );
412 uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor( getSheet()->createCursorByRange( xSheetCellRange ), uno::UNO_QUERY_THROW );
413 uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
414 xUsedCursor->gotoStartOfUsedArea( false );
415 xUsedCursor->gotoEndOfUsedArea( true );
416 uno::Reference< table::XCellRange > xRange( xSheetCellCursor, uno::UNO_QUERY);
417 return new ScVbaRange(this, mxContext, xRange);
418 }
419
420 uno::Reference< excel::XOutline >
421 // MS Excel VBA: Returns the outline for the worksheet.
422 // Status: stubbed - not fully implemented in Calc
Outline()423 ScVbaWorksheet::Outline( )
424 {
425 uno::Reference<sheet::XSheetOutline> xOutline(getSheet(),uno::UNO_QUERY_THROW);
426 return new ScVbaOutline( this, mxContext, xOutline);
427 }
428
429 uno::Reference< excel::XPageSetup >
430 // MS Excel VBA: Returns the page setup for the worksheet.
431 // Status: stubbed - not fully implemented in Calc
PageSetup()432 ScVbaWorksheet::PageSetup( )
433 {
434 return new ScVbaPageSetup( this, mxContext, getSheet(), getModel() );
435 }
436
437 uno::Any
438 // MS Excel VBA: Returns a HPageBreaks collection.
439 // Status: stubbed - not fully implemented in Calc
HPageBreaks(const uno::Any & aIndex)440 ScVbaWorksheet::HPageBreaks( const uno::Any& aIndex )
441 {
442 uno::Reference< sheet::XSheetPageBreak > xSheetPageBreak(getSheet(),uno::UNO_QUERY_THROW);
443 uno::Reference< excel::XHPageBreaks > xHPageBreaks( new ScVbaHPageBreaks( this, mxContext, xSheetPageBreak));
444 if ( aIndex.hasValue() )
445 return xHPageBreaks->Item( aIndex, uno::Any());
446 return uno::makeAny( xHPageBreaks );
447 }
448
449 uno::Any
450 // MS Excel VBA: Returns a VPageBreaks collection.
451 // Status: stubbed - not fully implemented in Calc
VPageBreaks(const uno::Any & aIndex)452 ScVbaWorksheet::VPageBreaks( const uno::Any& aIndex )
453 {
454 uno::Reference< sheet::XSheetPageBreak > xSheetPageBreak( getSheet(), uno::UNO_QUERY_THROW );
455 uno::Reference< excel::XVPageBreaks > xVPageBreaks( new ScVbaVPageBreaks( this, mxContext, xSheetPageBreak ) );
456 if( aIndex.hasValue() )
457 return xVPageBreaks->Item( aIndex, uno::Any());
458 return uno::makeAny( xVPageBreaks );
459 }
460
461 sal_Int32
462 // MS Excel VBA: Gets the standard column width.
463 // Status: implemented
getStandardWidth()464 ScVbaWorksheet::getStandardWidth()
465 {
466 return STANDARDWIDTH ;
467 }
468
469 sal_Int32
470 // MS Excel VBA: Gets the standard row height.
471 // Status: implemented
getStandardHeight()472 ScVbaWorksheet::getStandardHeight()
473 {
474 return STANDARDHEIGHT;
475 }
476
477 sal_Bool
478 // MS Excel VBA: Gets whether the worksheet is in protection mode.
479 // Status: implemented - always returns False
getProtectionMode()480 ScVbaWorksheet::getProtectionMode()
481 {
482 return sal_False;
483 }
484
485 sal_Bool
486 // MS Excel VBA: Gets whether contents are protected.
487 // Status: implemented
getProtectContents()488 ScVbaWorksheet::getProtectContents()
489 {
490 uno::Reference<util::XProtectable > xProtectable(getSheet(), uno::UNO_QUERY_THROW);
491 return xProtectable->isProtected();
492 }
493
494 sal_Bool
495 // MS Excel VBA: Gets whether drawing objects are protected.
496 // Status: implemented - always returns False
getProtectDrawingObjects()497 ScVbaWorksheet::getProtectDrawingObjects()
498 {
499 return sal_False;
500 }
501
502 sal_Bool
503 // MS Excel VBA: Gets whether scenarios are protected.
504 // Status: implemented - always returns False
getProtectScenarios()505 ScVbaWorksheet::getProtectScenarios()
506 {
507 return sal_False;
508 }
509
510 void
511 // MS Excel VBA: Activates the worksheet.
512 // Status: implemented
Activate()513 ScVbaWorksheet::Activate()
514 {
515 uno::Reference< sheet::XSpreadsheetView > xSpreadsheet(
516 getModel()->getCurrentController(), uno::UNO_QUERY_THROW );
517 xSpreadsheet->setActiveSheet(getSheet());
518 }
519
520 void
521 // MS Excel VBA: Selects the worksheet.
522 // Status: implemented
Select()523 ScVbaWorksheet::Select()
524 {
525 Activate();
526 }
527
528 void
529 // MS Excel VBA: Moves the worksheet to a new location.
530 // Status: implemented
Move(const uno::Any & Before,const uno::Any & After)531 ScVbaWorksheet::Move( const uno::Any& Before, const uno::Any& After )
532 {
533 uno::Reference<excel::XWorksheet> xSheet;
534 rtl::OUString aCurrSheetName = getName();
535
536 if (!(Before >>= xSheet) && !(After >>=xSheet)&& !(Before.hasValue()) && !(After.hasValue()))
537 {
538 uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = getSheet()->createCursor( );
539 uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
540 uno::Reference< table::XCellRange > xRange1( xSheetCellCursor, uno::UNO_QUERY);
541 // #FIXME needs worksheet as parent
542 uno::Reference<excel::XRange> xRange = new ScVbaRange( this, mxContext, xRange1);
543 if (xRange.is())
544 xRange->Select();
545 excel::implnCopy(mxModel);
546 uno::Reference<frame::XModel> xModel = openNewDoc(aCurrSheetName);
547 if (xModel.is())
548 {
549 excel::implnPaste(xModel);
550 Delete();
551 }
552 return ;
553 }
554
555 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
556 SCTAB nDest = 0;
557 if ( ScVbaWorksheets::nameExists (xSpreadDoc, xSheet->getName(), nDest) )
558 {
559 sal_Bool bAfter = After.hasValue();
560 if (bAfter)
561 nDest++;
562 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
563 xSheets->moveByName(aCurrSheetName,nDest);
564 }
565 }
566
567 void
568 // MS Excel VBA: Copies the worksheet to a new location.
569 // Status: implemented
Copy(const uno::Any & Before,const uno::Any & After)570 ScVbaWorksheet::Copy( const uno::Any& Before, const uno::Any& After )
571 {
572 uno::Reference<excel::XWorksheet> xSheet;
573 rtl::OUString aCurrSheetName =getName();
574 if (!(Before >>= xSheet) && !(After >>=xSheet)&& !(Before.hasValue()) && !(After.hasValue()))
575 {
576 uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = getSheet()->createCursor( );
577 uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
578 uno::Reference< table::XCellRange > xRange1( xSheetCellCursor, uno::UNO_QUERY);
579 uno::Reference<excel::XRange> xRange = new ScVbaRange( this, mxContext, xRange1);
580 if (xRange.is())
581 xRange->Select();
582 excel::implnCopy(mxModel);
583 uno::Reference<frame::XModel> xModel = openNewDoc(aCurrSheetName);
584 if (xModel.is())
585 {
586 excel::implnPaste(xModel);
587 }
588 return;
589 }
590
591 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY );
592 SCTAB nDest = 0;
593 rtl::OUString aSheetName = xSheet->getName();
594 if ( ScVbaWorksheets::nameExists (xSpreadDoc, aSheetName, nDest ) )
595 {
596 sal_Bool bAfter = After.hasValue();
597 if(bAfter)
598 nDest++;
599 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
600 getNewSpreadsheetName(aSheetName,aCurrSheetName,xSpreadDoc);
601 xSheets->copyByName(aCurrSheetName,aSheetName,nDest);
602 }
603 }
604
605
606 void
607 // MS Excel VBA: Pastes clipboard contents to the destination.
608 // Status: implemented
Paste(const uno::Any & Destination,const uno::Any &)609 ScVbaWorksheet::Paste( const uno::Any& Destination, const uno::Any& /*Link*/ )
610 {
611 // #TODO# #FIXME# Link is not used
612 uno::Reference<excel::XRange> xRange( Destination, uno::UNO_QUERY );
613 if ( xRange.is() )
614 xRange->Select();
615 excel::implnPaste( mxModel );
616 }
617
618 void
619 // MS Excel VBA: Deletes the worksheet.
620 // Status: implemented
Delete()621 ScVbaWorksheet::Delete()
622 {
623 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
624 rtl::OUString aSheetName = getName();
625 if ( xSpreadDoc.is() )
626 {
627 SCTAB nTab = 0;
628 if (!ScVbaWorksheets::nameExists(xSpreadDoc, aSheetName, nTab ))
629 {
630 return;
631 }
632 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
633 uno::Reference<container::XNameContainer> xNameContainer(xSheets,uno::UNO_QUERY_THROW);
634 xNameContainer->removeByName(aSheetName);
635 mxSheet.clear();
636 }
637 }
638
639 uno::Reference< excel::XWorksheet >
640 // MS Excel VBA: Internal helper - gets a worksheet by offset.
641 // Status: internal helper
getSheetAtOffset(SCTAB offset)642 ScVbaWorksheet::getSheetAtOffset(SCTAB offset)
643 {
644 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
645 uno::Reference <sheet::XSpreadsheets> xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
646 uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY_THROW );
647
648 SCTAB nIdx = 0;
649 if ( !ScVbaWorksheets::nameExists (xSpreadDoc, getName(), nIdx ) )
650 return uno::Reference< excel::XWorksheet >();
651 nIdx = nIdx + offset;
652 uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(nIdx), uno::UNO_QUERY_THROW);
653 // parent will be the parent of 'this' worksheet
654 return new ScVbaWorksheet (getParent(), mxContext, xSheet, getModel());
655 }
656
657 uno::Reference< excel::XWorksheet >
658 // MS Excel VBA: Returns the next worksheet.
659 // Status: implemented
getNext()660 ScVbaWorksheet::getNext()
661 {
662 return getSheetAtOffset(static_cast<SCTAB>(1));
663 }
664
665 uno::Reference< excel::XWorksheet >
666 // MS Excel VBA: Returns the previous worksheet.
667 // Status: implemented
getPrevious()668 ScVbaWorksheet::getPrevious()
669 {
670 return getSheetAtOffset(-1);
671 }
672
673
674 void
675 // MS Excel VBA: Protects the worksheet with a password.
676 // Status: implemented - partial (subset of options supported)
Protect(const uno::Any & Password,const uno::Any &,const uno::Any &,const uno::Any &,const uno::Any &)677 ScVbaWorksheet::Protect( const uno::Any& Password, const uno::Any& /*DrawingObjects*/, const uno::Any& /*Contents*/, const uno::Any& /*Scenarios*/, const uno::Any& /*UserInterfaceOnly*/ )
678 {
679 // #TODO# #FIXME# is there anything we can do with the unused param
680 // can the implementation use anything else here
681 uno::Reference<util::XProtectable > xProtectable(getSheet(), uno::UNO_QUERY_THROW);
682 ::rtl::OUString aPasswd;
683 Password >>= aPasswd;
684 xProtectable->protect( aPasswd );
685 }
686
687 void
688 // MS Excel VBA: Removes protection from the worksheet.
689 // Status: implemented
Unprotect(const uno::Any & Password)690 ScVbaWorksheet::Unprotect( const uno::Any& Password )
691 {
692 uno::Reference<util::XProtectable > xProtectable(getSheet(), uno::UNO_QUERY_THROW);
693 ::rtl::OUString aPasswd;
694 Password >>= aPasswd;
695 xProtectable->unprotect( aPasswd );
696 }
697
698 void
699 // MS Excel VBA: Calculates the worksheet.
700 // Status: implemented
Calculate()701 ScVbaWorksheet::Calculate()
702 {
703 uno::Reference <sheet::XCalculatable> xReCalculate(getModel(), uno::UNO_QUERY_THROW);
704 xReCalculate->calculate();
705 }
706
707 uno::Reference< excel::XRange >
708 // MS Excel VBA: Returns a Range object representing a cell or range.
709 // Status: implemented
Range(const::uno::Any & Cell1,const::uno::Any & Cell2)710 ScVbaWorksheet::Range( const ::uno::Any& Cell1, const ::uno::Any& Cell2 )
711 {
712 uno::Reference< excel::XRange > xSheetRange( new ScVbaRange( this, mxContext
713 , uno::Reference< table::XCellRange >( getSheet(), uno::UNO_QUERY_THROW ) ) );
714 return xSheetRange->Range( Cell1, Cell2 );
715 }
716
717 void
718 // MS Excel VBA: Checks spelling of the worksheet text.
719 // Status: implemented
CheckSpelling(const uno::Any &,const uno::Any &,const uno::Any &,const uno::Any &)720 ScVbaWorksheet::CheckSpelling( const uno::Any& /*CustomDictionary*/,const uno::Any& /*IgnoreUppercase*/,const uno::Any& /*AlwaysSuggest*/, const uno::Any& /*SpellingLang*/ )
721 {
722 // #TODO# #FIXME# unused params above, can we do anything with those
723 rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SpellDialog"));
724 uno::Reference< frame::XModel > xModel( getModel() );
725 dispatchRequests(xModel,url);
726 }
727
728 uno::Reference< excel::XRange >
729 // MS Excel VBA: Internal helper - gets the entire range of the sheet.
730 // Status: internal helper
getSheetRange()731 ScVbaWorksheet::getSheetRange()
732 {
733 uno::Reference< table::XCellRange > xRange( getSheet(),uno::UNO_QUERY_THROW );
734 return uno::Reference< excel::XRange >( new ScVbaRange( this, mxContext, xRange ) );
735 }
736
737 // These are hacks - we prolly (somehow) need to inherit
738 // the vbarange functionality here ...
739 uno::Reference< excel::XRange >
740 // MS Excel VBA: Returns a single cell or cell range.
741 // Status: implemented
Cells(const::uno::Any & nRow,const::uno::Any & nCol)742 ScVbaWorksheet::Cells( const ::uno::Any &nRow, const ::uno::Any &nCol )
743 {
744 // Performance optimization for often-called Cells method:
745 // Use a common helper method instead of creating a new ScVbaRange object
746 uno::Reference< table::XCellRange > xRange( getSheet(), uno::UNO_QUERY_THROW );
747 return ScVbaRange::CellsHelper( this, mxContext, xRange, nRow, nCol );
748 }
749
750 uno::Reference< excel::XRange >
751 // MS Excel VBA: Returns a single row or row range.
752 // Status: implemented
Rows(const uno::Any & aIndex)753 ScVbaWorksheet::Rows(const uno::Any& aIndex )
754 {
755 return getSheetRange()->Rows( aIndex );
756 }
757
758 uno::Reference< excel::XRange >
759 // MS Excel VBA: Returns a single column or column range.
760 // Status: implemented
Columns(const uno::Any & aIndex)761 ScVbaWorksheet::Columns( const uno::Any& aIndex )
762 {
763 return getSheetRange()->Columns( aIndex );
764 }
765
766 uno::Any SAL_CALL
767 // MS Excel VBA: Returns a ChartObject by index.
768 // Status: stubbed - not fully implemented in Calc
ChartObjects(const uno::Any & Index)769 ScVbaWorksheet::ChartObjects( const uno::Any& Index )
770 {
771 if ( !mxCharts.is() )
772 {
773 uno::Reference< table::XTableChartsSupplier > xChartSupplier( getSheet(), uno::UNO_QUERY_THROW );
774 uno::Reference< table::XTableCharts > xTableCharts = xChartSupplier->getCharts();
775
776 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxSheet, uno::UNO_QUERY_THROW );
777 mxCharts = new ScVbaChartObjects( this, mxContext, xTableCharts, xDrawPageSupplier );
778 }
779 if ( Index.hasValue() )
780 {
781 uno::Reference< XCollection > xColl( mxCharts, uno::UNO_QUERY_THROW );
782 return xColl->Item( Index, uno::Any() );
783 }
784 else
785 return uno::makeAny( mxCharts );
786
787 }
788
789 uno::Any SAL_CALL
790 // MS Excel VBA: Returns a PivotTable by index.
791 // Status: stubbed - not fully implemented in Calc
PivotTables(const uno::Any & Index)792 ScVbaWorksheet::PivotTables( const uno::Any& Index )
793 {
794 uno::Reference< css::sheet::XSpreadsheet > xSheet = getSheet();
795 uno::Reference< sheet::XDataPilotTablesSupplier > xTables(xSheet, uno::UNO_QUERY_THROW ) ;
796 uno::Reference< container::XIndexAccess > xIndexAccess( xTables->getDataPilotTables(), uno::UNO_QUERY_THROW );
797
798 uno::Reference< XCollection > xColl( new ScVbaPivotTables( this, mxContext, xIndexAccess ) );
799 if ( Index.hasValue() )
800 return xColl->Item( Index, uno::Any() );
801 return uno::makeAny( xColl );
802 }
803
804 uno::Any SAL_CALL
805 // MS Excel VBA: Returns a Comment by index.
806 // Status: implemented
Comments(const uno::Any & Index)807 ScVbaWorksheet::Comments( const uno::Any& Index )
808 {
809 uno::Reference< css::sheet::XSpreadsheet > xSheet = getSheet();
810 uno::Reference< sheet::XSheetAnnotationsSupplier > xAnnosSupp( xSheet, uno::UNO_QUERY_THROW );
811 uno::Reference< sheet::XSheetAnnotations > xAnnos( xAnnosSupp->getAnnotations(), uno::UNO_QUERY_THROW );
812 uno::Reference< container::XIndexAccess > xIndexAccess( xAnnos, uno::UNO_QUERY_THROW );
813 uno::Reference< XCollection > xColl( new ScVbaComments( this, mxContext, mxModel, xIndexAccess ) );
814 if ( Index.hasValue() )
815 return xColl->Item( Index, uno::Any() );
816 return uno::makeAny( xColl );
817 }
818
819 uno::Any SAL_CALL
820 // MS Excel VBA: Returns a Hyperlink by index.
821 // Status: implemented
Hyperlinks(const uno::Any & aIndex)822 ScVbaWorksheet::Hyperlinks( const uno::Any& aIndex )
823 {
824 /* The worksheet always returns the same Hyperlinks object.
825 See vbahyperlinks.hxx for more details. */
826 if( !mxHlinks.is() )
827 mxHlinks.set( new ScVbaHyperlinks( this, mxContext ) );
828 if( aIndex.hasValue() )
829 return uno::Reference< XCollection >( mxHlinks, uno::UNO_QUERY_THROW )->Item( aIndex, uno::Any() );
830 return uno::Any( mxHlinks );
831 }
832
833 uno::Any SAL_CALL
834 // MS Excel VBA: Returns a Name object by index (uses all global names).
835 // Status: implemented - partial (no sheet-local names)
Names(const css::uno::Any & aIndex)836 ScVbaWorksheet::Names( const css::uno::Any& aIndex )
837 {
838 // fake sheet-local names by returning all global names
839 // #163498# initialize Names object with correct parent (this worksheet)
840 // TODO: real sheet-local names...
841 uno::Reference< beans::XPropertySet > xProps( mxModel, uno::UNO_QUERY_THROW );
842 uno::Reference< sheet::XNamedRanges > xNamedRanges( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NamedRanges") ) ), uno::UNO_QUERY_THROW );
843 uno::Reference< XCollection > xNames( new ScVbaNames( this, mxContext, xNamedRanges, mxModel ) );
844 if ( aIndex.hasValue() )
845 return uno::Any( xNames->Item( aIndex, uno::Any() ) );
846 return uno::Any( xNames );
847 }
848
849 uno::Any SAL_CALL
850 // MS Excel VBA: Returns an OLEObject by index.
851 // Status: stubbed - not fully implemented in Calc
OLEObjects(const uno::Any & Index)852 ScVbaWorksheet::OLEObjects( const uno::Any& Index )
853 {
854 uno::Reference< sheet::XSpreadsheet > xSpreadsheet( getSheet(), uno::UNO_QUERY_THROW );
855 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xSpreadsheet, uno::UNO_QUERY_THROW );
856 uno::Reference< drawing::XDrawPage > xDrawPage( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
857 uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPage, uno::UNO_QUERY_THROW );
858
859 uno::Reference< excel::XOLEObjects >xOleObjects( new ScVbaOLEObjects( this, mxContext, xIndexAccess ) );
860 if( Index.hasValue() )
861 return xOleObjects->Item( Index, uno::Any() );
862 return uno::Any( xOleObjects );
863 }
864
865 uno::Any SAL_CALL
866 // MS Excel VBA: Returns a Shape object by index.
867 // Status: implemented
Shapes(const uno::Any & aIndex)868 ScVbaWorksheet::Shapes( const uno::Any& aIndex )
869 {
870 uno::Reference< sheet::XSpreadsheet > xSpreadsheet( getSheet(), uno::UNO_QUERY_THROW );
871 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xSpreadsheet, uno::UNO_QUERY_THROW );
872 uno::Reference< drawing::XShapes > xShapes( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
873 uno::Reference< container::XIndexAccess > xIndexAccess( xShapes, uno::UNO_QUERY_THROW );
874
875 uno::Reference< msforms::XShapes> xVbaShapes( new ScVbaShapes( this, mxContext, xIndexAccess, getModel() ) );
876 if ( aIndex.hasValue() )
877 return xVbaShapes->Item( aIndex, uno::Any() );
878 return uno::makeAny( xVbaShapes );
879 }
880
881 uno::Any SAL_CALL
882 // MS Excel VBA: Returns Button controls on the worksheet.
883 // Status: not implemented in Calc
Buttons(const uno::Any & rIndex)884 ScVbaWorksheet::Buttons( const uno::Any& rIndex )
885 {
886 if( !mxButtons.is() )
887 mxButtons.set( new ScVbaButtons( this, mxContext, mxModel, mxSheet ) );
888 else
889 mxButtons->collectShapes();
890 if( rIndex.hasValue() )
891 return mxButtons->Item( rIndex, uno::Any() );
892 return uno::Any( uno::Reference< XCollection >( mxButtons.get() ) );
893 }
894
895 uno::Any SAL_CALL
896 // MS Excel VBA: Returns CheckBox controls on the worksheet.
897 // Status: not implemented in Calc
CheckBoxes(const uno::Any &)898 ScVbaWorksheet::CheckBoxes( const uno::Any& /*rIndex*/ )
899 {
900 throw uno::RuntimeException();
901 }
902
903 uno::Any SAL_CALL
904 // MS Excel VBA: Returns DropDown controls on the worksheet.
905 // Status: not implemented in Calc
DropDowns(const uno::Any &)906 ScVbaWorksheet::DropDowns( const uno::Any& /*rIndex*/ )
907 {
908 throw uno::RuntimeException();
909 }
910
911 uno::Any SAL_CALL
912 // MS Excel VBA: Returns GroupBox controls on the worksheet.
913 // Status: not implemented in Calc
GroupBoxes(const uno::Any &)914 ScVbaWorksheet::GroupBoxes( const uno::Any& /*rIndex*/ )
915 {
916 throw uno::RuntimeException();
917 }
918
919 uno::Any SAL_CALL
920 // MS Excel VBA: Returns Label controls on the worksheet.
921 // Status: not implemented in Calc
Labels(const uno::Any &)922 ScVbaWorksheet::Labels( const uno::Any& /*rIndex*/ )
923 {
924 throw uno::RuntimeException();
925 }
926
927 uno::Any SAL_CALL
928 // MS Excel VBA: Returns ListBox controls on the worksheet.
929 // Status: not implemented in Calc
ListBoxes(const uno::Any &)930 ScVbaWorksheet::ListBoxes( const uno::Any& /*rIndex*/ )
931 {
932 throw uno::RuntimeException();
933 }
934
935 uno::Any SAL_CALL
936 // MS Excel VBA: Returns OptionButton controls on the worksheet.
937 // Status: not implemented in Calc
OptionButtons(const uno::Any &)938 ScVbaWorksheet::OptionButtons( const uno::Any& /*rIndex*/ )
939 {
940 throw uno::RuntimeException();
941 }
942
943 uno::Any SAL_CALL
944 // MS Excel VBA: Returns ScrollBars control objects on the worksheet.
945 // Status: not implemented in Calc
ScrollBars(const uno::Any &)946 ScVbaWorksheet::ScrollBars( const uno::Any& /*rIndex*/ )
947 {
948 throw uno::RuntimeException();
949 }
950
951 uno::Any SAL_CALL
952 // MS Excel VBA: Returns Spinners control objects on the worksheet.
953 // Status: not implemented in Calc
Spinners(const uno::Any &)954 ScVbaWorksheet::Spinners( const uno::Any& /*rIndex*/ )
955 {
956 throw uno::RuntimeException();
957 }
958
959 void SAL_CALL
960 // MS Excel VBA: Displays the data form for entering/editing data.
961 // Status: partial (only in OO build with VBA_OOBUILD_HACK)
ShowDataForm()962 ScVbaWorksheet::ShowDataForm( )
963 {
964 #ifdef VBA_OOBUILD_HACK
965 uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
966 ScTabViewShell* pTabViewShell = excel::getBestViewShell( xModel );
967
968 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
969 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
970
971 AbstractScDataFormDlg* pDlg = pFact->CreateScDataFormDlg( pTabViewShell->GetDialogParent(),RID_SCDLG_DATAFORM, pTabViewShell);
972 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
973
974 pDlg->Execute();
975 #else
976 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
977 #endif
978 }
979
980 uno::Any SAL_CALL
981 // MS Excel VBA: Evaluates an Excel formula expression.
982 // Status: implemented
Evaluate(const::rtl::OUString & Name)983 ScVbaWorksheet::Evaluate( const ::rtl::OUString& Name )
984 {
985 // #TODO Evaluate allows other things to be evaluated, e.g. functions
986 // I think ( like SIN(3) etc. ) need to investigate that
987 // named Ranges also? e.g. [MyRange] if so need a list of named ranges
988 uno::Any aVoid;
989 return uno::Any( Range( uno::Any( Name ), aVoid ) );
990 }
991
992
993 uno::Reference< beans::XIntrospectionAccess > SAL_CALL
994 // MS Excel VBA: Returns introspection access (XInvocation).
995 // Status: implemented - returns empty reference
getIntrospection()996 ScVbaWorksheet::getIntrospection( )
997 {
998 return uno::Reference< beans::XIntrospectionAccess >();
999 }
1000
1001 uno::Any SAL_CALL
invoke(const::rtl::OUString & aFunctionName,const uno::Sequence<uno::Any> &,uno::Sequence<::sal_Int16> &,uno::Sequence<uno::Any> &)1002 ScVbaWorksheet::invoke( const ::rtl::OUString& aFunctionName, const uno::Sequence< uno::Any >& /*aParams*/, uno::Sequence< ::sal_Int16 >& /*aOutParamIndex*/, uno::Sequence< uno::Any >& /*aOutParam*/ )
1003 {
1004 // MS Excel VBA: Invokes a method by name (XInvocation).
1005 // Status: stubbed - throws RuntimeException
1006 OSL_TRACE("** ScVbaWorksheet::invoke( %s ), will barf",
1007 rtl::OUStringToOString( aFunctionName, RTL_TEXTENCODING_UTF8 ).getStr() );
1008
1009 throw uno::RuntimeException(); // unsupported operation
1010 }
1011
1012 void SAL_CALL
1013 // MS Excel VBA: Sets the value of a property by name.
1014 // Status: implemented
setValue(const::rtl::OUString & aPropertyName,const uno::Any & aValue)1015 ScVbaWorksheet::setValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue )
1016 {
1017 setDefaultPropByIntrospection( uno::makeAny( getValue( aPropertyName ) ), aValue );
1018 }
1019 uno::Any SAL_CALL
1020 // MS Excel VBA: Gets the value of a property by name.
1021 // Status: implemented
getValue(const::rtl::OUString & aPropertyName)1022 ScVbaWorksheet::getValue( const ::rtl::OUString& aPropertyName )
1023 {
1024 uno::Reference< drawing::XControlShape > xControlShape( getControlShape( aPropertyName ), uno::UNO_QUERY_THROW );
1025
1026 uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
1027 uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.ControlProvider" ) ), mxContext ), uno::UNO_QUERY_THROW );
1028 uno::Reference< msforms::XControl > xControl( xControlProvider->createControl( xControlShape, getModel() ) );
1029 return uno::makeAny( xControl );
1030 }
1031
1032 ::sal_Bool SAL_CALL
1033 // MS Excel VBA: Indicates if a method exists on this object.
1034 // Status: implemented - always returns False
hasMethod(const::rtl::OUString &)1035 ScVbaWorksheet::hasMethod( const ::rtl::OUString& /*aName*/ )
1036 {
1037 return sal_False;
1038 }
1039
1040 uno::Reference< container::XNameAccess >
1041 // MS Excel VBA: Internal helper - gets form controls of the sheet.
1042 // Status: internal helper
getFormControls()1043 ScVbaWorksheet::getFormControls()
1044 {
1045 uno::Reference< container::XNameAccess > xFormControls;
1046 try
1047 {
1048 uno::Reference< sheet::XSpreadsheet > xSpreadsheet( getSheet(), uno::UNO_QUERY_THROW );
1049 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xSpreadsheet, uno::UNO_QUERY_THROW );
1050 uno::Reference< form::XFormsSupplier > xFormSupplier( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
1051 uno::Reference< container::XIndexAccess > xIndexAccess( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
1052 // get the www-standard container ( maybe we should access the
1053 // 'www-standard' by name rather than index, this seems an
1054 // implementation detail
1055 if( xIndexAccess->hasElements() )
1056 xFormControls.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY );
1057
1058 }
1059 catch( uno::Exception& )
1060 {
1061 }
1062 return xFormControls;
1063
1064 }
1065 ::sal_Bool SAL_CALL
1066 // MS Excel VBA: Indicates if a property exists on this object.
1067 // Status: implemented
hasProperty(const::rtl::OUString & aName)1068 ScVbaWorksheet::hasProperty( const ::rtl::OUString& aName )
1069 {
1070 uno::Reference< container::XNameAccess > xFormControls( getFormControls() );
1071 if ( xFormControls.is() )
1072 return xFormControls->hasByName( aName );
1073 return sal_False;
1074 }
1075
1076 uno::Any
1077 // MS Excel VBA: Internal helper - gets a control shape by name.
1078 // Status: internal helper
getControlShape(const::rtl::OUString & sName)1079 ScVbaWorksheet::getControlShape( const ::rtl::OUString& sName )
1080 {
1081 // ideally we would get an XControl object but it appears an XControl
1082 // implementation only exists for a Control implementation obtained from the
1083 // view ( e.g. in basic you would get this from
1084 // thiscomponent.currentcontroller.getControl( controlModel ) )
1085 // and the thing to realise is that it is only possible to get an XControl
1086 // for a currently displayed control :-( often we would want to modify
1087 // a control not on the active sheet. But.. you can always access the
1088 // XControlShape from the DrawPage whether that is the active drawpage or not
1089
1090 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( getSheet(), uno::UNO_QUERY_THROW );
1091 uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
1092
1093 sal_Int32 nCount = xIndexAccess->getCount();
1094 for( int index = 0; index < nCount; index++ )
1095 {
1096 uno::Any aUnoObj = xIndexAccess->getByIndex( index );
1097 // It seems there are some drawing objects that can not query into Control shapes?
1098 uno::Reference< drawing::XControlShape > xControlShape( aUnoObj, uno::UNO_QUERY );
1099 if( xControlShape.is() )
1100 {
1101 uno::Reference< container::XNamed > xNamed( xControlShape->getControl(), uno::UNO_QUERY_THROW );
1102 if( sName.equals( xNamed->getName() ))
1103 {
1104 return aUnoObj;
1105 }
1106 }
1107 }
1108 return uno::Any();
1109 }
1110
1111
1112 rtl::OUString&
1113 // MS Excel VBA: Returns the implementation service name for UNO.
1114 // Status: implemented
getServiceImplName()1115 ScVbaWorksheet::getServiceImplName()
1116 {
1117 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaWorksheet") );
1118 return sImplName;
1119 }
1120 void SAL_CALL
1121 // MS Excel VBA: Sets whether automatic calculation is enabled.
1122 // Status: implemented
setEnableCalculation(::sal_Bool bEnableCalculation)1123 ScVbaWorksheet::setEnableCalculation( ::sal_Bool bEnableCalculation )
1124 {
1125 uno::Reference <sheet::XCalculatable> xCalculatable(getModel(), uno::UNO_QUERY_THROW);
1126 xCalculatable->enableAutomaticCalculation( bEnableCalculation);
1127 }
1128 ::sal_Bool SAL_CALL
1129 // MS Excel VBA: Gets whether automatic calculation is enabled.
1130 // Status: implemented
getEnableCalculation()1131 ScVbaWorksheet::getEnableCalculation( )
1132 {
1133 uno::Reference <sheet::XCalculatable> xCalculatable(getModel(), uno::UNO_QUERY_THROW);
1134 return xCalculatable->isAutomaticCalculationEnabled();
1135 }
1136
1137 uno::Sequence< rtl::OUString >
1138 // MS Excel VBA: Returns the list of supported service names for UNO.
1139 // Status: implemented
getServiceNames()1140 ScVbaWorksheet::getServiceNames()
1141 {
1142 static uno::Sequence< rtl::OUString > aServiceNames;
1143 if ( aServiceNames.getLength() == 0 )
1144 {
1145 aServiceNames.realloc( 1 );
1146 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Worksheet" ) );
1147 }
1148 return aServiceNames;
1149 }
1150
1151 rtl::OUString SAL_CALL
1152 // MS Excel VBA: Returns the code name of the worksheet.
1153 // Status: implemented
getCodeName()1154 ScVbaWorksheet::getCodeName()
1155 {
1156 uno::Reference< beans::XPropertySet > xSheetProp( mxSheet, uno::UNO_QUERY_THROW );
1157 return xSheetProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CodeName" ) ) ).get< ::rtl::OUString >();
1158 }
1159
1160 sal_Int16
1161 // MS Excel VBA: Returns the sheet ID for this worksheet.
1162 // Status: implemented
getSheetID()1163 ScVbaWorksheet::getSheetID()
1164 {
1165 uno::Reference< sheet::XCellRangeAddressable > xAddressable( mxSheet, uno::UNO_QUERY_THROW );
1166 return xAddressable->getRangeAddress().Sheet;
1167 }
1168
1169 void SAL_CALL
1170 // MS Excel VBA: Prints the worksheet.
1171 // Status: implemented
PrintOut(const uno::Any & From,const uno::Any & To,const uno::Any & Copies,const uno::Any & Preview,const uno::Any & ActivePrinter,const uno::Any & PrintToFile,const uno::Any & Collate,const uno::Any & PrToFileName,const uno::Any & IgnorePrintAreas)1172 ScVbaWorksheet::PrintOut( const uno::Any& From, const uno::Any& To, const uno::Any& Copies, const uno::Any& Preview, const uno::Any& ActivePrinter, const uno::Any& PrintToFile, const uno::Any& Collate, const uno::Any& PrToFileName, const uno::Any& IgnorePrintAreas )
1173 {
1174 sal_Int32 nTo = 0;
1175 sal_Int32 nFrom = 0;
1176 sal_Int16 nCopies = 1;
1177 sal_Bool bCollate = sal_False;
1178 sal_Bool bSelection = sal_False;
1179 sal_Bool bIgnorePrintAreas = sal_False;
1180 From >>= nFrom;
1181 To >>= nTo;
1182 Copies >>= nCopies;
1183 IgnorePrintAreas >>= bIgnorePrintAreas;
1184 if ( nCopies > 1 ) // Collate only useful when more that 1 copy
1185 Collate >>= bCollate;
1186
1187 if ( !( nFrom || nTo ) )
1188 bSelection = sal_True;
1189
1190 uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
1191 PrintOutHelper( excel::getBestViewShell( xModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, bSelection );
1192 }
1193
1194 namespace worksheet
1195 {
1196 namespace sdecl = comphelper::service_decl;
1197 sdecl::vba_service_class_<ScVbaWorksheet, sdecl::with_args<true> > serviceImpl;
1198 extern sdecl::ServiceDecl const serviceDecl(
1199 serviceImpl,
1200 "ScVbaWorksheet",
1201 "ooo.vba.excel.Worksheet" );
1202 }
1203