25#include <com/sun/star/sheet/XPrintAreas.hpp>
26#include <com/sun/star/sheet/XHeaderFooterContent.hpp>
27#include <com/sun/star/text/XText.hpp>
28#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
29#include <com/sun/star/container/XNameAccess.hpp>
30#include <ooo/vba/excel/XlPageOrientation.hpp>
31#include <ooo/vba/excel/XlOrder.hpp>
32#include <ooo/vba/excel/Constants.hpp>
33#include <ooo/vba/excel/XlPaperSize.hpp>
45 const uno::Reference< uno::XComponentContext >& xContext,
46 uno::Reference< sheet::XSpreadsheet > xSheet,
47 const uno::Reference< frame::XModel >& xModel):
52 uno::Reference< beans::XPropertySet > xSheetProps(
mxSheet, uno::UNO_QUERY_THROW );
53 uno::Any aValue = xSheetProps->getPropertyValue(
"PageStyle");
55 aValue >>= aStyleName;
57 uno::Reference< style::XStyleFamiliesSupplier > xStyleFamiliesSup(
mxModel, uno::UNO_QUERY_THROW );
58 uno::Reference< container::XNameAccess > xStyleFamilies = xStyleFamiliesSup->getStyleFamilies();
59 uno::Reference< container::XNameAccess > xPageStyle( xStyleFamilies->getByName(
"PageStyles"), uno::UNO_QUERY_THROW );
60 mxPageProps.set( xPageStyle->getByName(aStyleName), uno::UNO_QUERY_THROW );
61 mnOrientLandscape = excel::XlPageOrientation::xlLandscape;
62 mnOrientPortrait = excel::XlPageOrientation::xlPortrait;
63 mxPageProps->getPropertyValue(
"IsLandscape") >>=
mbIsLandscape;
69 uno::Reference< sheet::XPrintAreas > xPrintAreas(
mxSheet, uno::UNO_QUERY_THROW );
70 const uno::Sequence< table::CellRangeAddress >
aSeq = xPrintAreas->getPrintAreas();
71 if(
aSeq.hasElements() )
74 for(
const auto& rRange :
aSeq )
92 uno::Reference< sheet::XPrintAreas > xPrintAreas(
mxSheet, uno::UNO_QUERY_THROW );
93 if( rAreas.isEmpty() ||
94 rAreas.equalsIgnoreAsciiCase(
"FALSE" ) )
97 uno::Sequence< table::CellRangeAddress >
aSeq;
98 xPrintAreas->setPrintAreas(
aSeq );
106 uno::Sequence< table::CellRangeAddress >
aSeq( aCellRanges.
size() );
107 auto aSeqRange = asNonConstRange(
aSeq);
108 for (
size_t i = 0, nRanges = aCellRanges.
size();
i < nRanges; ++
i )
110 ScRange & rRange = aCellRanges[
i ];
111 table::CellRangeAddress aRangeAddress;
113 aSeqRange[
i++ ] = aRangeAddress;
115 xPrintAreas->setPrintAreas(
aSeq );
142 return mxPageProps->getPropertyValue(
"ScaleToPagesY");
149 sal_uInt16 scaleToPageY = 0;
151 if( fitToPagesTall.getValueTypeClass() != uno::TypeClass_BOOLEAN || (fitToPagesTall >>= aValue))
153 fitToPagesTall >>= scaleToPageY;
156 mxPageProps->setPropertyValue(
"ScaleToPagesY",
uno::Any( scaleToPageY ));
158 catch( uno::Exception& )
165 return mxPageProps->getPropertyValue(
"ScaleToPagesX");
172 sal_uInt16 scaleToPageX = 0;
174 if( fitToPagesWide.getValueTypeClass() != uno::TypeClass_BOOLEAN || (fitToPagesWide >>= aValue))
176 fitToPagesWide >>= scaleToPageX;
179 mxPageProps->setPropertyValue(
"ScaleToPagesX",
uno::Any( scaleToPageX ));
181 catch( uno::Exception& )
188 return mxPageProps->getPropertyValue(
"PageScale");
193 sal_uInt16 pageScale = 0;
196 if( zoom.getValueTypeClass() == uno::TypeClass_BOOLEAN )
215 sal_uInt16 nScale = 0;
216 mxPageProps->setPropertyValue(
"ScaleToPages",
uno::Any( nScale ));
217 mxPageProps->setPropertyValue(
"ScaleToPagesX",
uno::Any( nScale ));
218 mxPageProps->setPropertyValue(
"ScaleToPagesY",
uno::Any( nScale ));
220 catch (
const beans::UnknownPropertyException&)
227 catch (
const uno::Exception&)
231 mxPageProps->setPropertyValue(
"PageScale",
uno::Any( pageScale ));
239 uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue(
"RightPageHeaderContent"), uno::UNO_QUERY_THROW);
240 uno::Reference< text::XText > xText = xHeaderContent->getLeftText();
241 leftHeader = xText->getString();
243 catch( uno::Exception& )
254 uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue(
"RightPageHeaderContent"), uno::UNO_QUERY_THROW);
255 uno::Reference< text::XText > xText = xHeaderContent->getLeftText();
256 xText->setString( leftHeader );
257 mxPageProps->setPropertyValue(
"RightPageHeaderContent",
uno::Any(xHeaderContent) );
259 catch( uno::Exception& )
266 OUString centerHeader;
269 uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue(
"RightPageHeaderContent"), uno::UNO_QUERY_THROW);
270 uno::Reference< text::XText > xText = xHeaderContent->getCenterText();
271 centerHeader = xText->getString();
273 catch( uno::Exception& )
284 uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue(
"RightPageHeaderContent"), uno::UNO_QUERY_THROW);
285 uno::Reference< text::XText > xText = xHeaderContent->getCenterText();
286 xText->setString( centerHeader );
287 mxPageProps->setPropertyValue(
"RightPageHeaderContent",
uno::Any(xHeaderContent) );
289 catch( uno::Exception& )
296 OUString rightHeader;
299 uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue(
"RightPageHeaderContent"), uno::UNO_QUERY_THROW);
300 uno::Reference< text::XText > xText = xHeaderContent->getRightText();
301 rightHeader = xText->getString();
303 catch( uno::Exception& )
314 uno::Reference<sheet::XHeaderFooterContent> xHeaderContent( mxPageProps->getPropertyValue(
"RightPageHeaderContent"), uno::UNO_QUERY_THROW);
315 uno::Reference< text::XText > xText = xHeaderContent->getRightText();
316 xText->setString( rightHeader );
317 mxPageProps->setPropertyValue(
"RightPageHeaderContent",
uno::Any(xHeaderContent) );
319 catch( uno::Exception& )
329 uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue(
"RightPageFooterContent"), uno::UNO_QUERY_THROW);
330 uno::Reference< text::XText > xText = xFooterContent->getLeftText();
331 leftFooter = xText->getString();
333 catch( uno::Exception& )
344 uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue(
"RightPageFooterContent"), uno::UNO_QUERY_THROW);
345 uno::Reference< text::XText > xText = xFooterContent->getLeftText();
346 xText->setString( leftFooter );
347 mxPageProps->setPropertyValue(
"RightPageFooterContent",
uno::Any(xFooterContent) );
349 catch( uno::Exception& )
356 OUString centerFooter;
359 uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue(
"RightPageFooterContent"), uno::UNO_QUERY_THROW);
360 uno::Reference< text::XText > xText = xFooterContent->getCenterText();
361 centerFooter = xText->getString();
363 catch( uno::Exception& )
374 uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue(
"RightPageFooterContent"), uno::UNO_QUERY_THROW);
375 uno::Reference< text::XText > xText = xFooterContent->getCenterText();
376 xText->setString( centerFooter );
377 mxPageProps->setPropertyValue(
"RightPageFooterContent",
uno::Any(xFooterContent) );
379 catch( uno::Exception& )
387 OUString rightFooter;
390 uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue(
"RightPageFooterContent"), uno::UNO_QUERY_THROW);
391 uno::Reference< text::XText > xText = xFooterContent->getRightText();
392 rightFooter = xText->getString();
394 catch( uno::Exception& )
405 uno::Reference<sheet::XHeaderFooterContent> xFooterContent( mxPageProps->getPropertyValue(
"RightPageFooterContent"), uno::UNO_QUERY_THROW);
406 uno::Reference< text::XText > xText = xFooterContent->getRightText();
407 xText->setString( rightFooter );
408 mxPageProps->setPropertyValue(
"RightPageFooterContent",
uno::Any(xFooterContent) );
410 catch( uno::Exception& )
417 sal_Int32 order = excel::XlOrder::xlDownThenOver;
420 uno::Any aValue = mxPageProps->getPropertyValue(
"PrintDownFirst");
421 bool bPrintDownFirst =
false;
422 aValue >>= bPrintDownFirst;
423 if( !bPrintDownFirst )
424 order = excel::XlOrder::xlOverThenDown;
426 catch( uno::Exception& )
438 case excel::XlOrder::xlDownThenOver:
440 case excel::XlOrder::xlOverThenDown:
449 mxPageProps->setPropertyValue(
"PrintDownFirst",
uno::Any( bOrder ));
451 catch (
const uno::Exception&)
458 sal_Int16 number = 0;
461 uno::Any aValue = mxPageProps->getPropertyValue(
"FirstPageNumber");
464 catch( uno::Exception& )
470 number = excel::Constants::xlAutomatic;
478 if( firstPageNumber == excel::Constants::xlAutomatic )
484 aValue <<= static_cast<sal_Int16>(firstPageNumber);
485 mxPageProps->setPropertyValue(
"FirstPageNumber", aValue );
487 catch (
const uno::Exception&)
494 bool centerVertically =
false;
497 uno::Any aValue = mxPageProps->getPropertyValue(
"CenterVertically");
498 aValue >>= centerVertically;
500 catch (
const uno::Exception&)
503 return centerVertically;
510 mxPageProps->setPropertyValue(
"CenterVertically",
uno::Any( centerVertically ));
512 catch (
const uno::Exception&)
519 bool centerHorizontally =
false;
522 uno::Any aValue = mxPageProps->getPropertyValue(
"CenterHorizontally");
523 aValue >>= centerHorizontally;
525 catch (
const uno::Exception&)
528 return centerHorizontally;
535 mxPageProps->setPropertyValue(
"CenterHorizontally",
uno::Any( centerHorizontally ));
537 catch (
const uno::Exception&)
544 bool printHeadings =
false;
547 uno::Any aValue = mxPageProps->getPropertyValue(
"PrintHeaders");
548 aValue >>= printHeadings;
550 catch (
const uno::Exception&)
553 return printHeadings;
560 mxPageProps->setPropertyValue(
"PrintHeaders",
uno::Any( printHeadings ));
562 catch( uno::Exception& )
595 mxPageProps->getPropertyValue(
"Size" ) >>= aSize;
597 ::std::swap( aSize.Width, aSize.Height );
600 if ( nPaperSizeIndex == 0 )
601 nPaperSizeIndex = excel::XlPaperSize::xlPaperUser;
602 return nPaperSizeIndex;
607 if ( papersize != excel::XlPaperSize::xlPaperUser )
609 awt::Size aPaperSize;
611 aPaperSize.Height = rConvertedSize.
mnHeight;
612 aPaperSize.Width = rConvertedSize.
mnWidth;
614 ::std::swap( aPaperSize.Width, aPaperSize.Height );
615 mxPageProps->setPropertyValue(
"Size",
uno::Any( aPaperSize ) );
622 return "ScVbaPageSetup";
625uno::Sequence< OUString >
630 "ooo.vba.excel.PageSetup"
css::uno::Reference< css::frame::XModel2 > mxModel
void Format(OUString &, ScRefFlags nFlags, const ScDocument &, formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO, sal_Unicode cDelimiter=0, bool bFullAddressNotation=false) const
void push_back(const ScRange &rRange)
static void FillScRange(ScRange &rScRange, const css::table::CellRangeAddress &rApiRange)
static void FillApiRange(css::table::CellRangeAddress &rApiRange, const ScRange &rScRange)
virtual void SAL_CALL setCenterVertically(sal_Bool centerVertically) override
virtual OUString SAL_CALL getCenterFooter() override
virtual sal_Bool SAL_CALL getCenterVertically() override
virtual void SAL_CALL setLeftFooter(const OUString &leftFooter) override
virtual void SAL_CALL setRightFooter(const OUString &rightFooter) override
virtual void SAL_CALL setPrintArea(const OUString &rAreas) override
virtual OUString SAL_CALL getRightFooter() override
virtual void SAL_CALL setLeftHeader(const OUString &leftHeader) override
virtual void SAL_CALL setPrintHeadings(sal_Bool printHeadings) override
void SAL_CALL setHeaderMargin(double margin) override
virtual OUString SAL_CALL getPrintTitleColumns() override
virtual void SAL_CALL setRightHeader(const OUString &rightHeader) override
virtual void SAL_CALL setOrder(sal_Int32 order) override
virtual void SAL_CALL setPaperSize(sal_Int32 papersize) override
void SAL_CALL setFooterMargin(double margin) override
virtual void SAL_CALL setFitToPagesTall(const css::uno::Any &fitToPagesTall) override
virtual sal_Bool SAL_CALL getCenterHorizontally() override
virtual void SAL_CALL setFirstPageNumber(sal_Int32 firstPageNumber) override
virtual sal_Int32 SAL_CALL getFirstPageNumber() override
virtual OUString SAL_CALL getPrintArea() override
virtual void SAL_CALL setCenterHeader(const OUString ¢erHeader) override
virtual css::uno::Any SAL_CALL getFitToPagesTall() override
virtual css::uno::Sequence< OUString > getServiceNames() override
double SAL_CALL getFooterMargin() override
virtual OUString SAL_CALL getPrintTitleRows() override
virtual void SAL_CALL setCenterHorizontally(sal_Bool centerHorizontally) override
virtual sal_Bool SAL_CALL getPrintHeadings() override
virtual sal_Int32 SAL_CALL getPaperSize() override
virtual OUString SAL_CALL getLeftFooter() override
ScVbaPageSetup(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, css::uno::Reference< css::sheet::XSpreadsheet > xSheet, const css::uno::Reference< css::frame::XModel > &xModel)
virtual double SAL_CALL getHeaderMargin() override
virtual OUString SAL_CALL getLeftHeader() override
virtual void SAL_CALL setCenterFooter(const OUString ¢erFooter) override
virtual css::uno::Any SAL_CALL getZoom() override
virtual void SAL_CALL setPrintTitleColumns(const OUString &_printtitlecolumns) override
virtual void SAL_CALL setPrintTitleRows(const OUString &_printtitlerows) override
virtual void SAL_CALL setFitToPagesWide(const css::uno::Any &fitToPagesWide) override
virtual OUString SAL_CALL getRightHeader() override
css::uno::Reference< css::sheet::XSpreadsheet > mxSheet
virtual sal_Int32 SAL_CALL getOrder() override
virtual css::uno::Any SAL_CALL getFitToPagesWide() override
virtual void SAL_CALL setPrintGridlines(sal_Bool _printgridlines) override
virtual OUString SAL_CALL getCenterHeader() override
virtual sal_Bool SAL_CALL getPrintGridlines() override
virtual void SAL_CALL setZoom(const css::uno::Any &zoom) override
virtual OUString getServiceImplName() override
virtual void SAL_CALL setFooterMargin(double margin)
virtual double SAL_CALL getFooterMargin()
virtual void SAL_CALL setHeaderMargin(double margin)
virtual double SAL_CALL getHeaderMargin()
static const ApiPaperSize & getApiSizeForMSPaperSizeIndex(sal_Int32 nMSOPaperIndex)
static sal_Int32 getMSPaperSizeIndex(const css::awt::Size &rSize)
Sequence< OUString > aServiceNames
Sequence< sal_Int8 > aSeq
ScDocShell * getDocShell(const css::uno::Reference< css::frame::XModel > &xModel)
#define ERRCODE_BASIC_BAD_PARAMETER
Reference< XModel > xModel
cppu::ImplInheritanceHelper< VbaPageSetupBase, ov::excel::XPageSetup > ScVbaPageSetup_BASE
bool getScRangeListForAddress(const OUString &sName, ScDocShell *pDocSh, const ScRange &refRange, ScRangeList &aCellRanges, formula::FormulaGrammar::AddressConvention aConv)