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
getNewSpreadsheetName(rtl::OUString & aNewName,rtl::OUString aOldName,uno::Reference<sheet::XSpreadsheetDocument> & xSpreadDoc)104 static void getNewSpreadsheetName (rtl::OUString &aNewName, rtl::OUString aOldName, uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc )
105 {
106 if (!xSpreadDoc.is())
107 throw lang::IllegalArgumentException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "getNewSpreadsheetName() xSpreadDoc is null" ) ), uno::Reference< uno::XInterface >(), 1 );
108 static rtl::OUString aUnderScre( RTL_CONSTASCII_USTRINGPARAM( "_" ) );
109 int currentNum =2;
110 aNewName = aOldName + aUnderScre+ String::CreateFromInt32(currentNum) ;
111 SCTAB nTab = 0;
112 while ( ScVbaWorksheets::nameExists(xSpreadDoc,aNewName, nTab ) )
113 {
114 aNewName = aOldName + aUnderScre +
115 String::CreateFromInt32(++currentNum) ;
116 }
117 }
118
removeAllSheets(uno::Reference<sheet::XSpreadsheetDocument> & xSpreadDoc,rtl::OUString aSheetName)119 static void removeAllSheets( uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc, rtl::OUString aSheetName)
120 {
121 if (!xSpreadDoc.is())
122 throw lang::IllegalArgumentException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "removeAllSheets() xSpreadDoc is null" ) ), uno::Reference< uno::XInterface >(), 1 );
123 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
124 uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY );
125
126 if ( xIndex.is() )
127 {
128 uno::Reference<container::XNameContainer> xNameContainer(xSheets,uno::UNO_QUERY_THROW);
129 for (sal_Int32 i = xIndex->getCount() -1; i>= 1; i--)
130 {
131 uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(i), uno::UNO_QUERY);
132 uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
133 if (xNamed.is())
134 {
135 xNameContainer->removeByName(xNamed->getName());
136 }
137 }
138
139 uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(0), uno::UNO_QUERY);
140 uno::Reference< container::XNamed > xNamed( xSheet, uno::UNO_QUERY_THROW );
141 if (xNamed.is())
142 {
143 xNamed->setName(aSheetName);
144 }
145 }
146 }
147
148 static uno::Reference<frame::XModel>
openNewDoc(rtl::OUString aSheetName)149 openNewDoc(rtl::OUString aSheetName )
150 {
151 uno::Reference<frame::XModel> xModel;
152 try
153 {
154 uno::Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
155 uno::Reference< uno::XComponentContext > xContext( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW );
156 uno::Reference<lang::XMultiComponentFactory > xServiceManager(
157 xContext->getServiceManager(), uno::UNO_QUERY_THROW );
158
159 uno::Reference <frame::XComponentLoader > xComponentLoader(
160 xServiceManager->createInstanceWithContext(
161 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ),
162 xContext ), uno::UNO_QUERY_THROW );
163
164 uno::Reference<lang::XComponent > xComponent( xComponentLoader->loadComponentFromURL(
165 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:factory/scalc" ) ),
166 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" ) ), 0,
167 uno::Sequence < ::com::sun::star::beans::PropertyValue >() ) );
168 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xComponent, uno::UNO_QUERY_THROW );
169 if ( xSpreadDoc.is() )
170 {
171 removeAllSheets(xSpreadDoc,aSheetName);
172 }
173 xModel.set(xSpreadDoc,uno::UNO_QUERY_THROW);
174 }
175 catch ( uno::Exception & /*e*/ )
176 {
177 }
178 return xModel;
179 }
180
ScVbaWorksheet(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext)181 ScVbaWorksheet::ScVbaWorksheet( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext ) : WorksheetImpl_BASE( xParent, xContext ), mbVeryHidden( false )
182 {
183 }
184
ScVbaWorksheet(const uno::Reference<XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<sheet::XSpreadsheet> & xSheet,const uno::Reference<frame::XModel> & xModel)185 ScVbaWorksheet::ScVbaWorksheet(const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext,
186 const uno::Reference< sheet::XSpreadsheet >& xSheet,
187 const uno::Reference< frame::XModel >& xModel ) : WorksheetImpl_BASE( xParent, xContext ), mxSheet( xSheet ), mxModel(xModel), mbVeryHidden( false )
188 {
189 }
190
ScVbaWorksheet(uno::Sequence<uno::Any> const & args,uno::Reference<uno::XComponentContext> const & xContext)191 ScVbaWorksheet::ScVbaWorksheet( uno::Sequence< uno::Any> const & args,
192 uno::Reference< uno::XComponentContext> const & xContext ) : WorksheetImpl_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext ), mxModel( getXSomethingFromArgs< frame::XModel >( args, 1 ) ), mbVeryHidden( false )
193 {
194 if ( args.getLength() < 3 )
195 throw lang::IllegalArgumentException();
196
197 rtl::OUString sSheetName;
198 args[2] >>= sSheetName;
199
200 uno::Reference< sheet::XSpreadsheetDocument > xSpreadDoc( mxModel, uno::UNO_QUERY_THROW );
201 uno::Reference< container::XNameAccess > xNameAccess( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
202 mxSheet.set( xNameAccess->getByName( sSheetName ), uno::UNO_QUERY_THROW );
203 }
204
~ScVbaWorksheet()205 ScVbaWorksheet::~ScVbaWorksheet()
206 {
207 }
208
209 ::rtl::OUString
getName()210 ScVbaWorksheet::getName()
211 {
212 uno::Reference< container::XNamed > xNamed( getSheet(), uno::UNO_QUERY_THROW );
213 return xNamed->getName();
214 }
215
216 void
setName(const::rtl::OUString & rName)217 ScVbaWorksheet::setName(const ::rtl::OUString &rName )
218 {
219 uno::Reference< container::XNamed > xNamed( getSheet(), uno::UNO_QUERY_THROW );
220 xNamed->setName( rName );
221 }
222
223 sal_Int32
getVisible()224 ScVbaWorksheet::getVisible()
225 {
226 uno::Reference< beans::XPropertySet > xProps( getSheet(), uno::UNO_QUERY_THROW );
227 bool bVisible = false;
228 xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) ) ) >>= bVisible;
229 using namespace ::ooo::vba::excel::XlSheetVisibility;
230 return bVisible ? xlSheetVisible : (mbVeryHidden ? xlSheetVeryHidden : xlSheetHidden);
231 }
232
233 void
setVisible(sal_Int32 nVisible)234 ScVbaWorksheet::setVisible( sal_Int32 nVisible )
235 {
236 using namespace ::ooo::vba::excel::XlSheetVisibility;
237 bool bVisible = true;
238 switch( nVisible )
239 {
240 case xlSheetVisible: case 1: // Excel accepts -1 and 1 for visible sheets
241 bVisible = true;
242 mbVeryHidden = false;
243 break;
244 case xlSheetHidden:
245 bVisible = false;
246 mbVeryHidden = false;
247 break;
248 case xlSheetVeryHidden:
249 bVisible = false;
250 mbVeryHidden = true;
251 break;
252 default:
253 throw uno::RuntimeException();
254 }
255 uno::Reference< beans::XPropertySet > xProps( getSheet(), uno::UNO_QUERY_THROW );
256 xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsVisible" ) ), uno::Any( bVisible ) );
257 }
258
259 sal_Int16
getIndex()260 ScVbaWorksheet::getIndex()
261 {
262 return getSheetID() + 1;
263 }
264
265 sal_Int32
getEnableSelection()266 ScVbaWorksheet::getEnableSelection()
267 {
268 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
269 SCTAB nTab = 0;
270 if ( ScVbaWorksheets::nameExists(xSpreadDoc, getName(), nTab) )
271 {
272 uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
273 ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument();
274 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
275 sal_Bool bLockedCells = sal_False;
276 sal_Bool bUnlockedCells = sal_False;
277 if( pProtect )
278 {
279 bLockedCells = pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
280 bUnlockedCells = pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
281 }
282 if( bLockedCells )
283 return excel::XlEnableSelection::xlNoRestrictions;
284 if( bUnlockedCells )
285 return excel::XlEnableSelection::xlUnlockedCells;
286 return excel::XlEnableSelection::xlNoSelection;
287 }
288 else
289 throw uno::RuntimeException(::rtl::OUString(
290 RTL_CONSTASCII_USTRINGPARAM( "Sheet Name does not exist. ") ),
291 uno::Reference< XInterface >() );
292 return excel::XlEnableSelection::xlNoSelection;
293 }
294
295
296 void
setEnableSelection(sal_Int32 nSelection)297 ScVbaWorksheet::setEnableSelection( sal_Int32 nSelection )
298 {
299 if( (nSelection != excel::XlEnableSelection::xlNoRestrictions) &&
300 (nSelection != excel::XlEnableSelection::xlUnlockedCells) &&
301 (nSelection != excel::XlEnableSelection::xlNoSelection) )
302 {
303 DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
304 }
305
306 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
307 SCTAB nTab = 0;
308 if ( ScVbaWorksheets::nameExists(xSpreadDoc, getName(), nTab) )
309 {
310 uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
311 ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument();
312 ScTableProtection* pProtect = pDoc->GetTabProtection(nTab);
313 // default is xlNoSelection
314 sal_Bool bLockedCells = sal_False;
315 sal_Bool bUnlockedCells = sal_False;
316 if( nSelection == excel::XlEnableSelection::xlNoRestrictions )
317 {
318 bLockedCells = sal_True;
319 bUnlockedCells = sal_True;
320 }
321 else if( nSelection == excel::XlEnableSelection::xlUnlockedCells )
322 {
323 bUnlockedCells = sal_True;
324 }
325 if( pProtect )
326 {
327 pProtect->setOption( ScTableProtection::SELECT_LOCKED_CELLS, bLockedCells );
328 pProtect->setOption( ScTableProtection::SELECT_UNLOCKED_CELLS, bUnlockedCells );
329 }
330 }
331 else
332 throw uno::RuntimeException(::rtl::OUString(
333 RTL_CONSTASCII_USTRINGPARAM( "Sheet Name does not exist. ") ),
334 uno::Reference< XInterface >() );
335
336 }
337
getFirstDBRangeProperties()338 uno::Reference< beans::XPropertySet > ScVbaWorksheet::getFirstDBRangeProperties()
339 {
340 uno::Reference< beans::XPropertySet > xModelProps( mxModel, uno::UNO_QUERY_THROW );
341 uno::Reference< container::XIndexAccess > xDBRangesIA( xModelProps->getPropertyValue(
342 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DatabaseRanges" ) ) ), uno::UNO_QUERY_THROW );
343
344 for( sal_Int32 nIndex = 0, nCount = xDBRangesIA->getCount(); nIndex < nCount; ++nIndex )
345 {
346 uno::Reference< sheet::XCellRangeReferrer > xDBRange( xDBRangesIA->getByIndex( nIndex ), uno::UNO_QUERY_THROW );
347 // check if the database area is on this sheet
348 uno::Reference< sheet::XCellRangeAddressable > xRangeAddr( xDBRange->getReferredCells(), uno::UNO_QUERY_THROW );
349 if( getSheetID() == xRangeAddr->getRangeAddress().Sheet )
350 return uno::Reference< beans::XPropertySet >( xDBRange, uno::UNO_QUERY_THROW );
351 }
352 return uno::Reference< beans::XPropertySet >();
353 }
354
getAutoFilterMode()355 sal_Bool SAL_CALL ScVbaWorksheet::getAutoFilterMode()
356 {
357 uno::Reference< beans::XPropertySet > xDBRangeProps = getFirstDBRangeProperties();
358 sal_Bool bAutoFilterMode = sal_False;
359 return
360 xDBRangeProps.is() &&
361 (xDBRangeProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoFilter" ) ) ) >>= bAutoFilterMode) &&
362 bAutoFilterMode;
363 }
364
setAutoFilterMode(sal_Bool bAutoFilterMode)365 void SAL_CALL ScVbaWorksheet::setAutoFilterMode( sal_Bool bAutoFilterMode )
366 {
367 uno::Reference< beans::XPropertySet > xDBRangeProps = getFirstDBRangeProperties();
368 if( xDBRangeProps.is() )
369 xDBRangeProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutoFilter" ) ), uno::Any( bAutoFilterMode ) );
370 }
371
372 uno::Reference< excel::XRange >
getUsedRange()373 ScVbaWorksheet::getUsedRange()
374 {
375 uno::Reference< sheet::XSheetCellRange > xSheetCellRange(getSheet(), uno::UNO_QUERY_THROW );
376 uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor( getSheet()->createCursorByRange( xSheetCellRange ), uno::UNO_QUERY_THROW );
377 uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
378 xUsedCursor->gotoStartOfUsedArea( false );
379 xUsedCursor->gotoEndOfUsedArea( true );
380 uno::Reference< table::XCellRange > xRange( xSheetCellCursor, uno::UNO_QUERY);
381 return new ScVbaRange(this, mxContext, xRange);
382 }
383
384 uno::Reference< excel::XOutline >
Outline()385 ScVbaWorksheet::Outline( )
386 {
387 uno::Reference<sheet::XSheetOutline> xOutline(getSheet(),uno::UNO_QUERY_THROW);
388 return new ScVbaOutline( this, mxContext, xOutline);
389 }
390
391 uno::Reference< excel::XPageSetup >
PageSetup()392 ScVbaWorksheet::PageSetup( )
393 {
394 return new ScVbaPageSetup( this, mxContext, getSheet(), getModel() );
395 }
396
397 uno::Any
HPageBreaks(const uno::Any & aIndex)398 ScVbaWorksheet::HPageBreaks( const uno::Any& aIndex )
399 {
400 uno::Reference< sheet::XSheetPageBreak > xSheetPageBreak(getSheet(),uno::UNO_QUERY_THROW);
401 uno::Reference< excel::XHPageBreaks > xHPageBreaks( new ScVbaHPageBreaks( this, mxContext, xSheetPageBreak));
402 if ( aIndex.hasValue() )
403 return xHPageBreaks->Item( aIndex, uno::Any());
404 return uno::makeAny( xHPageBreaks );
405 }
406
407 uno::Any
VPageBreaks(const uno::Any & aIndex)408 ScVbaWorksheet::VPageBreaks( const uno::Any& aIndex )
409 {
410 uno::Reference< sheet::XSheetPageBreak > xSheetPageBreak( getSheet(), uno::UNO_QUERY_THROW );
411 uno::Reference< excel::XVPageBreaks > xVPageBreaks( new ScVbaVPageBreaks( this, mxContext, xSheetPageBreak ) );
412 if( aIndex.hasValue() )
413 return xVPageBreaks->Item( aIndex, uno::Any());
414 return uno::makeAny( xVPageBreaks );
415 }
416
417 sal_Int32
getStandardWidth()418 ScVbaWorksheet::getStandardWidth()
419 {
420 return STANDARDWIDTH ;
421 }
422
423 sal_Int32
getStandardHeight()424 ScVbaWorksheet::getStandardHeight()
425 {
426 return STANDARDHEIGHT;
427 }
428
429 sal_Bool
getProtectionMode()430 ScVbaWorksheet::getProtectionMode()
431 {
432 return sal_False;
433 }
434
435 sal_Bool
getProtectContents()436 ScVbaWorksheet::getProtectContents()
437 {
438 uno::Reference<util::XProtectable > xProtectable(getSheet(), uno::UNO_QUERY_THROW);
439 return xProtectable->isProtected();
440 }
441
442 sal_Bool
getProtectDrawingObjects()443 ScVbaWorksheet::getProtectDrawingObjects()
444 {
445 return sal_False;
446 }
447
448 sal_Bool
getProtectScenarios()449 ScVbaWorksheet::getProtectScenarios()
450 {
451 return sal_False;
452 }
453
454 void
Activate()455 ScVbaWorksheet::Activate()
456 {
457 uno::Reference< sheet::XSpreadsheetView > xSpreadsheet(
458 getModel()->getCurrentController(), uno::UNO_QUERY_THROW );
459 xSpreadsheet->setActiveSheet(getSheet());
460 }
461
462 void
Select()463 ScVbaWorksheet::Select()
464 {
465 Activate();
466 }
467
468 void
Move(const uno::Any & Before,const uno::Any & After)469 ScVbaWorksheet::Move( const uno::Any& Before, const uno::Any& After )
470 {
471 uno::Reference<excel::XWorksheet> xSheet;
472 rtl::OUString aCurrSheetName = getName();
473
474 if (!(Before >>= xSheet) && !(After >>=xSheet)&& !(Before.hasValue()) && !(After.hasValue()))
475 {
476 uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = getSheet()->createCursor( );
477 uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
478 uno::Reference< table::XCellRange > xRange1( xSheetCellCursor, uno::UNO_QUERY);
479 // #FIXME needs worksheet as parent
480 uno::Reference<excel::XRange> xRange = new ScVbaRange( this, mxContext, xRange1);
481 if (xRange.is())
482 xRange->Select();
483 excel::implnCopy(mxModel);
484 uno::Reference<frame::XModel> xModel = openNewDoc(aCurrSheetName);
485 if (xModel.is())
486 {
487 excel::implnPaste(xModel);
488 Delete();
489 }
490 return ;
491 }
492
493 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
494 SCTAB nDest = 0;
495 if ( ScVbaWorksheets::nameExists (xSpreadDoc, xSheet->getName(), nDest) )
496 {
497 sal_Bool bAfter = After.hasValue();
498 if (bAfter)
499 nDest++;
500 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
501 xSheets->moveByName(aCurrSheetName,nDest);
502 }
503 }
504
505 void
Copy(const uno::Any & Before,const uno::Any & After)506 ScVbaWorksheet::Copy( const uno::Any& Before, const uno::Any& After )
507 {
508 uno::Reference<excel::XWorksheet> xSheet;
509 rtl::OUString aCurrSheetName =getName();
510 if (!(Before >>= xSheet) && !(After >>=xSheet)&& !(Before.hasValue()) && !(After.hasValue()))
511 {
512 uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = getSheet()->createCursor( );
513 uno::Reference<sheet::XUsedAreaCursor> xUsedCursor(xSheetCellCursor,uno::UNO_QUERY_THROW);
514 uno::Reference< table::XCellRange > xRange1( xSheetCellCursor, uno::UNO_QUERY);
515 uno::Reference<excel::XRange> xRange = new ScVbaRange( this, mxContext, xRange1);
516 if (xRange.is())
517 xRange->Select();
518 excel::implnCopy(mxModel);
519 uno::Reference<frame::XModel> xModel = openNewDoc(aCurrSheetName);
520 if (xModel.is())
521 {
522 excel::implnPaste(xModel);
523 }
524 return;
525 }
526
527 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY );
528 SCTAB nDest = 0;
529 rtl::OUString aSheetName = xSheet->getName();
530 if ( ScVbaWorksheets::nameExists (xSpreadDoc, aSheetName, nDest ) )
531 {
532 sal_Bool bAfter = After.hasValue();
533 if(bAfter)
534 nDest++;
535 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
536 getNewSpreadsheetName(aSheetName,aCurrSheetName,xSpreadDoc);
537 xSheets->copyByName(aCurrSheetName,aSheetName,nDest);
538 }
539 }
540
541
542 void
Paste(const uno::Any & Destination,const uno::Any &)543 ScVbaWorksheet::Paste( const uno::Any& Destination, const uno::Any& /*Link*/ )
544 {
545 // #TODO# #FIXME# Link is not used
546 uno::Reference<excel::XRange> xRange( Destination, uno::UNO_QUERY );
547 if ( xRange.is() )
548 xRange->Select();
549 excel::implnPaste( mxModel );
550 }
551
552 void
Delete()553 ScVbaWorksheet::Delete()
554 {
555 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
556 rtl::OUString aSheetName = getName();
557 if ( xSpreadDoc.is() )
558 {
559 SCTAB nTab = 0;
560 if (!ScVbaWorksheets::nameExists(xSpreadDoc, aSheetName, nTab ))
561 {
562 return;
563 }
564 uno::Reference<sheet::XSpreadsheets> xSheets = xSpreadDoc->getSheets();
565 uno::Reference<container::XNameContainer> xNameContainer(xSheets,uno::UNO_QUERY_THROW);
566 xNameContainer->removeByName(aSheetName);
567 mxSheet.clear();
568 }
569 }
570
571 uno::Reference< excel::XWorksheet >
getSheetAtOffset(SCTAB offset)572 ScVbaWorksheet::getSheetAtOffset(SCTAB offset)
573 {
574 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( getModel(), uno::UNO_QUERY_THROW );
575 uno::Reference <sheet::XSpreadsheets> xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
576 uno::Reference <container::XIndexAccess> xIndex( xSheets, uno::UNO_QUERY_THROW );
577
578 SCTAB nIdx = 0;
579 if ( !ScVbaWorksheets::nameExists (xSpreadDoc, getName(), nIdx ) )
580 return uno::Reference< excel::XWorksheet >();
581 nIdx = nIdx + offset;
582 uno::Reference< sheet::XSpreadsheet > xSheet(xIndex->getByIndex(nIdx), uno::UNO_QUERY_THROW);
583 // parent will be the parent of 'this' worksheet
584 return new ScVbaWorksheet (getParent(), mxContext, xSheet, getModel());
585 }
586
587 uno::Reference< excel::XWorksheet >
getNext()588 ScVbaWorksheet::getNext()
589 {
590 return getSheetAtOffset(static_cast<SCTAB>(1));
591 }
592
593 uno::Reference< excel::XWorksheet >
getPrevious()594 ScVbaWorksheet::getPrevious()
595 {
596 return getSheetAtOffset(-1);
597 }
598
599
600 void
Protect(const uno::Any & Password,const uno::Any &,const uno::Any &,const uno::Any &,const uno::Any &)601 ScVbaWorksheet::Protect( const uno::Any& Password, const uno::Any& /*DrawingObjects*/, const uno::Any& /*Contents*/, const uno::Any& /*Scenarios*/, const uno::Any& /*UserInterfaceOnly*/ )
602 {
603 // #TODO# #FIXME# is there anything we can do with the unused param
604 // can the implementation use anything else here
605 uno::Reference<util::XProtectable > xProtectable(getSheet(), uno::UNO_QUERY_THROW);
606 ::rtl::OUString aPasswd;
607 Password >>= aPasswd;
608 xProtectable->protect( aPasswd );
609 }
610
611 void
Unprotect(const uno::Any & Password)612 ScVbaWorksheet::Unprotect( const uno::Any& Password )
613 {
614 uno::Reference<util::XProtectable > xProtectable(getSheet(), uno::UNO_QUERY_THROW);
615 ::rtl::OUString aPasswd;
616 Password >>= aPasswd;
617 xProtectable->unprotect( aPasswd );
618 }
619
620 void
Calculate()621 ScVbaWorksheet::Calculate()
622 {
623 uno::Reference <sheet::XCalculatable> xReCalculate(getModel(), uno::UNO_QUERY_THROW);
624 xReCalculate->calculate();
625 }
626
627 uno::Reference< excel::XRange >
Range(const::uno::Any & Cell1,const::uno::Any & Cell2)628 ScVbaWorksheet::Range( const ::uno::Any& Cell1, const ::uno::Any& Cell2 )
629 {
630 uno::Reference< excel::XRange > xSheetRange( new ScVbaRange( this, mxContext
631 , uno::Reference< table::XCellRange >( getSheet(), uno::UNO_QUERY_THROW ) ) );
632 return xSheetRange->Range( Cell1, Cell2 );
633 }
634
635 void
CheckSpelling(const uno::Any &,const uno::Any &,const uno::Any &,const uno::Any &)636 ScVbaWorksheet::CheckSpelling( const uno::Any& /*CustomDictionary*/,const uno::Any& /*IgnoreUppercase*/,const uno::Any& /*AlwaysSuggest*/, const uno::Any& /*SpellingLang*/ )
637 {
638 // #TODO# #FIXME# unused params above, can we do anything with those
639 rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SpellDialog"));
640 uno::Reference< frame::XModel > xModel( getModel() );
641 dispatchRequests(xModel,url);
642 }
643
644 uno::Reference< excel::XRange >
getSheetRange()645 ScVbaWorksheet::getSheetRange()
646 {
647 uno::Reference< table::XCellRange > xRange( getSheet(),uno::UNO_QUERY_THROW );
648 return uno::Reference< excel::XRange >( new ScVbaRange( this, mxContext, xRange ) );
649 }
650
651 // These are hacks - we prolly (somehow) need to inherit
652 // the vbarange functionality here ...
653 uno::Reference< excel::XRange >
Cells(const::uno::Any & nRow,const::uno::Any & nCol)654 ScVbaWorksheet::Cells( const ::uno::Any &nRow, const ::uno::Any &nCol )
655 {
656 // Performance optimization for often-called Cells method:
657 // Use a common helper method instead of creating a new ScVbaRange object
658 uno::Reference< table::XCellRange > xRange( getSheet(), uno::UNO_QUERY_THROW );
659 return ScVbaRange::CellsHelper( this, mxContext, xRange, nRow, nCol );
660 }
661
662 uno::Reference< excel::XRange >
Rows(const uno::Any & aIndex)663 ScVbaWorksheet::Rows(const uno::Any& aIndex )
664 {
665 return getSheetRange()->Rows( aIndex );
666 }
667
668 uno::Reference< excel::XRange >
Columns(const uno::Any & aIndex)669 ScVbaWorksheet::Columns( const uno::Any& aIndex )
670 {
671 return getSheetRange()->Columns( aIndex );
672 }
673
674 uno::Any SAL_CALL
ChartObjects(const uno::Any & Index)675 ScVbaWorksheet::ChartObjects( const uno::Any& Index )
676 {
677 if ( !mxCharts.is() )
678 {
679 uno::Reference< table::XTableChartsSupplier > xChartSupplier( getSheet(), uno::UNO_QUERY_THROW );
680 uno::Reference< table::XTableCharts > xTableCharts = xChartSupplier->getCharts();
681
682 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxSheet, uno::UNO_QUERY_THROW );
683 mxCharts = new ScVbaChartObjects( this, mxContext, xTableCharts, xDrawPageSupplier );
684 }
685 if ( Index.hasValue() )
686 {
687 uno::Reference< XCollection > xColl( mxCharts, uno::UNO_QUERY_THROW );
688 return xColl->Item( Index, uno::Any() );
689 }
690 else
691 return uno::makeAny( mxCharts );
692
693 }
694
695 uno::Any SAL_CALL
PivotTables(const uno::Any & Index)696 ScVbaWorksheet::PivotTables( const uno::Any& Index )
697 {
698 uno::Reference< css::sheet::XSpreadsheet > xSheet = getSheet();
699 uno::Reference< sheet::XDataPilotTablesSupplier > xTables(xSheet, uno::UNO_QUERY_THROW ) ;
700 uno::Reference< container::XIndexAccess > xIndexAccess( xTables->getDataPilotTables(), uno::UNO_QUERY_THROW );
701
702 uno::Reference< XCollection > xColl( new ScVbaPivotTables( this, mxContext, xIndexAccess ) );
703 if ( Index.hasValue() )
704 return xColl->Item( Index, uno::Any() );
705 return uno::makeAny( xColl );
706 }
707
708 uno::Any SAL_CALL
Comments(const uno::Any & Index)709 ScVbaWorksheet::Comments( const uno::Any& Index )
710 {
711 uno::Reference< css::sheet::XSpreadsheet > xSheet = getSheet();
712 uno::Reference< sheet::XSheetAnnotationsSupplier > xAnnosSupp( xSheet, uno::UNO_QUERY_THROW );
713 uno::Reference< sheet::XSheetAnnotations > xAnnos( xAnnosSupp->getAnnotations(), uno::UNO_QUERY_THROW );
714 uno::Reference< container::XIndexAccess > xIndexAccess( xAnnos, uno::UNO_QUERY_THROW );
715 uno::Reference< XCollection > xColl( new ScVbaComments( this, mxContext, mxModel, xIndexAccess ) );
716 if ( Index.hasValue() )
717 return xColl->Item( Index, uno::Any() );
718 return uno::makeAny( xColl );
719 }
720
721 uno::Any SAL_CALL
Hyperlinks(const uno::Any & aIndex)722 ScVbaWorksheet::Hyperlinks( const uno::Any& aIndex )
723 {
724 /* The worksheet always returns the same Hyperlinks object.
725 See vbahyperlinks.hxx for more details. */
726 if( !mxHlinks.is() )
727 mxHlinks.set( new ScVbaHyperlinks( this, mxContext ) );
728 if( aIndex.hasValue() )
729 return uno::Reference< XCollection >( mxHlinks, uno::UNO_QUERY_THROW )->Item( aIndex, uno::Any() );
730 return uno::Any( mxHlinks );
731 }
732
733 uno::Any SAL_CALL
Names(const css::uno::Any & aIndex)734 ScVbaWorksheet::Names( const css::uno::Any& aIndex )
735 {
736 // fake sheet-local names by returning all global names
737 // #163498# initialize Names object with correct parent (this worksheet)
738 // TODO: real sheet-local names...
739 uno::Reference< beans::XPropertySet > xProps( mxModel, uno::UNO_QUERY_THROW );
740 uno::Reference< sheet::XNamedRanges > xNamedRanges( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NamedRanges") ) ), uno::UNO_QUERY_THROW );
741 uno::Reference< XCollection > xNames( new ScVbaNames( this, mxContext, xNamedRanges, mxModel ) );
742 if ( aIndex.hasValue() )
743 return uno::Any( xNames->Item( aIndex, uno::Any() ) );
744 return uno::Any( xNames );
745 }
746
747 uno::Any SAL_CALL
OLEObjects(const uno::Any & Index)748 ScVbaWorksheet::OLEObjects( const uno::Any& Index )
749 {
750 uno::Reference< sheet::XSpreadsheet > xSpreadsheet( getSheet(), uno::UNO_QUERY_THROW );
751 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xSpreadsheet, uno::UNO_QUERY_THROW );
752 uno::Reference< drawing::XDrawPage > xDrawPage( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
753 uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPage, uno::UNO_QUERY_THROW );
754
755 uno::Reference< excel::XOLEObjects >xOleObjects( new ScVbaOLEObjects( this, mxContext, xIndexAccess ) );
756 if( Index.hasValue() )
757 return xOleObjects->Item( Index, uno::Any() );
758 return uno::Any( xOleObjects );
759 }
760
761 uno::Any SAL_CALL
Shapes(const uno::Any & aIndex)762 ScVbaWorksheet::Shapes( const uno::Any& aIndex )
763 {
764 uno::Reference< sheet::XSpreadsheet > xSpreadsheet( getSheet(), uno::UNO_QUERY_THROW );
765 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xSpreadsheet, uno::UNO_QUERY_THROW );
766 uno::Reference< drawing::XShapes > xShapes( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
767 uno::Reference< container::XIndexAccess > xIndexAccess( xShapes, uno::UNO_QUERY_THROW );
768
769 uno::Reference< msforms::XShapes> xVbaShapes( new ScVbaShapes( this, mxContext, xIndexAccess, getModel() ) );
770 if ( aIndex.hasValue() )
771 return xVbaShapes->Item( aIndex, uno::Any() );
772 return uno::makeAny( xVbaShapes );
773 }
774
775 uno::Any SAL_CALL
Buttons(const uno::Any & rIndex)776 ScVbaWorksheet::Buttons( const uno::Any& rIndex )
777 {
778 if( !mxButtons.is() )
779 mxButtons.set( new ScVbaButtons( this, mxContext, mxModel, mxSheet ) );
780 else
781 mxButtons->collectShapes();
782 if( rIndex.hasValue() )
783 return mxButtons->Item( rIndex, uno::Any() );
784 return uno::Any( uno::Reference< XCollection >( mxButtons.get() ) );
785 }
786
787 uno::Any SAL_CALL
CheckBoxes(const uno::Any &)788 ScVbaWorksheet::CheckBoxes( const uno::Any& /*rIndex*/ )
789 {
790 throw uno::RuntimeException();
791 }
792
793 uno::Any SAL_CALL
DropDowns(const uno::Any &)794 ScVbaWorksheet::DropDowns( const uno::Any& /*rIndex*/ )
795 {
796 throw uno::RuntimeException();
797 }
798
799 uno::Any SAL_CALL
GroupBoxes(const uno::Any &)800 ScVbaWorksheet::GroupBoxes( const uno::Any& /*rIndex*/ )
801 {
802 throw uno::RuntimeException();
803 }
804
805 uno::Any SAL_CALL
Labels(const uno::Any &)806 ScVbaWorksheet::Labels( const uno::Any& /*rIndex*/ )
807 {
808 throw uno::RuntimeException();
809 }
810
811 uno::Any SAL_CALL
ListBoxes(const uno::Any &)812 ScVbaWorksheet::ListBoxes( const uno::Any& /*rIndex*/ )
813 {
814 throw uno::RuntimeException();
815 }
816
817 uno::Any SAL_CALL
OptionButtons(const uno::Any &)818 ScVbaWorksheet::OptionButtons( const uno::Any& /*rIndex*/ )
819 {
820 throw uno::RuntimeException();
821 }
822
823 uno::Any SAL_CALL
ScrollBars(const uno::Any &)824 ScVbaWorksheet::ScrollBars( const uno::Any& /*rIndex*/ )
825 {
826 throw uno::RuntimeException();
827 }
828
829 uno::Any SAL_CALL
Spinners(const uno::Any &)830 ScVbaWorksheet::Spinners( const uno::Any& /*rIndex*/ )
831 {
832 throw uno::RuntimeException();
833 }
834
835 void SAL_CALL
ShowDataForm()836 ScVbaWorksheet::ShowDataForm( )
837 {
838 #ifdef VBA_OOBUILD_HACK
839 uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
840 ScTabViewShell* pTabViewShell = excel::getBestViewShell( xModel );
841
842 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
843 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
844
845 AbstractScDataFormDlg* pDlg = pFact->CreateScDataFormDlg( pTabViewShell->GetDialogParent(),RID_SCDLG_DATAFORM, pTabViewShell);
846 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
847
848 pDlg->Execute();
849 #else
850 throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
851 #endif
852 }
853
854 uno::Any SAL_CALL
Evaluate(const::rtl::OUString & Name)855 ScVbaWorksheet::Evaluate( const ::rtl::OUString& Name )
856 {
857 // #TODO Evaluate allows other things to be evaluated, e.g. functions
858 // I think ( like SIN(3) etc. ) need to investigate that
859 // named Ranges also? e.g. [MyRange] if so need a list of named ranges
860 uno::Any aVoid;
861 return uno::Any( Range( uno::Any( Name ), aVoid ) );
862 }
863
864
865 uno::Reference< beans::XIntrospectionAccess > SAL_CALL
getIntrospection()866 ScVbaWorksheet::getIntrospection( )
867 {
868 return uno::Reference< beans::XIntrospectionAccess >();
869 }
870
871 uno::Any SAL_CALL
invoke(const::rtl::OUString & aFunctionName,const uno::Sequence<uno::Any> &,uno::Sequence<::sal_Int16> &,uno::Sequence<uno::Any> &)872 ScVbaWorksheet::invoke( const ::rtl::OUString& aFunctionName, const uno::Sequence< uno::Any >& /*aParams*/, uno::Sequence< ::sal_Int16 >& /*aOutParamIndex*/, uno::Sequence< uno::Any >& /*aOutParam*/ )
873 {
874 OSL_TRACE("** ScVbaWorksheet::invoke( %s ), will barf",
875 rtl::OUStringToOString( aFunctionName, RTL_TEXTENCODING_UTF8 ).getStr() );
876
877 throw uno::RuntimeException(); // unsupported operation
878 }
879
880 void SAL_CALL
setValue(const::rtl::OUString & aPropertyName,const uno::Any & aValue)881 ScVbaWorksheet::setValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue )
882 {
883 setDefaultPropByIntrospection( uno::makeAny( getValue( aPropertyName ) ), aValue );
884 }
885 uno::Any SAL_CALL
getValue(const::rtl::OUString & aPropertyName)886 ScVbaWorksheet::getValue( const ::rtl::OUString& aPropertyName )
887 {
888 uno::Reference< drawing::XControlShape > xControlShape( getControlShape( aPropertyName ), uno::UNO_QUERY_THROW );
889
890 uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
891 uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.ControlProvider" ) ), mxContext ), uno::UNO_QUERY_THROW );
892 uno::Reference< msforms::XControl > xControl( xControlProvider->createControl( xControlShape, getModel() ) );
893 return uno::makeAny( xControl );
894 }
895
896 ::sal_Bool SAL_CALL
hasMethod(const::rtl::OUString &)897 ScVbaWorksheet::hasMethod( const ::rtl::OUString& /*aName*/ )
898 {
899 return sal_False;
900 }
901
902 uno::Reference< container::XNameAccess >
getFormControls()903 ScVbaWorksheet::getFormControls()
904 {
905 uno::Reference< container::XNameAccess > xFormControls;
906 try
907 {
908 uno::Reference< sheet::XSpreadsheet > xSpreadsheet( getSheet(), uno::UNO_QUERY_THROW );
909 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xSpreadsheet, uno::UNO_QUERY_THROW );
910 uno::Reference< form::XFormsSupplier > xFormSupplier( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
911 uno::Reference< container::XIndexAccess > xIndexAccess( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
912 // get the www-standard container ( maybe we should access the
913 // 'www-standard' by name rather than index, this seems an
914 // implementation detail
915 if( xIndexAccess->hasElements() )
916 xFormControls.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY );
917
918 }
919 catch( uno::Exception& )
920 {
921 }
922 return xFormControls;
923
924 }
925 ::sal_Bool SAL_CALL
hasProperty(const::rtl::OUString & aName)926 ScVbaWorksheet::hasProperty( const ::rtl::OUString& aName )
927 {
928 uno::Reference< container::XNameAccess > xFormControls( getFormControls() );
929 if ( xFormControls.is() )
930 return xFormControls->hasByName( aName );
931 return sal_False;
932 }
933
934 uno::Any
getControlShape(const::rtl::OUString & sName)935 ScVbaWorksheet::getControlShape( const ::rtl::OUString& sName )
936 {
937 // ideally we would get an XControl object but it appears an XControl
938 // implementation only exists for a Control implementation obtained from the
939 // view ( e.g. in basic you would get this from
940 // thiscomponent.currentcontroller.getControl( controlModel ) )
941 // and the thing to realise is that it is only possible to get an XControl
942 // for a currently displayed control :-( often we would want to modify
943 // a control not on the active sheet. But.. you can always access the
944 // XControlShape from the DrawPage whether that is the active drawpage or not
945
946 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( getSheet(), uno::UNO_QUERY_THROW );
947 uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
948
949 sal_Int32 nCount = xIndexAccess->getCount();
950 for( int index = 0; index < nCount; index++ )
951 {
952 uno::Any aUnoObj = xIndexAccess->getByIndex( index );
953 // It seems there are some drawing objects that can not query into Control shapes?
954 uno::Reference< drawing::XControlShape > xControlShape( aUnoObj, uno::UNO_QUERY );
955 if( xControlShape.is() )
956 {
957 uno::Reference< container::XNamed > xNamed( xControlShape->getControl(), uno::UNO_QUERY_THROW );
958 if( sName.equals( xNamed->getName() ))
959 {
960 return aUnoObj;
961 }
962 }
963 }
964 return uno::Any();
965 }
966
967
968 rtl::OUString&
getServiceImplName()969 ScVbaWorksheet::getServiceImplName()
970 {
971 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaWorksheet") );
972 return sImplName;
973 }
974 void SAL_CALL
setEnableCalculation(::sal_Bool bEnableCalculation)975 ScVbaWorksheet::setEnableCalculation( ::sal_Bool bEnableCalculation )
976 {
977 uno::Reference <sheet::XCalculatable> xCalculatable(getModel(), uno::UNO_QUERY_THROW);
978 xCalculatable->enableAutomaticCalculation( bEnableCalculation);
979 }
980 ::sal_Bool SAL_CALL
getEnableCalculation()981 ScVbaWorksheet::getEnableCalculation( )
982 {
983 uno::Reference <sheet::XCalculatable> xCalculatable(getModel(), uno::UNO_QUERY_THROW);
984 return xCalculatable->isAutomaticCalculationEnabled();
985 }
986
987 uno::Sequence< rtl::OUString >
getServiceNames()988 ScVbaWorksheet::getServiceNames()
989 {
990 static uno::Sequence< rtl::OUString > aServiceNames;
991 if ( aServiceNames.getLength() == 0 )
992 {
993 aServiceNames.realloc( 1 );
994 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Worksheet" ) );
995 }
996 return aServiceNames;
997 }
998
999 rtl::OUString SAL_CALL
getCodeName()1000 ScVbaWorksheet::getCodeName()
1001 {
1002 uno::Reference< beans::XPropertySet > xSheetProp( mxSheet, uno::UNO_QUERY_THROW );
1003 return xSheetProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CodeName" ) ) ).get< ::rtl::OUString >();
1004 }
1005
1006 sal_Int16
getSheetID()1007 ScVbaWorksheet::getSheetID()
1008 {
1009 uno::Reference< sheet::XCellRangeAddressable > xAddressable( mxSheet, uno::UNO_QUERY_THROW );
1010 return xAddressable->getRangeAddress().Sheet;
1011 }
1012
1013 void SAL_CALL
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)1014 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 )
1015 {
1016 sal_Int32 nTo = 0;
1017 sal_Int32 nFrom = 0;
1018 sal_Int16 nCopies = 1;
1019 sal_Bool bCollate = sal_False;
1020 sal_Bool bSelection = sal_False;
1021 sal_Bool bIgnorePrintAreas = sal_False;
1022 From >>= nFrom;
1023 To >>= nTo;
1024 Copies >>= nCopies;
1025 IgnorePrintAreas >>= bIgnorePrintAreas;
1026 if ( nCopies > 1 ) // Collate only useful when more that 1 copy
1027 Collate >>= bCollate;
1028
1029 if ( !( nFrom || nTo ) )
1030 bSelection = sal_True;
1031
1032 uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
1033 PrintOutHelper( excel::getBestViewShell( xModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, bSelection );
1034 }
1035
1036 namespace worksheet
1037 {
1038 namespace sdecl = comphelper::service_decl;
1039 sdecl::vba_service_class_<ScVbaWorksheet, sdecl::with_args<true> > serviceImpl;
1040 extern sdecl::ServiceDecl const serviceDecl(
1041 serviceImpl,
1042 "ScVbaWorksheet",
1043 "ooo.vba.excel.Worksheet" );
1044 }
1045