xref: /trunk/main/sc/source/ui/vba/vbaworkbook.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir #include <vbahelper/helperdecl.hxx>
28*cdf0e10cSrcweir #include <tools/urlobj.hxx>
29*cdf0e10cSrcweir #include <comphelper/unwrapargs.hxx>
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/util/XProtectable.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/sheet/XSpreadsheetView.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
38*cdf0e10cSrcweir #include <ooo/vba/excel/XlFileFormat.hpp>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include "scextopt.hxx"
41*cdf0e10cSrcweir #include "vbaworksheet.hxx"
42*cdf0e10cSrcweir #include "vbaworksheets.hxx"
43*cdf0e10cSrcweir #include "vbaworkbook.hxx"
44*cdf0e10cSrcweir #include "vbawindows.hxx"
45*cdf0e10cSrcweir #include "vbastyles.hxx"
46*cdf0e10cSrcweir #include "excelvbahelper.hxx"
47*cdf0e10cSrcweir #include "vbapalette.hxx"
48*cdf0e10cSrcweir #include <osl/file.hxx>
49*cdf0e10cSrcweir #include <stdio.h>
50*cdf0e10cSrcweir #include "vbanames.hxx"  // Amelia Wang
51*cdf0e10cSrcweir #include "nameuno.hxx"
52*cdf0e10cSrcweir #include "docoptio.hxx"
53*cdf0e10cSrcweir #include "unonames.hxx"
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir // Much of the impl. for the equivalend UNO module is
56*cdf0e10cSrcweir // sc/source/ui/unoobj/docuno.cxx, viewuno.cxx
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir using namespace ::ooo::vba;
59*cdf0e10cSrcweir using namespace ::com::sun::star;
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir class ActiveSheet : public ScVbaWorksheet
62*cdf0e10cSrcweir {
63*cdf0e10cSrcweir protected:
64*cdf0e10cSrcweir 	virtual uno::Reference< frame::XModel > getModel()
65*cdf0e10cSrcweir 	{
66*cdf0e10cSrcweir 		return getCurrentExcelDoc( mxContext );
67*cdf0e10cSrcweir 	}
68*cdf0e10cSrcweir 	virtual uno::Reference< sheet::XSpreadsheet > getSheet()
69*cdf0e10cSrcweir 	{
70*cdf0e10cSrcweir 		uno::Reference< frame::XModel > xModel = getModel();
71*cdf0e10cSrcweir 		uno::Reference< sheet::XSpreadsheet > xSheet;
72*cdf0e10cSrcweir 		if ( xModel.is() )
73*cdf0e10cSrcweir 		{
74*cdf0e10cSrcweir 			uno::Reference< sheet::XSpreadsheetView > xSpreadsheet(
75*cdf0e10cSrcweir                         	xModel->getCurrentController(), uno::UNO_QUERY );
76*cdf0e10cSrcweir 			if ( xSpreadsheet.is() )
77*cdf0e10cSrcweir 				xSheet = xSpreadsheet->getActiveSheet();
78*cdf0e10cSrcweir 		}
79*cdf0e10cSrcweir 		return xSheet;
80*cdf0e10cSrcweir 	}
81*cdf0e10cSrcweir public:
82*cdf0e10cSrcweir 	ActiveSheet( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext ) : ScVbaWorksheet( xParent, xContext ) {}
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir };
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir uno::Sequence< sal_Int32 > ScVbaWorkbook::ColorData;
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir void ScVbaWorkbook::initColorData( const uno::Sequence< sal_Int32 >& sColors )
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir 		const sal_Int32* pSource = sColors.getConstArray();
91*cdf0e10cSrcweir 		sal_Int32* pDest = ColorData.getArray();
92*cdf0e10cSrcweir 		const sal_Int32* pEnd = pSource + sColors.getLength();
93*cdf0e10cSrcweir 		for ( ; pSource != pEnd; ++pSource, ++pDest )
94*cdf0e10cSrcweir 			*pDest = *pSource;
95*cdf0e10cSrcweir }
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir void SAL_CALL
99*cdf0e10cSrcweir ScVbaWorkbook::ResetColors(  ) throw (::script::BasicErrorException, ::uno::RuntimeException)
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir 		uno::Reference< container::XIndexAccess > xIndexAccess( ScVbaPalette::getDefaultPalette(), uno::UNO_QUERY_THROW );
102*cdf0e10cSrcweir 		sal_Int32 nLen = xIndexAccess->getCount();
103*cdf0e10cSrcweir 		ColorData.realloc( nLen );
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 		uno::Sequence< sal_Int32 > dDefaultColors( nLen );
106*cdf0e10cSrcweir 		sal_Int32* pDest = dDefaultColors.getArray();
107*cdf0e10cSrcweir 		for ( sal_Int32 index=0; index < nLen; ++pDest, ++index )
108*cdf0e10cSrcweir 			xIndexAccess->getByIndex( index )  >>= (*pDest);
109*cdf0e10cSrcweir 		initColorData( dDefaultColors );
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir ::uno::Any SAL_CALL
113*cdf0e10cSrcweir ScVbaWorkbook::Colors( const ::uno::Any& Index ) throw (::script::BasicErrorException, ::uno::RuntimeException)
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir 	uno::Any aRet;
116*cdf0e10cSrcweir 	if ( Index.getValue() )
117*cdf0e10cSrcweir 	{
118*cdf0e10cSrcweir 		sal_Int32 nIndex = 0;
119*cdf0e10cSrcweir 		Index >>= nIndex;
120*cdf0e10cSrcweir 		aRet = uno::makeAny( XLRGBToOORGB( ColorData[ --nIndex ] ) );
121*cdf0e10cSrcweir 	}
122*cdf0e10cSrcweir 	else
123*cdf0e10cSrcweir 		aRet = uno::makeAny( ColorData );
124*cdf0e10cSrcweir 	return aRet;
125*cdf0e10cSrcweir }
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir ::sal_Int32 SAL_CALL
128*cdf0e10cSrcweir ScVbaWorkbook::FileFormat(  ) throw (::script::BasicErrorException, ::uno::RuntimeException)
129*cdf0e10cSrcweir {
130*cdf0e10cSrcweir         sal_Int32 aFileFormat = 0;
131*cdf0e10cSrcweir         rtl::OUString aFilterName;
132*cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue > aArgs = getModel()->getArgs();
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 		// #FIXME - seems suspect should we not walk through the properties
135*cdf0e10cSrcweir 		// to find the FilterName
136*cdf0e10cSrcweir         if (aArgs[0].Name.equalsAscii( "FilterName")) {
137*cdf0e10cSrcweir             aArgs[0].Value >>= aFilterName;
138*cdf0e10cSrcweir         } else {
139*cdf0e10cSrcweir            aArgs[1].Value >>= aFilterName;
140*cdf0e10cSrcweir         }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir         if (aFilterName.equalsAscii("Text - txt - csv (StarCalc)")) {
143*cdf0e10cSrcweir             aFileFormat = excel::XlFileFormat::xlCSV; //xlFileFormat.
144*cdf0e10cSrcweir         }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir         if (aFilterName.equalsAscii("DBF")) {
147*cdf0e10cSrcweir             aFileFormat = excel::XlFileFormat::xlDBF4;
148*cdf0e10cSrcweir         }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir         if (aFilterName.equalsAscii("DIF")) {
151*cdf0e10cSrcweir             aFileFormat = excel::XlFileFormat::xlDIF;
152*cdf0e10cSrcweir         }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir         if (aFilterName.equalsAscii("Lotus")) {
155*cdf0e10cSrcweir             aFileFormat = excel::XlFileFormat::xlWK3;
156*cdf0e10cSrcweir         }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir         if (aFilterName.equalsAscii("MS Excel 4.0")) {
159*cdf0e10cSrcweir             aFileFormat = excel::XlFileFormat::xlExcel4Workbook;
160*cdf0e10cSrcweir         }
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir         if (aFilterName.equalsAscii("MS Excel 5.0/95")) {
163*cdf0e10cSrcweir             aFileFormat = excel::XlFileFormat::xlExcel5;
164*cdf0e10cSrcweir         }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir         if (aFilterName.equalsAscii("MS Excel 97")) {
167*cdf0e10cSrcweir             aFileFormat = excel::XlFileFormat::xlExcel9795;
168*cdf0e10cSrcweir         }
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir         if (aFilterName.equalsAscii("HTML (StarCalc)")) {
171*cdf0e10cSrcweir             aFileFormat = excel::XlFileFormat::xlHtml;
172*cdf0e10cSrcweir         }
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir         if (aFilterName.equalsAscii("calc_StarOffice_XML_Calc_Template")) {
175*cdf0e10cSrcweir             aFileFormat = excel::XlFileFormat::xlTemplate;
176*cdf0e10cSrcweir         }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir         if (aFilterName.equalsAscii("StarOffice XML (Calc)")) {
179*cdf0e10cSrcweir             aFileFormat = excel::XlFileFormat::xlWorkbookNormal;
180*cdf0e10cSrcweir         }
181*cdf0e10cSrcweir         if (aFilterName.equalsAscii("calc8")) {
182*cdf0e10cSrcweir             aFileFormat = excel::XlFileFormat::xlWorkbookNormal;
183*cdf0e10cSrcweir         }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir         return aFileFormat;
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir void
189*cdf0e10cSrcweir ScVbaWorkbook::init()
190*cdf0e10cSrcweir {
191*cdf0e10cSrcweir 	if ( !ColorData.getLength() )
192*cdf0e10cSrcweir 		ResetColors();
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir ScVbaWorkbook::ScVbaWorkbook( 	const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext) :ScVbaWorkbook_BASE( xParent, xContext )
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir 	//#FIXME this persists the color data per office instance and
197*cdf0e10cSrcweir 	// not per workbook instance, need to hook the data into XModel
198*cdf0e10cSrcweir 	// ( e.g. we already store the imported palette in there )
199*cdf0e10cSrcweir 	// so we should,
200*cdf0e10cSrcweir 	// a) make the class that does that a service
201*cdf0e10cSrcweir 	// b) make that service implement XIndexContainer
202*cdf0e10cSrcweir 	init();
203*cdf0e10cSrcweir }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir ScVbaWorkbook::ScVbaWorkbook( 	const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, css::uno::Reference< css::frame::XModel > xModel ) : ScVbaWorkbook_BASE( xParent, xContext, xModel )
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir 	init();
208*cdf0e10cSrcweir }
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir ScVbaWorkbook::ScVbaWorkbook( uno::Sequence< uno::Any> const & args,
211*cdf0e10cSrcweir     uno::Reference< uno::XComponentContext> const & xContext ) : ScVbaWorkbook_BASE( args, xContext )
212*cdf0e10cSrcweir {
213*cdf0e10cSrcweir 	init();
214*cdf0e10cSrcweir }
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir uno::Reference< excel::XWorksheet >
217*cdf0e10cSrcweir ScVbaWorkbook::getActiveSheet() throw (uno::RuntimeException)
218*cdf0e10cSrcweir {
219*cdf0e10cSrcweir 	uno::Reference< frame::XModel > xModel( getCurrentExcelDoc( mxContext ), uno::UNO_SET_THROW );
220*cdf0e10cSrcweir 	uno::Reference< sheet::XSpreadsheetView > xView( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
221*cdf0e10cSrcweir     uno::Reference< sheet::XSpreadsheet > xSheet( xView->getActiveSheet(), uno::UNO_SET_THROW );
222*cdf0e10cSrcweir     // #162503# return the original sheet module wrapper object, instead of a new instance
223*cdf0e10cSrcweir     return uno::Reference< excel::XWorksheet >( excel::getUnoSheetModuleObj( xSheet ), uno::UNO_QUERY_THROW );
224*cdf0e10cSrcweir }
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir uno::Any SAL_CALL
227*cdf0e10cSrcweir ScVbaWorkbook::Sheets( const uno::Any& aIndex ) throw (uno::RuntimeException)
228*cdf0e10cSrcweir {
229*cdf0e10cSrcweir 	return Worksheets( aIndex );
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir uno::Any SAL_CALL
233*cdf0e10cSrcweir ScVbaWorkbook::Worksheets( const uno::Any& aIndex ) throw (uno::RuntimeException)
234*cdf0e10cSrcweir {
235*cdf0e10cSrcweir 	uno::Reference< frame::XModel > xModel( getModel() );
236*cdf0e10cSrcweir 	uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
237*cdf0e10cSrcweir 	uno::Reference<container::XIndexAccess > xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
238*cdf0e10cSrcweir 	uno::Reference< XCollection > xWorkSheets(  new ScVbaWorksheets( this, mxContext, xSheets, xModel ) );
239*cdf0e10cSrcweir 	if (  aIndex.getValueTypeClass() == uno::TypeClass_VOID )
240*cdf0e10cSrcweir 	{
241*cdf0e10cSrcweir 		return uno::Any( xWorkSheets );
242*cdf0e10cSrcweir 	}
243*cdf0e10cSrcweir 	// pass on to collection
244*cdf0e10cSrcweir 	return uno::Any( xWorkSheets->Item( aIndex, uno::Any() ) );
245*cdf0e10cSrcweir }
246*cdf0e10cSrcweir uno::Any SAL_CALL
247*cdf0e10cSrcweir ScVbaWorkbook::Windows( const uno::Any& aIndex ) throw (uno::RuntimeException)
248*cdf0e10cSrcweir {
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir 	uno::Reference< excel::XWindows >  xWindows( new ScVbaWindows( getParent(), mxContext ) );
251*cdf0e10cSrcweir 	if ( aIndex.getValueTypeClass() == uno::TypeClass_VOID )
252*cdf0e10cSrcweir 		return uno::Any( xWindows );
253*cdf0e10cSrcweir 	return uno::Any( xWindows->Item( aIndex, uno::Any() ) );
254*cdf0e10cSrcweir }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir void SAL_CALL
257*cdf0e10cSrcweir ScVbaWorkbook::Activate() throw (uno::RuntimeException)
258*cdf0e10cSrcweir {
259*cdf0e10cSrcweir     VbaDocumentBase::Activate();
260*cdf0e10cSrcweir }
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir ::sal_Bool
263*cdf0e10cSrcweir ScVbaWorkbook::getProtectStructure() throw (uno::RuntimeException)
264*cdf0e10cSrcweir {
265*cdf0e10cSrcweir 	uno::Reference< util::XProtectable > xProt( getModel(), uno::UNO_QUERY_THROW );
266*cdf0e10cSrcweir 	return xProt->isProtected();
267*cdf0e10cSrcweir }
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir ::sal_Bool SAL_CALL ScVbaWorkbook::getPrecisionAsDisplayed() throw (uno::RuntimeException)
270*cdf0e10cSrcweir {
271*cdf0e10cSrcweir     uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
272*cdf0e10cSrcweir     ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument();
273*cdf0e10cSrcweir     return pDoc->GetDocOptions().IsCalcAsShown();
274*cdf0e10cSrcweir }
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir void SAL_CALL ScVbaWorkbook::setPrecisionAsDisplayed( sal_Bool _precisionAsDisplayed ) throw (uno::RuntimeException)
277*cdf0e10cSrcweir {
278*cdf0e10cSrcweir     uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_QUERY_THROW );
279*cdf0e10cSrcweir     ScDocument* pDoc = excel::getDocShell( xModel )->GetDocument();
280*cdf0e10cSrcweir     ScDocOptions aOpt = pDoc->GetDocOptions();
281*cdf0e10cSrcweir     aOpt.SetCalcAsShown( _precisionAsDisplayed );
282*cdf0e10cSrcweir     pDoc->SetDocOptions( aOpt );
283*cdf0e10cSrcweir }
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir void
286*cdf0e10cSrcweir ScVbaWorkbook::SaveCopyAs( const rtl::OUString& sFileName ) throw ( uno::RuntimeException)
287*cdf0e10cSrcweir {
288*cdf0e10cSrcweir 	rtl::OUString aURL;
289*cdf0e10cSrcweir 	osl::FileBase::getFileURLFromSystemPath( sFileName, aURL );
290*cdf0e10cSrcweir 	uno::Reference< frame::XStorable > xStor( getModel(), uno::UNO_QUERY_THROW );
291*cdf0e10cSrcweir 	uno::Sequence<  beans::PropertyValue > storeProps(1);
292*cdf0e10cSrcweir 	storeProps[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) );
293*cdf0e10cSrcweir 	storeProps[0].Value <<= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MS Excel 97" ) );
294*cdf0e10cSrcweir 	xStor->storeToURL( aURL, storeProps );
295*cdf0e10cSrcweir }
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir css::uno::Any SAL_CALL
298*cdf0e10cSrcweir ScVbaWorkbook::Styles( const uno::Any& Item ) throw (uno::RuntimeException)
299*cdf0e10cSrcweir {
300*cdf0e10cSrcweir 	// quick look and Styles object doesn't seem to have a valid parent
301*cdf0e10cSrcweir 	// or a least the object browser just shows an object that has no
302*cdf0e10cSrcweir 	// variables ( therefore... leave as NULL for now )
303*cdf0e10cSrcweir 	uno::Reference< XCollection > dStyles = new ScVbaStyles( uno::Reference< XHelperInterface >(), mxContext, getModel() );
304*cdf0e10cSrcweir 	if ( Item.hasValue() )
305*cdf0e10cSrcweir 		return dStyles->Item( Item, uno::Any() );
306*cdf0e10cSrcweir 	return uno::makeAny( dStyles );
307*cdf0e10cSrcweir }
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir // Amelia Wang
310*cdf0e10cSrcweir uno::Any SAL_CALL
311*cdf0e10cSrcweir ScVbaWorkbook::Names( const uno::Any& aIndex ) throw (uno::RuntimeException)
312*cdf0e10cSrcweir {
313*cdf0e10cSrcweir 	uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_SET_THROW );
314*cdf0e10cSrcweir 	uno::Reference< beans::XPropertySet > xProps( xModel, uno::UNO_QUERY_THROW );
315*cdf0e10cSrcweir 	uno::Reference< sheet::XNamedRanges > xNamedRanges(  xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("NamedRanges") ) ), uno::UNO_QUERY_THROW );
316*cdf0e10cSrcweir 	uno::Reference< XCollection > xNames( new ScVbaNames( this, mxContext, xNamedRanges, xModel ) );
317*cdf0e10cSrcweir     if ( aIndex.hasValue() )
318*cdf0e10cSrcweir         return uno::Any( xNames->Item( aIndex, uno::Any() ) );
319*cdf0e10cSrcweir 	return uno::Any( xNames );
320*cdf0e10cSrcweir }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir rtl::OUString&
323*cdf0e10cSrcweir ScVbaWorkbook::getServiceImplName()
324*cdf0e10cSrcweir {
325*cdf0e10cSrcweir 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaWorkbook") );
326*cdf0e10cSrcweir 	return sImplName;
327*cdf0e10cSrcweir }
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir uno::Sequence< rtl::OUString >
330*cdf0e10cSrcweir ScVbaWorkbook::getServiceNames()
331*cdf0e10cSrcweir {
332*cdf0e10cSrcweir 	static uno::Sequence< rtl::OUString > aServiceNames;
333*cdf0e10cSrcweir 	if ( aServiceNames.getLength() == 0 )
334*cdf0e10cSrcweir 	{
335*cdf0e10cSrcweir 		aServiceNames.realloc( 1 );
336*cdf0e10cSrcweir 		aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Workbook" ) );
337*cdf0e10cSrcweir 	}
338*cdf0e10cSrcweir 	return aServiceNames;
339*cdf0e10cSrcweir }
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir ::rtl::OUString SAL_CALL
342*cdf0e10cSrcweir ScVbaWorkbook::getCodeName() throw (css::uno::RuntimeException)
343*cdf0e10cSrcweir {
344*cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xModelProp( getModel(), uno::UNO_QUERY_THROW );
345*cdf0e10cSrcweir     return xModelProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CodeName" ) ) ).get< ::rtl::OUString >();
346*cdf0e10cSrcweir }
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir namespace workbook
349*cdf0e10cSrcweir {
350*cdf0e10cSrcweir namespace sdecl = comphelper::service_decl;
351*cdf0e10cSrcweir sdecl::vba_service_class_<ScVbaWorkbook, sdecl::with_args<true> > serviceImpl;
352*cdf0e10cSrcweir extern sdecl::ServiceDecl const serviceDecl(
353*cdf0e10cSrcweir     serviceImpl,
354*cdf0e10cSrcweir     "ScVbaWorkbook",
355*cdf0e10cSrcweir     "ooo.vba.excel.Workbook" );
356*cdf0e10cSrcweir }
357