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>
46 uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier;
50 ChartObjectEnumerationImpl(
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< container::XEnumeration >& xEnumeration, uno::Reference< drawing::XDrawPageSupplier > _xDrawPageSupplier,
const uno::Reference< XHelperInterface >& _xParent ) :
EnumerationHelperImpl( _xParent, xContext, xEnumeration ), xDrawPageSupplier(
std::move( _xDrawPageSupplier )) {}
51 virtual uno::Any SAL_CALL nextElement( )
override
57 uno::Reference< table::XTableChart > xTableChart( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
59 ret <<= uno::Reference< excel::XChartObject > (
new ScVbaChartObject( m_xParent, m_xContext, xTableChart, xDrawPageSupplier ) );
61 catch (
const lang::WrappedTargetException&)
65 catch (
const container::NoSuchElementException&)
69 catch (
const uno::RuntimeException&)
73 catch (
const uno::Exception&)
76 throw lang::WrappedTargetException(
77 "Error creating ScVbaChartObject!",
87ScVbaChartObjects::ScVbaChartObjects(
const css::uno::Reference< ov::XHelperInterface >& _xParent,
const css::uno::Reference< css::uno::XComponentContext >& _xContext,
const css::uno::Reference< css::table::XTableCharts >& _xTableCharts, uno::Reference< drawing::XDrawPageSupplier > _xDrawPageSupplier ) :
ChartObjects_BASE(_xParent,
_xContext, css::
uno::
Reference< css::container::XIndexAccess >( _xTableCharts, css::
uno::UNO_QUERY ) ), xTableCharts( _xTableCharts ) , xDrawPageSupplier(
std::move( _xDrawPageSupplier ))
98uno::Sequence< OUString >
101 uno::Sequence< OUString > sChartNames;
105 uno::Reference< uno::XInterface > xIf(
xDrawPageSupplier, uno::UNO_QUERY_THROW );
106 ScCellRangesBase* pUno =
dynamic_cast< ScCellRangesBase*
>( xIf.get() );
109 throw uno::RuntimeException(
"Failed to obtain the impl class from the drawpage" );
110 pDocShell = pUno->GetDocShell();
112 throw uno::RuntimeException(
"Failed to obtain the docshell implclass" );
114 uno::Reference< sheet::XSpreadsheets > xSpreadsheets = pDocShell->
GetModel()->
getSheets();
115 std::vector< OUString > aChartNamesVector;
117 const uno::Sequence< OUString > sSheetNames = xSpreadsheets->getElementNames();
118 for (
const auto& rSheetName : sSheetNames)
120 uno::Reference< table::XTableChartsSupplier > xLocTableChartsSupplier( xSpreadsheets->getByName(rSheetName), uno::UNO_QUERY_THROW );
121 const uno::Sequence< OUString > scurchartnames = xLocTableChartsSupplier->getCharts()->getElementNames();
122 aChartNamesVector.insert( aChartNamesVector.end(), scurchartnames.begin(), scurchartnames.end() );
126 catch (uno::Exception& )
128 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(
ERRCODE_BASIC_METHOD_FAILED), OUString() );
139 uno::Sequence< table::CellRangeAddress > aCellRangeAddress( 1 );
140 awt::Rectangle aRectangle;
141 aRectangle.X = Millimeter::getInHundredthsOfOneMillimeter(_nX);
142 aRectangle.Y = Millimeter::getInHundredthsOfOneMillimeter(_nY);
143 aRectangle.Width = Millimeter::getInHundredthsOfOneMillimeter(_nWidth);
144 aRectangle.Height = Millimeter::getInHundredthsOfOneMillimeter(_nHeight);
146 OUString sPersistChartName = ContainerUtilities::getUniqueName(
getChartObjectNames(),
"Chart " , std::u16string_view(), 1);
147 xTableCharts->addNewByName(sPersistChartName, aRectangle, aCellRangeAddress,
true,
false );
148 uno::Reference< excel::XChartObject > xChartObject(
getItemByStringIndex( sPersistChartName ), uno::UNO_QUERY_THROW );
149 xChartObject->getChart()->setChartType(excel::XlChartType::xlColumnClustered);
152 catch (
const uno::Exception&)
160 const uno::Sequence< OUString > sChartNames =
xTableCharts->getElementNames();
161 for (
const auto& rChartName : sChartNames)
167uno::Reference< container::XEnumeration >
170 css::uno::Reference< container::XEnumerationAccess > xEnumAccess(
xTableCharts, uno::UNO_QUERY_THROW );
186 uno::Reference< table::XTableChart > xTableChart( aSource, uno::UNO_QUERY_THROW );
194 return "ScVbaChartObjects";
197css::uno::Sequence<OUString>
200 static uno::Sequence< OUString >
const sNames
202 "ooo.vba.excel.ChartObjects"
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent() override
ScModelObj * GetModel() const
virtual css::uno::Reference< css::sheet::XSpreadsheets > SAL_CALL getSheets() override
XSpreadsheetDocument.
css::uno::Reference< css::table::XTableCharts > xTableCharts
virtual OUString getServiceImplName() override
void removeByName(const OUString &_sChartName)
css::uno::Sequence< OUString > getChartObjectNames() const
virtual void SAL_CALL Delete() override
css::uno::Reference< css::drawing::XDrawPageSupplier > xDrawPageSupplier
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) 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, css::uno::Reference< css::drawing::XDrawPageSupplier > _xDrawPageSupplier)
virtual css::uno::Type SAL_CALL getElementType() override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual css::uno::Any SAL_CALL Add(double Left, double Top, double Width, double Height) override
virtual css::uno::Any getItemByStringIndex(const OUString &sIndex)
css::uno::Type const & get()
#define DBG_UNHANDLED_EXCEPTION(...)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
Any SAL_CALL getCaughtException()
#define ERRCODE_BASIC_METHOD_FAILED
Reference< XComponentContext > _xContext