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>
58constexpr OUStringLiteral
LOCALE =
u"Locale";
60template<
typename... Ifc >
62 const uno::Reference< uno::XComponentContext > & xContext,
63 uno::Reference< beans::XPropertySet > _xPropertySet,
64 uno::Reference< frame::XModel > xModel,
65 bool bCheckAmbiguoity )
67 m_aDefaultLocale(
"en",
"US", OUString() ),
70 mbCheckAmbiguoity( bCheckAmbiguoity ),
80 catch (
const uno::Exception& )
82 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED, {} );
86template<
typename... Ifc >
93 sal_Int32 nAlignment = 0;
94 if ( !(_oAlignment >>= nAlignment ))
95 throw uno::RuntimeException();
98 case excel::XlVAlign::xlVAlignBottom :
99 aVal <<= table::CellVertJustify2::BOTTOM;
101 case excel::XlVAlign::xlVAlignCenter :
102 aVal <<= table::CellVertJustify2::CENTER;
104 case excel::XlVAlign::xlVAlignDistributed:
105 case excel::XlVAlign::xlVAlignJustify:
106 aVal <<= table::CellVertJustify2::STANDARD;
109 case excel::XlVAlign::xlVAlignTop:
110 aVal <<= table::CellVertJustify2::TOP;
113 aVal <<= table::CellVertJustify2::STANDARD;
118 catch (
const uno::Exception&)
124template<
typename... Ifc >
133 sal_Int32 aAPIAlignment = table::CellVertJustify2::STANDARD;
135 switch( aAPIAlignment )
137 case table::CellVertJustify2::BOTTOM:
138 aResult <<= excel::XlVAlign::xlVAlignBottom;
140 case table::CellVertJustify2::CENTER:
141 aResult <<= excel::XlVAlign::xlVAlignCenter;
143 case table::CellVertJustify2::STANDARD:
144 aResult <<= excel::XlVAlign::xlVAlignBottom;
146 case table::CellVertJustify2::TOP:
147 aResult <<= excel::XlVAlign::xlVAlignTop;
154 catch (
const uno::Exception& )
161template<
typename... Ifc >
168 sal_Int32 nAlignment = 0;
169 if ( !( HorizontalAlignment >>= nAlignment ) )
170 throw uno::RuntimeException();
171 switch ( nAlignment )
173 case excel::XlHAlign::xlHAlignJustify:
174 aVal <<= table::CellHoriJustify_BLOCK;
176 case excel::XlHAlign::xlHAlignCenter:
177 aVal <<= table::CellHoriJustify_CENTER;
179 case excel::XlHAlign::xlHAlignDistributed:
180 aVal <<= table::CellHoriJustify_BLOCK;
182 case excel::XlHAlign::xlHAlignLeft:
183 aVal <<= table::CellHoriJustify_LEFT;
185 case excel::XlHAlign::xlHAlignRight:
186 aVal <<= table::CellHoriJustify_RIGHT;
194 catch (
const uno::Exception& )
201template<
typename... Ifc >
209 if (!isAmbiguous(sHoriJust))
211 table::CellHoriJustify aAPIAlignment = table::CellHoriJustify_BLOCK;
213 if ( mxPropertySet->getPropertyValue(sHoriJust) >>= aAPIAlignment )
215 switch( aAPIAlignment )
217 case table::CellHoriJustify_BLOCK:
218 NRetAlignment <<= excel::XlHAlign::xlHAlignJustify;
220 case table::CellHoriJustify_CENTER:
221 NRetAlignment <<= excel::XlHAlign::xlHAlignCenter;
223 case table::CellHoriJustify_LEFT:
224 NRetAlignment <<= excel::XlHAlign::xlHAlignLeft;
226 case table::CellHoriJustify_RIGHT:
227 NRetAlignment <<= excel::XlHAlign::xlHAlignRight;
235 catch (
const uno::Exception& )
239 return NRetAlignment;
242template<
typename... Ifc >
248 sal_Int32 nOrientation = 0;
249 if ( !( _aOrientation >>= nOrientation ) )
250 throw uno::RuntimeException();
252 switch( nOrientation )
254 case excel::XlOrientation::xlDownward:
255 aVal <<= table::CellOrientation_TOPBOTTOM;
257 case excel::XlOrientation::xlHorizontal:
258 aVal <<= table::CellOrientation_STANDARD;
261 case excel::XlOrientation::xlUpward:
262 aVal <<= table::CellOrientation_BOTTOMTOP;
264 case excel::XlOrientation::xlVertical:
265 aVal <<= table::CellOrientation_STACKED;
274 catch (
const uno::Exception& )
279template<
typename... Ifc >
288 table::CellOrientation aOrientation = table::CellOrientation_STANDARD;
290 throw uno::RuntimeException();
294 case table::CellOrientation_STANDARD:
295 NRetOrientation <<= excel::XlOrientation::xlHorizontal;
297 case table::CellOrientation_BOTTOMTOP:
298 NRetOrientation <<= excel::XlOrientation::xlUpward;
300 case table::CellOrientation_TOPBOTTOM:
301 NRetOrientation <<= excel::XlOrientation::xlDownward;
303 case table::CellOrientation_STACKED:
304 NRetOrientation <<= excel::XlOrientation::xlVertical;
307 NRetOrientation <<= excel::XlOrientation::xlHorizontal;
311 catch (
const uno::Exception& )
315 return NRetOrientation;
318template<
typename... Ifc >
326 catch (
const uno::Exception& )
332template<
typename... Ifc >
342 aWrap = mxPropertySet->getPropertyValue(
aPropName);
345 catch (
const uno::Exception&)
352template<
typename... Ifc >
357 uno::Reference< XCollection > xColl =
new ScVbaBorders( thisHelperIface(), ScVbaFormat_BASE::mxContext, uno::Reference< table::XCellRange >( mxPropertySet, uno::UNO_QUERY_THROW ), aPalette );
359 if (
Index.hasValue() )
366template<
typename... Ifc >
367uno::Reference< excel::XFont > SAL_CALL
371 return new ScVbaFont( thisHelperIface(), ScVbaFormat_BASE::mxContext, aPalette, mxPropertySet );
374template<
typename... Ifc >
375uno::Reference< excel::XInterior > SAL_CALL
378 return new ScVbaInterior( thisHelperIface(), ScVbaFormat_BASE::mxContext, mxPropertySet );
381template<
typename... Ifc >
389 if (!isAmbiguous( sPropName ))
392 initializeNumberFormats();
394 sal_Int32 nFormat = 0;
395 if ( ! (mxPropertySet->getPropertyValue( sPropName ) >>= nFormat ) )
396 throw uno::RuntimeException();
399 xNumberFormats->getByKey(nFormat)->getPropertyValue(
FORMATSTRING ) >>= sFormat;
400 aRet <<= sFormat.toAsciiLowerCase();
404 catch (
const uno::Exception&)
412template<
typename... Ifc >
418 OUString sLocalFormatString;
419 sal_Int32 nFormat = -1;
421 if ( !(_oLocalFormatString >>= sLocalFormatString )
422 || !( mxPropertySet->getPropertyValue(sNumFormat) >>= nFormat ) )
423 throw uno::RuntimeException();
425 sLocalFormatString = sLocalFormatString.toAsciiUpperCase();
426 initializeNumberFormats();
427 lang::Locale aRangeLocale;
428 xNumberFormats->getByKey(nFormat)->getPropertyValue(
LOCALE ) >>= aRangeLocale;
429 sal_Int32 nNewFormat = xNumberFormats->queryKey(sLocalFormatString, aRangeLocale,
true);
431 if (nNewFormat == -1)
432 nNewFormat = xNumberFormats->addNew(sLocalFormatString, aRangeLocale);
433 mxPropertySet->setPropertyValue(sNumFormat,
uno::Any( nNewFormat ));
435 catch (
const uno::Exception& )
441template<
typename... Ifc >
447 OUString sFormatString;
448 if ( !( _oFormatString >>= sFormatString ) )
449 throw uno::RuntimeException();
451 sFormatString = sFormatString.toAsciiUpperCase();
453 lang::Locale aDefaultLocale = m_aDefaultLocale;
454 initializeNumberFormats();
455 sal_Int32 nFormat = xNumberFormats->queryKey(sFormatString, aDefaultLocale,
true);
458 nFormat = xNumberFormats->addNew(sFormatString, aDefaultLocale);
460 lang::Locale aRangeLocale;
461 xNumberFormats->getByKey(nFormat)->getPropertyValue(
LOCALE ) >>= aRangeLocale;
462 sal_Int32 nNewFormat = xNumberFormatTypes->getFormatForLocale(nFormat, aRangeLocale);
465 catch (
const uno::Exception& )
472template<
typename... Ifc >
478 sal_Int32 nLevel = 0;
479 if ( !(_aLevel >>= nLevel ) )
480 throw uno::RuntimeException();
481 table::CellHoriJustify aAPIAlignment = table::CellHoriJustify_STANDARD;
484 if ( !( mxPropertySet->getPropertyValue(sHoriJust) >>= aAPIAlignment ) )
485 throw uno::RuntimeException();
486 if (aAPIAlignment == table::CellHoriJustify_STANDARD)
487 mxPropertySet->setPropertyValue( sHoriJust,
uno::Any( table::CellHoriJustify_LEFT) ) ;
490 catch (
const uno::Exception&)
496template<
typename... Ifc >
504 if (!isAmbiguous(sParaIndent))
506 sal_Int16 IndentLevel = 0;
507 if ( mxPropertySet->getPropertyValue(sParaIndent) >>= IndentLevel )
508 NRetIndentLevel <<= sal_Int32( rtl::math::round(static_cast<double>( IndentLevel ) / 352.8));
510 NRetIndentLevel <<= sal_Int32(0);
513 catch (
const uno::Exception&)
517 return NRetIndentLevel;
520template<
typename... Ifc >
526 bool bIsLocked =
false;
527 if ( !( _aLocked >>= bIsLocked ) )
528 throw uno::RuntimeException();
529 util::CellProtection aCellProtection;
531 mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
532 aCellProtection.IsLocked = bIsLocked;
533 mxPropertySet->setPropertyValue(sCellProt,
uno::Any( aCellProtection ) );
535 catch (
const uno::Exception&)
541template<
typename... Ifc >
547 bool bIsFormulaHidden =
false;
548 FormulaHidden >>= bIsFormulaHidden;
549 util::CellProtection aCellProtection;
551 mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
552 aCellProtection.IsFormulaHidden = bIsFormulaHidden;
553 mxPropertySet->setPropertyValue(sCellProt,
uno::Any(aCellProtection));
555 catch (
const uno::Exception&)
561template<
typename... Ifc >
570 if (!isAmbiguous(sCellProt))
577 if(eState != SfxItemState::DONTCARE)
582 util::CellProtection cellProtection;
583 mxPropertySet->getPropertyValue(sCellProt) >>= cellProtection;
584 aCellProtection <<= cellProtection.IsLocked;
588 catch (
const uno::Exception&)
592 return aCellProtection;
595template<
typename... Ifc >
603 if (!isAmbiguous(sCellProt))
610 if(eState != SfxItemState::DONTCARE)
615 util::CellProtection aCellProtection;
616 mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
617 aBoolRet <<= aCellProtection.IsFormulaHidden;
621 catch (
const uno::Exception&)
628template<
typename... Ifc >
636 catch (
const uno::Exception& )
643template<
typename... Ifc >
651 if (!isAmbiguous(sShrinkToFit))
652 aRet = mxPropertySet->getPropertyValue(sShrinkToFit);
654 catch (
const uno::Exception& )
661template<
typename... Ifc >
667 sal_Int32 nReadingOrder = 0;
668 if ( !(ReadingOrder >>= nReadingOrder ))
669 throw uno::RuntimeException();
671 switch(nReadingOrder)
673 case excel::Constants::xlLTR:
674 aVal <<= sal_Int16(text::WritingMode_LR_TB);
676 case excel::Constants::xlRTL:
677 aVal <<= sal_Int16(text::WritingMode_RL_TB);
679 case excel::Constants::xlContext:
683 aVal <<= sal_Int16(text::WritingMode_LR_TB);
690 catch (
const uno::Exception& )
697template<
typename... Ifc >
705 if (!isAmbiguous(sWritingMode))
707 text::WritingMode aWritingMode = text::WritingMode_LR_TB;
708 if ( ( mxPropertySet->getPropertyValue(sWritingMode) ) >>= aWritingMode )
709 switch (aWritingMode)
711 case text::WritingMode_LR_TB:
712 NRetReadingOrder <<= excel::Constants::xlLTR;
714 case text::WritingMode_RL_TB:
715 NRetReadingOrder <<= excel::Constants::xlRTL;
718 NRetReadingOrder <<= excel::Constants::xlRTL;
722 catch (
const uno::Exception& )
726 return NRetReadingOrder;
730template<
typename... Ifc >
737 sal_Int32 nFormat = -1;
739 if (!isAmbiguous(sNumFormat) &&
740 ( mxPropertySet->getPropertyValue(sNumFormat) >>= nFormat) )
742 initializeNumberFormats();
744 sal_Int32 nNewFormat = xNumberFormatTypes->getFormatForLocale(nFormat, m_aDefaultLocale );
746 xNumberFormats->getByKey(nNewFormat)->getPropertyValue(
FORMATSTRING ) >>= sFormat;
750 catch (
const uno::Exception& )
757template<
typename... Ifc >
761 bool bResult =
false;
764 if (mbCheckAmbiguoity)
765 bResult = ( getXPropertyState()->getPropertyState(_sPropertyName) == beans::PropertyState_AMBIGUOUS_VALUE );
767 catch (
const uno::Exception& )
774template<
typename... Ifc >
778 if ( !xNumberFormats.is() )
780 mxNumberFormatsSupplier.set(
mxModel, uno::UNO_QUERY_THROW );
781 xNumberFormats = mxNumberFormatsSupplier->getNumberFormats();
782 xNumberFormatTypes.set( xNumberFormats, uno::UNO_QUERY );
786template<
typename... Ifc >
787uno::Reference< beans::XPropertyState >
const &
790 if ( !xPropertyState.is() )
791 xPropertyState.set( mxPropertySet, uno::UNO_QUERY_THROW );
792 return xPropertyState;
795template<
typename... Ifc >
799 return dynamic_cast<ScCellRangesBase*
>( mxPropertySet.get() );
802template<
typename... Ifc >
806 SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( getCellRangesBase() );
808 throw uno::RuntimeException(
"Can't access Itemset for XPropertySet" );
css::uno::Reference< css::frame::XModel2 > mxModel
bool GetHideFormula() const
bool GetProtection() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
Reference< XPropertySet > _xPropertySet
ScDocShell * getDocShell(const css::uno::Reference< css::frame::XModel > &xModel)
#define ERRCODE_BASIC_METHOD_FAILED
#define ERRCODE_BASIC_NOT_IMPLEMENTED
constexpr TypedWhichId< ScProtectionAttr > ATTR_PROTECTION(149)
Reference< XModel > xModel
constexpr OUStringLiteral SC_UNONAME_WRITING
constexpr OUStringLiteral SC_UNONAME_WRAP
constexpr OUStringLiteral SC_UNONAME_PINDENT
constexpr OUStringLiteral SC_UNONAME_CELLORI
constexpr OUStringLiteral SC_UNONAME_CELLPRO
constexpr OUStringLiteral SC_UNONAME_SHRINK_TO_FIT
constexpr OUStringLiteral SC_UNONAME_ROTANG
constexpr OUStringLiteral SC_UNONAME_CELLVJUS
#define SC_UNO_DP_NUMBERFO
constexpr OUStringLiteral SC_UNONAME_CELLHJUS