20#include <com/sun/star/table/XCellRange.hpp>
21#include <com/sun/star/sheet/XCellRangeAddressable.hpp>
22#include <com/sun/star/sheet/XNamedRange.hpp>
23#include <com/sun/star/sheet/XNamedRanges.hpp>
32#include <compiler.hxx>
33#include <tokenarray.hxx>
45 uno::Reference< frame::XModel >
m_xModel;
46 uno::Reference< sheet::XNamedRanges > m_xNames;
49 NamesEnumeration(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< container::XEnumeration >& xEnumeration, uno::Reference< frame::XModel > xModel , uno::Reference< sheet::XNamedRanges > xNames ) :
EnumerationHelperImpl( xParent, xContext, xEnumeration ),
m_xModel(
std::move(
xModel )), m_xNames(
std::move( xNames )) {}
51 virtual uno::Any SAL_CALL nextElement( )
override
53 uno::Reference< sheet::XNamedRange > xNamed( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
54 return uno::Any( uno::Reference< excel::XName > (
new ScVbaName( m_xParent, m_xContext, xNamed ,m_xNames , m_xModel ) ) );
62 const css::uno::Reference< css::uno::XComponentContext >& xContext,
63 const css::uno::Reference< css::sheet::XNamedRanges >& xNames,
64 css::uno::Reference< css::frame::XModel > xModel ):
79 uno::Reference< frame::XModel >
xModel(
getModel() , uno::UNO_SET_THROW );
82 throw uno::RuntimeException(
"No ViewShell available" );
89 const css::uno::Any& RefersTo,
90 const css::uno::Any& ,
91 const css::uno::Any& ,
92 const css::uno::Any& ,
93 const css::uno::Any& ,
94 const css::uno::Any& NameLocal,
95 const css::uno::Any& ,
96 const css::uno::Any& ,
97 const css::uno::Any& RefersToR1C1,
98 const css::uno::Any& RefersToR1C1Local )
101 uno::Reference< excel::XRange > xRange;
102 if (
Name.hasValue() )
104 else if ( NameLocal.hasValue() )
106 if ( !
sName.isEmpty() )
116 throw uno::RuntimeException(
"This Name is not valid ." );
119 uno::Reference< table::XCellRange > xUnoRange;
120 if ( RefersTo.hasValue() || RefersToR1C1.hasValue() || RefersToR1C1Local.hasValue() )
125 if ( RefersTo.hasValue() )
127 if ( RefersTo.getValueTypeClass() == uno::TypeClass_STRING )
132 if ( RefersToR1C1.hasValue() )
134 if ( RefersToR1C1.getValueTypeClass() == uno::TypeClass_STRING )
140 RefersToR1C1 >>= xRange;
142 if ( RefersToR1C1Local.hasValue() )
144 if ( RefersToR1C1Local.getValueTypeClass() == uno::TypeClass_STRING )
150 RefersToR1C1Local >>= xRange;
152 if ( !xRange.is() && !
sFormula.isEmpty() )
161 if (pTokens->IsValidReference(aRange, aBlank))
174 if ( aCellRanges.
size() == 1 )
178 uno::Reference< sheet::XSheetCellRangeContainer > xRanges(
new ScCellRangesObj( pDocSh, aCellRanges ) );
188 if ( xRange.is() || xUnoRange.is() )
193 uno::Reference< excel::XRange > xArea( xRange->Areas(
uno::Any( sal_Int32(1) ) ), uno::UNO_QUERY );
195 uno::Any aAny = xArea->getCellRange() ;
197 uno::Reference< sheet::XCellRangeAddressable > thisRangeAdd( aAny, ::uno::UNO_QUERY_THROW);
199 table::CellRangeAddress aAddr = thisRangeAdd->getRangeAddress();
203 table::CellAddress aCellAddr( aAddr.Sheet , aAddr.StartColumn , aAddr.StartRow );
206 OUStringBuffer sTmp =
"$";
207 uno::Reference< ov::XCollection > xCol( xRange->Areas(
uno::Any() ), uno::UNO_QUERY );
208 for ( sal_Int32 nArea = 1; nArea <= xCol->getCount(); ++nArea )
210 xArea.set( xRange->Areas(
uno::Any( nArea ) ), uno::UNO_QUERY_THROW );
212 OUString sRangeAdd = xArea->Address( aAny2, aAny2 , aAny2 , aAny2, aAny2 );
215 sTmp.append(
"'" + xRange->getWorksheet()->getName() +
"'." + sRangeAdd);
217 mxNames->addNewByName(
sName, sTmp.makeStringAndClear(), aCellAddr, 0);
221 return css::uno::Any();
231uno::Reference< container::XEnumeration >
234 uno::Reference< container::XEnumerationAccess > xEnumAccess(
mxNames, uno::UNO_QUERY_THROW );
241 uno::Reference< sheet::XNamedRange > xName( aSource, uno::UNO_QUERY );
251css::uno::Sequence<OUString>
256 "ooo.vba.excel.NamedRanges"
css::uno::Reference< css::frame::XModel2 > mxModel
css::uno::Reference< css::uno::XComponentContext > mxContext
css::uno::WeakReference< ov::XHelperInterface > mxParent
virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent() override
std::unique_ptr< ScTokenArray > CompileString(const OUString &rFormula)
Tokenize formula expression string into an array of tokens.
static SC_DLLPUBLIC IsNameValidType IsNameValid(const OUString &rName, const ScDocument &rDoc)
ScViewData & GetViewData()
css::uno::Reference< css::container::XNameAccess > m_xNameAccess
virtual css::uno::Any SAL_CALL Item(const css::uno::Any &Index1, const css::uno::Any &) override
css::uno::Reference< css::sheet::XNamedRanges > mxNames
ScVbaNames(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::sheet::XNamedRanges > &xNames, css::uno::Reference< css::frame::XModel > xModel)
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
css::uno::Reference< css::frame::XModel > mxModel
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual css::uno::Sequence< OUString > getServiceNames() override
ScDocument & getScDocument()
virtual css::uno::Type SAL_CALL getElementType() override
const css::uno::Reference< css::frame::XModel > & getModel() const
virtual ~ScVbaNames() override
virtual OUString getServiceImplName() override
virtual css::uno::Any SAL_CALL Add(const css::uno::Any &aName, const css::uno::Any &aRefersTo, const css::uno::Any &aVisible, const css::uno::Any &aMacroType, const css::uno::Any &aShoutcutKey, const css::uno::Any &aCategory, const css::uno::Any &aNameLocal, const css::uno::Any &aRefersToLocal, const css::uno::Any &aCategoryLocal, const css::uno::Any &aRefersToR1C1, const css::uno::Any &aRefersToR1C1Local) override
static bool getCellRangesForAddress(ScRefFlags &rResFlags, std::u16string_view sAddress, ScDocShell *pDocSh, ScRangeList &rCellRanges, formula::FormulaGrammar::AddressConvention eConv, char cDelimiter)
ScDocument & GetDocument() const
css::uno::Type const & get()
Reference< frame::XModel > m_xModel
Sequence< OUString > aServiceNames
ScDocShell * getDocShell(const css::uno::Reference< css::frame::XModel > &xModel)
ScTabViewShell * getBestViewShell(const css::uno::Reference< css::frame::XModel > &xModel)
Reference< XModel > xModel