20 #include <ooo/vba/excel/XFont.hpp>
21 #include <ooo/vba/excel/XStyle.hpp>
22 #include <ooo/vba/excel/XlVAlign.hpp>
23 #include <ooo/vba/excel/XlHAlign.hpp>
24 #include <ooo/vba/excel/XlOrientation.hpp>
25 #include <ooo/vba/excel/Constants.hpp>
26 #include <ooo/vba/excel/XRange.hpp>
27 #include <com/sun/star/table/CellVertJustify2.hpp>
28 #include <com/sun/star/table/CellHoriJustify.hpp>
29 #include <com/sun/star/table/CellOrientation.hpp>
30 #include <com/sun/star/table/XCellRange.hpp>
31 #include <com/sun/star/text/WritingMode.hpp>
32 #include <com/sun/star/util/CellProtection.hpp>
33 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
34 #include <com/sun/star/util/XNumberFormats.hpp>
35 #include <com/sun/star/util/XNumberFormatTypes.hpp>
36 #include <com/sun/star/frame/XModel.hpp>
39 #include <rtl/math.hxx>
48 #include <unonames.hxx>
56 #define FORMATSTRING "FormatString"
57 #define LOCALE "Locale"
59 template<
typename... Ifc >
61 const uno::Reference< uno::XComponentContext > & xContext,
62 const uno::Reference< beans::XPropertySet >& _xPropertySet,
63 const uno::Reference< frame::XModel >& xModel,
64 bool bCheckAmbiguoity )
66 m_aDefaultLocale(
"en",
"US", OUString() ),
67 mxPropertySet( _xPropertySet ),
69 mbCheckAmbiguoity( bCheckAmbiguoity ),
79 catch (
const uno::Exception& )
85 template<
typename... Ifc >
92 sal_Int32 nAlignment = 0;
93 if ( !(_oAlignment >>= nAlignment ))
94 throw uno::RuntimeException();
97 case excel::XlVAlign::xlVAlignBottom :
98 aVal <<= table::CellVertJustify2::BOTTOM;
100 case excel::XlVAlign::xlVAlignCenter :
101 aVal <<= table::CellVertJustify2::CENTER;
103 case excel::XlVAlign::xlVAlignDistributed:
104 case excel::XlVAlign::xlVAlignJustify:
105 aVal <<= table::CellVertJustify2::STANDARD;
108 case excel::XlVAlign::xlVAlignTop:
109 aVal <<= table::CellVertJustify2::TOP;
112 aVal <<= table::CellVertJustify2::STANDARD;
117 catch (
const uno::Exception&)
123 template<
typename... Ifc >
132 sal_Int32 aAPIAlignment = table::CellVertJustify2::STANDARD;
134 switch( aAPIAlignment )
136 case table::CellVertJustify2::BOTTOM:
137 aResult <<= excel::XlVAlign::xlVAlignBottom;
139 case table::CellVertJustify2::CENTER:
140 aResult <<= excel::XlVAlign::xlVAlignCenter;
142 case table::CellVertJustify2::STANDARD:
143 aResult <<= excel::XlVAlign::xlVAlignBottom;
145 case table::CellVertJustify2::TOP:
146 aResult <<= excel::XlVAlign::xlVAlignTop;
153 catch (
const uno::Exception& )
160 template<
typename... Ifc >
167 sal_Int32 nAlignment = 0;
168 if ( !( HorizontalAlignment >>= nAlignment ) )
169 throw uno::RuntimeException();
170 switch ( nAlignment )
172 case excel::XlHAlign::xlHAlignJustify:
173 aVal <<= table::CellHoriJustify_BLOCK;
175 case excel::XlHAlign::xlHAlignCenter:
176 aVal <<= table::CellHoriJustify_CENTER;
178 case excel::XlHAlign::xlHAlignDistributed:
179 aVal <<= table::CellHoriJustify_BLOCK;
181 case excel::XlHAlign::xlHAlignLeft:
182 aVal <<= table::CellHoriJustify_LEFT;
184 case excel::XlHAlign::xlHAlignRight:
185 aVal <<= table::CellHoriJustify_RIGHT;
193 catch (
const uno::Exception& )
200 template<
typename... Ifc >
208 if (!isAmbiguous(sHoriJust))
210 table::CellHoriJustify aAPIAlignment = table::CellHoriJustify_BLOCK;
212 if ( mxPropertySet->getPropertyValue(sHoriJust) >>= aAPIAlignment )
214 switch( aAPIAlignment )
216 case table::CellHoriJustify_BLOCK:
217 NRetAlignment <<= excel::XlHAlign::xlHAlignJustify;
219 case table::CellHoriJustify_CENTER:
220 NRetAlignment <<= excel::XlHAlign::xlHAlignCenter;
222 case table::CellHoriJustify_LEFT:
223 NRetAlignment <<= excel::XlHAlign::xlHAlignLeft;
225 case table::CellHoriJustify_RIGHT:
226 NRetAlignment <<= excel::XlHAlign::xlHAlignRight;
234 catch (
const uno::Exception& )
238 return NRetAlignment;
241 template<
typename... Ifc >
247 sal_Int32 nOrientation = 0;
248 if ( !( _aOrientation >>= nOrientation ) )
249 throw uno::RuntimeException();
251 switch( nOrientation )
253 case excel::XlOrientation::xlDownward:
254 aVal <<= table::CellOrientation_TOPBOTTOM;
256 case excel::XlOrientation::xlHorizontal:
257 aVal <<= table::CellOrientation_STANDARD;
258 mxPropertySet->setPropertyValue(
SC_UNONAME_ROTANG, uno::makeAny( sal_Int32(0) ) );
260 case excel::XlOrientation::xlUpward:
261 aVal <<= table::CellOrientation_BOTTOMTOP;
263 case excel::XlOrientation::xlVertical:
264 aVal <<= table::CellOrientation_STACKED;
273 catch (
const uno::Exception& )
278 template<
typename... Ifc >
287 table::CellOrientation aOrientation = table::CellOrientation_STANDARD;
289 throw uno::RuntimeException();
293 case table::CellOrientation_STANDARD:
294 NRetOrientation <<= excel::XlOrientation::xlHorizontal;
296 case table::CellOrientation_BOTTOMTOP:
297 NRetOrientation <<= excel::XlOrientation::xlUpward;
299 case table::CellOrientation_TOPBOTTOM:
300 NRetOrientation <<= excel::XlOrientation::xlDownward;
302 case table::CellOrientation_STACKED:
303 NRetOrientation <<= excel::XlOrientation::xlVertical;
306 NRetOrientation <<= excel::XlOrientation::xlHorizontal;
310 catch (
const uno::Exception& )
314 return NRetOrientation;
317 template<
typename... Ifc >
325 catch (
const uno::Exception& )
331 template<
typename... Ifc >
339 if (!isAmbiguous( aPropName ))
341 aWrap = mxPropertySet->getPropertyValue(aPropName);
344 catch (
const uno::Exception&)
351 template<
typename... Ifc >
356 uno::Reference< XCollection > xColl =
new ScVbaBorders( thisHelperIface(), ScVbaFormat_BASE::mxContext, uno::Reference< table::XCellRange >( mxPropertySet, uno::UNO_QUERY_THROW ), aPalette );
360 return xColl->Item( Index,
uno::Any() );
362 return uno::makeAny( xColl );
365 template<
typename... Ifc >
366 uno::Reference< excel::XFont > SAL_CALL
370 return new ScVbaFont( thisHelperIface(), ScVbaFormat_BASE::mxContext, aPalette, mxPropertySet );
373 template<
typename... Ifc >
374 uno::Reference< excel::XInterior > SAL_CALL
377 return new ScVbaInterior( thisHelperIface(), ScVbaFormat_BASE::mxContext, mxPropertySet );
380 template<
typename... Ifc >
384 uno::Any aRet = uno::makeAny( OUString() );
388 if (!isAmbiguous( sPropName ))
391 initializeNumberFormats();
393 sal_Int32 nFormat = 0;
394 if ( ! (mxPropertySet->getPropertyValue( sPropName ) >>= nFormat ) )
395 throw uno::RuntimeException();
398 xNumberFormats->getByKey(nFormat)->getPropertyValue(
FORMATSTRING ) >>= sFormat;
399 aRet <<= sFormat.toAsciiLowerCase();
403 catch (
const uno::Exception&)
411 template<
typename... Ifc >
417 OUString sLocalFormatString;
418 sal_Int32 nFormat = -1;
420 if ( !(_oLocalFormatString >>= sLocalFormatString )
421 || !( mxPropertySet->getPropertyValue(sNumFormat) >>= nFormat ) )
422 throw uno::RuntimeException();
424 sLocalFormatString = sLocalFormatString.toAsciiUpperCase();
425 initializeNumberFormats();
426 lang::Locale aRangeLocale;
427 xNumberFormats->getByKey(nFormat)->getPropertyValue(
LOCALE ) >>= aRangeLocale;
428 sal_Int32 nNewFormat = xNumberFormats->queryKey(sLocalFormatString, aRangeLocale,
true);
430 if (nNewFormat == -1)
431 nNewFormat = xNumberFormats->addNew(sLocalFormatString, aRangeLocale);
432 mxPropertySet->setPropertyValue(sNumFormat, uno::makeAny( nNewFormat ));
434 catch (
const uno::Exception& )
440 template<
typename... Ifc >
446 OUString sFormatString;
447 if ( !( _oFormatString >>= sFormatString ) )
448 throw uno::RuntimeException();
450 sFormatString = sFormatString.toAsciiUpperCase();
452 lang::Locale aDefaultLocale = m_aDefaultLocale;
453 initializeNumberFormats();
454 sal_Int32 nFormat = xNumberFormats->queryKey(sFormatString, aDefaultLocale,
true);
457 nFormat = xNumberFormats->addNew(sFormatString, aDefaultLocale);
459 lang::Locale aRangeLocale;
460 xNumberFormats->getByKey(nFormat)->getPropertyValue(
LOCALE ) >>= aRangeLocale;
461 sal_Int32 nNewFormat = xNumberFormatTypes->getFormatForLocale(nFormat, aRangeLocale);
464 catch (
const uno::Exception& )
471 template<
typename... Ifc >
477 sal_Int32 nLevel = 0;
478 if ( !(_aLevel >>= nLevel ) )
479 throw uno::RuntimeException();
480 table::CellHoriJustify aAPIAlignment = table::CellHoriJustify_STANDARD;
483 if ( !( mxPropertySet->getPropertyValue(sHoriJust) >>= aAPIAlignment ) )
484 throw uno::RuntimeException();
485 if (aAPIAlignment == table::CellHoriJustify_STANDARD)
486 mxPropertySet->setPropertyValue( sHoriJust, uno::makeAny( table::CellHoriJustify_LEFT) ) ;
487 mxPropertySet->setPropertyValue(
SC_UNONAME_PINDENT, uno::makeAny( sal_Int16(nLevel * 352.8) ) );
489 catch (
const uno::Exception&)
495 template<
typename... Ifc >
503 if (!isAmbiguous(sParaIndent))
505 sal_Int16 IndentLevel = 0;
506 if ( mxPropertySet->getPropertyValue(sParaIndent) >>= IndentLevel )
507 NRetIndentLevel <<= sal_Int32( rtl::math::round(static_cast<double>( IndentLevel ) / 352.8));
509 NRetIndentLevel <<= sal_Int32(0);
512 catch (
const uno::Exception&)
516 return NRetIndentLevel;
519 template<
typename... Ifc >
525 bool bIsLocked =
false;
526 if ( !( _aLocked >>= bIsLocked ) )
527 throw uno::RuntimeException();
528 util::CellProtection aCellProtection;
530 mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
531 aCellProtection.IsLocked = bIsLocked;
532 mxPropertySet->setPropertyValue(sCellProt, uno::makeAny( aCellProtection ) );
534 catch (
const uno::Exception&)
540 template<
typename... Ifc >
546 bool bIsFormulaHidden =
false;
547 FormulaHidden >>= bIsFormulaHidden;
548 util::CellProtection aCellProtection;
550 mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
551 aCellProtection.IsFormulaHidden = bIsFormulaHidden;
552 mxPropertySet->setPropertyValue(sCellProt,uno::makeAny(aCellProtection));
554 catch (
const uno::Exception&)
560 template<
typename... Ifc >
569 if (!isAmbiguous(sCellProt))
576 if(eState != SfxItemState::DONTCARE)
581 util::CellProtection cellProtection;
582 mxPropertySet->getPropertyValue(sCellProt) >>= cellProtection;
583 aCellProtection <<= cellProtection.IsLocked;
587 catch (
const uno::Exception&)
591 return aCellProtection;
594 template<
typename... Ifc >
602 if (!isAmbiguous(sCellProt))
609 if(eState != SfxItemState::DONTCARE)
614 util::CellProtection aCellProtection;
615 mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
616 aBoolRet <<= aCellProtection.IsFormulaHidden;
620 catch (
const uno::Exception&)
627 template<
typename... Ifc >
635 catch (
const uno::Exception& )
642 template<
typename... Ifc >
650 if (!isAmbiguous(sShrinkToFit))
651 aRet = mxPropertySet->getPropertyValue(sShrinkToFit);
653 catch (
const uno::Exception& )
660 template<
typename... Ifc >
666 sal_Int32 nReadingOrder = 0;
667 if ( !(ReadingOrder >>= nReadingOrder ))
668 throw uno::RuntimeException();
670 switch(nReadingOrder)
672 case excel::Constants::xlLTR:
673 aVal <<= sal_Int16(text::WritingMode_LR_TB);
675 case excel::Constants::xlRTL:
676 aVal <<= sal_Int16(text::WritingMode_RL_TB);
678 case excel::Constants::xlContext:
682 aVal <<= sal_Int16(text::WritingMode_LR_TB);
689 catch (
const uno::Exception& )
696 template<
typename... Ifc >
704 if (!isAmbiguous(sWritingMode))
706 text::WritingMode aWritingMode = text::WritingMode_LR_TB;
707 if ( ( mxPropertySet->getPropertyValue(sWritingMode) ) >>= aWritingMode )
708 switch (aWritingMode)
710 case text::WritingMode_LR_TB:
711 NRetReadingOrder <<= excel::Constants::xlLTR;
713 case text::WritingMode_RL_TB:
714 NRetReadingOrder <<= excel::Constants::xlRTL;
717 NRetReadingOrder <<= excel::Constants::xlRTL;
721 catch (
const uno::Exception& )
725 return NRetReadingOrder;
729 template<
typename... Ifc >
736 sal_Int32 nFormat = -1;
738 if (!isAmbiguous(sNumFormat) &&
739 ( mxPropertySet->getPropertyValue(sNumFormat) >>= nFormat) )
741 initializeNumberFormats();
743 sal_Int32 nNewFormat = xNumberFormatTypes->getFormatForLocale(nFormat, m_aDefaultLocale );
745 xNumberFormats->getByKey(nNewFormat)->getPropertyValue(
FORMATSTRING ) >>= sFormat;
749 catch (
const uno::Exception& )
756 template<
typename... Ifc >
760 bool bResult =
false;
763 if (mbCheckAmbiguoity)
764 bResult = ( getXPropertyState()->getPropertyState(_sPropertyName) == beans::PropertyState_AMBIGUOUS_VALUE );
766 catch (
const uno::Exception& )
773 template<
typename... Ifc >
777 if ( !xNumberFormats.is() )
779 mxNumberFormatsSupplier.set(
mxModel, uno::UNO_QUERY_THROW );
780 xNumberFormats = mxNumberFormatsSupplier->getNumberFormats();
781 xNumberFormatTypes.set( xNumberFormats, uno::UNO_QUERY );
785 template<
typename... Ifc >
786 uno::Reference< beans::XPropertyState >
const &
789 if ( !xPropertyState.is() )
790 xPropertyState.set( mxPropertySet, uno::UNO_QUERY_THROW );
791 return xPropertyState;
794 template<
typename... Ifc >
798 return comphelper::getUnoTunnelImplementation<ScCellRangesBase>( mxPropertySet );
801 template<
typename... Ifc >
805 SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( getCellRangesBase() );
807 throw uno::RuntimeException(
"Can't access Itemset for XPropertySet" );
css::uno::Reference< css::frame::XModel2 > mxModel
constexpr TypedWhichId< ScProtectionAttr > ATTR_PROTECTION(149)
#define ERRCODE_BASIC_NOT_IMPLEMENTED
#define SC_UNONAME_SHRINK_TO_FIT
#define SC_UNONAME_WRITING
#define SC_UNONAME_PINDENT
ScDocShell * getDocShell(const css::uno::Reference< css::frame::XModel > &xModel)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define SC_UNONAME_CELLPRO
bool GetHideFormula() const
#define SC_UNONAME_CELLHJUS
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
bool GetProtection() const
#define SC_UNONAME_ROTANG
#define SC_UNONAME_CELLORI
#define SC_UNONAME_CELLVJUS
#define ERRCODE_BASIC_METHOD_FAILED
#define SC_UNO_DP_NUMBERFO