20 #include <com/sun/star/table/XTableChartsSupplier.hpp>
21 #include <com/sun/star/table/XTableChart.hpp>
22 #include <com/sun/star/script/BasicErrorException.hpp>
23 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
24 #include <ooo/vba/excel/XlChartType.hpp>
31 #include <string_view>
44 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier;
48 ChartObjectEnumerationImpl(
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< container::XEnumeration >& xEnumeration,
const uno::Reference< drawing::XDrawPageSupplier >& _xDrawPageSupplier,
const uno::Reference< XHelperInterface >& _xParent ) :
EnumerationHelperImpl( _xParent, xContext, xEnumeration ), xDrawPageSupplier( _xDrawPageSupplier ) {}
49 virtual uno::Any SAL_CALL nextElement( )
override
55 uno::Reference< table::XTableChart > xTableChart( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
57 ret <<= uno::Reference< excel::XChartObject > (
new ScVbaChartObject( m_xParent, m_xContext, xTableChart, xDrawPageSupplier ) );
59 catch (
const lang::WrappedTargetException&)
63 catch (
const container::NoSuchElementException&)
67 catch (
const uno::RuntimeException&)
71 catch (
const uno::Exception&)
74 throw lang::WrappedTargetException(
75 "Error creating ScVbaChartObject!",
76 static_cast < OWeakObject * > (
this ),
85 ScVbaChartObjects::ScVbaChartObjects(
const css::uno::Reference< ov::XHelperInterface >& _xParent,
const css::uno::Reference< css::uno::XComponentContext >& _xContext,
const css::uno::Reference< css::table::XTableCharts >& _xTableCharts,
const uno::Reference< drawing::XDrawPageSupplier >& _xDrawPageSupplier ) :
ChartObjects_BASE(_xParent, _xContext,
css::
uno::
Reference<
css::
container::XIndexAccess >( _xTableCharts,
css::
uno::UNO_QUERY ) ), xTableCharts( _xTableCharts ) , xDrawPageSupplier( _xDrawPageSupplier )
96 uno::Sequence< OUString >
99 uno::Sequence< OUString > sChartNames;
103 uno::Reference< uno::XInterface > xIf( xDrawPageSupplier, uno::UNO_QUERY_THROW );
107 throw uno::RuntimeException(
"Failed to obtain the impl class from the drawpage" );
110 throw uno::RuntimeException(
"Failed to obtain the docshell implclass" );
112 uno::Reference< sheet::XSpreadsheetDocument > xSpreadsheetDocument( pDocShell->
GetModel(), uno::UNO_QUERY_THROW );
113 uno::Reference< sheet::XSpreadsheets > xSpreadsheets = xSpreadsheetDocument->getSheets();
114 std::vector< OUString > aChartNamesVector;
116 const uno::Sequence< OUString > sSheetNames = xSpreadsheets->getElementNames();
117 for (
const auto& rSheetName : sSheetNames)
119 uno::Reference< table::XTableChartsSupplier > xLocTableChartsSupplier( xSpreadsheets->getByName(rSheetName), uno::UNO_QUERY_THROW );
120 const uno::Sequence< OUString > scurchartnames = xLocTableChartsSupplier->getCharts()->getElementNames();
121 aChartNamesVector.insert( aChartNamesVector.end(), scurchartnames.begin(), scurchartnames.end() );
125 catch (uno::Exception& )
127 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(
ERRCODE_BASIC_METHOD_FAILED), OUString() );
138 uno::Sequence< table::CellRangeAddress > aCellRangeAddress( 1 );
139 awt::Rectangle aRectangle;
140 aRectangle.X = Millimeter::getInHundredthsOfOneMillimeter(_nX);
141 aRectangle.Y = Millimeter::getInHundredthsOfOneMillimeter(_nY);
142 aRectangle.Width = Millimeter::getInHundredthsOfOneMillimeter(_nWidth);
143 aRectangle.Height = Millimeter::getInHundredthsOfOneMillimeter(_nHeight);
145 OUString sPersistChartName = ContainerUtilities::getUniqueName(
getChartObjectNames(),
"Chart " , std::u16string_view(), 1);
146 xTableCharts->addNewByName(sPersistChartName, aRectangle, aCellRangeAddress,
true,
false );
147 uno::Reference< excel::XChartObject > xChartObject(
getItemByStringIndex( sPersistChartName ), uno::UNO_QUERY_THROW );
148 xChartObject->getChart()->setChartType(excel::XlChartType::xlColumnClustered);
151 catch (
const uno::Exception&)
159 const uno::Sequence< OUString > sChartNames =
xTableCharts->getElementNames();
160 for (
const auto& rChartName : sChartNames)
166 uno::Reference< container::XEnumeration >
169 css::uno::Reference< container::XEnumerationAccess > xEnumAccess(
xTableCharts, uno::UNO_QUERY_THROW );
185 uno::Reference< table::XTableChart > xTableChart( aSource, uno::UNO_QUERY_THROW );
193 return "ScVbaChartObjects";
196 css::uno::Sequence<OUString>
199 static uno::Sequence< OUString >
const sNames
201 "ooo.vba.excel.ChartObjects"
virtual css::uno::Any SAL_CALL Add(double Left, double Top, double Width, double Height) override
ScDocShell * GetDocShell() const
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
css::uno::Reference< css::frame::XModel3 > GetModel() const
virtual css::uno::Any getItemByStringIndex(const OUString &sIndex)
void removeByName(const OUString &_sChartName)
exports com.sun.star. container
Any SAL_CALL getCaughtException()
css::uno::Sequence< OUString > getChartObjectNames() const
#define DBG_UNHANDLED_EXCEPTION(...)
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
virtual void SAL_CALL Delete() override
virtual css::uno::Type SAL_CALL getElementType() override
css::uno::Type const & get()
virtual OUString getServiceImplName() override
ScVbaChartObjects(const css::uno::Reference< ov::XHelperInterface > &_xParent, const css::uno::Reference< css::uno::XComponentContext > &_xContext, const css::uno::Reference< css::table::XTableCharts > &_xTableCharts, const css::uno::Reference< css::drawing::XDrawPageSupplier > &_xDrawPageSupplier)
css::uno::Reference< css::drawing::XDrawPageSupplier > xDrawPageSupplier
virtual css::uno::Sequence< OUString > getServiceNames() override
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent() override
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
#define ERRCODE_BASIC_METHOD_FAILED
css::uno::Reference< css::table::XTableCharts > xTableCharts