20#include <com/sun/star/beans/XPropertySet.hpp>
21#include <com/sun/star/lang/XMultiServiceFactory.hpp>
22#include <com/sun/star/sheet/XCellRangeAddressable.hpp>
23#include <com/sun/star/chart/XAxisXSupplier.hpp>
24#include <com/sun/star/chart/XAxisYSupplier.hpp>
25#include <com/sun/star/chart/XAxisZSupplier.hpp>
26#include <com/sun/star/chart/XTwoAxisXSupplier.hpp>
27#include <com/sun/star/chart/XTwoAxisYSupplier.hpp>
28#include <com/sun/star/chart/XChartDataArray.hpp>
29#include <com/sun/star/chart/ChartSymbolType.hpp>
30#include <com/sun/star/chart/ChartSolidType.hpp>
31#include <com/sun/star/chart/ChartDataRowSource.hpp>
32#include <ooo/vba/excel/XlChartType.hpp>
33#include <ooo/vba/excel/XlRowCol.hpp>
34#include <ooo/vba/excel/XlAxisType.hpp>
35#include <ooo/vba/excel/XlAxisGroup.hpp>
42#include <document.hxx>
47using namespace ::ooo::vba::excel::XlChartType;
48using namespace ::ooo::vba::excel::XlRowCol;
49using namespace ::ooo::vba::excel::XlAxisType;
50using namespace ::ooo::vba::excel::XlAxisGroup;
56constexpr OUStringLiteral
UPDOWN(u
"UpDown");
57constexpr OUStringLiteral
VOLUME(u
"Volume");
58constexpr OUStringLiteral
LINES(u
"Lines");
61constexpr OUStringLiteral
DEEP(u
"Deep");
63constexpr OUStringLiteral
VERTICAL(u
"Vertical");
64constexpr OUStringLiteral
PERCENT(u
"Percent");
65constexpr OUStringLiteral
STACKED(u
"Stacked");
66constexpr OUStringLiteral
DIM3D(u
"Dim3D");
70ScVbaChart::ScVbaChart(
const css::uno::Reference< ov::XHelperInterface >& _xParent,
const css::uno::Reference< css::uno::XComponentContext >& _xContext,
const css::uno::Reference< css::lang::XComponent >& _xChartComponent, css::uno::Reference< css::table::XTableChart > _xTableChart ) :
ChartImpl_BASE( _xParent,
_xContext ), mxTableChart(
std::move( _xTableChart ))
86 uno::Reference< beans::XPropertySet > xProps(
mxChartDocument, uno::UNO_QUERY_THROW );
91 catch(
const uno::Exception & )
106 sal_Int32 nChartType = -1;
109 OUString sDiagramType =
mxChartDocument->getDiagram()->getDiagramType();
110 if ( sDiagramType ==
"com.sun.star.chart.AreaDiagram" )
114 nChartType =
getStackedType(xl3DAreaStacked, xl3DAreaStacked100, xl3DArea);
118 nChartType =
getStackedType(xlAreaStacked, xlAreaStacked100, xlArea);
121 else if ( sDiagramType ==
"com.sun.star.chart.PieDiagram" )
124 nChartType = xl3DPie;
128 else if ( sDiagramType ==
"com.sun.star.chart.BarDiagram" )
130 sal_Int32 nSolidType = chart::ChartSolidType::RECTANGULAR_SOLID;
138 case chart::ChartSolidType::CONE:
139 nChartType =
getSolidType(xlConeCol, xlConeColStacked, xlConeColStacked100, xlConeColClustered, xlConeBarStacked, xlConeBarStacked100, xlConeBarClustered);
141 case chart::ChartSolidType::CYLINDER:
142 nChartType =
getSolidType(xlCylinderCol, xlCylinderColStacked, xlCylinderColStacked100, xlCylinderColClustered, xlCylinderBarStacked, xlCylinderBarStacked100, xlCylinderBarClustered);
144 case chart::ChartSolidType::PYRAMID:
145 nChartType =
getSolidType(xlPyramidCol, xlPyramidColStacked, xlPyramidColStacked100, xlPyramidColClustered, xlPyramidBarStacked, xlPyramidBarStacked100, xlPyramidBarClustered);
150 nChartType =
getSolidType(xl3DColumn, xl3DColumnStacked, xl3DColumnStacked100, xl3DColumnClustered, xl3DBarStacked, xl3DBarStacked100, xl3DBarClustered);
154 nChartType =
getSolidType(xlColumnClustered, xlColumnStacked, xlColumnStacked100, xlColumnClustered, xlBarStacked, xlBarStacked100, xlBarClustered);
159 else if ( sDiagramType ==
"com.sun.star.chart.StockDiagram" )
161 bool bVolume =
false;
172 else if ( sDiagramType ==
"com.sun.star.chart.XYDiagram" )
174 bool bHasLines =
false;
176 sal_Int32 nSplineType = 0;
178 if (nSplineType == 1)
180 nChartType =
getMarkerType(xlXYScatterSmooth, xlXYScatterSmoothNoMarkers);
184 nChartType =
getMarkerType(xlXYScatterLines, xlXYScatterLinesNoMarkers);
188 nChartType = xlXYScatter;
191 else if ( sDiagramType ==
"com.sun.star.chart.LineDiagram" )
195 nChartType = xl3DLine;
199 nChartType =
getStackedType(xlLineMarkersStacked, xlLineMarkersStacked100, xlLineMarkers);
203 nChartType =
getStackedType(xlLineStacked, xlLineStacked100, xlLine);
206 else if ( sDiagramType ==
"com.sun.star.chart.DonutDiagram" )
208 nChartType = xlDoughnut;
210 else if ( sDiagramType ==
"com.sun.star.chart.NetDiagram" )
215 catch (
const uno::Exception& )
217 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(
ERRCODE_BASIC_METHOD_FAILED), OUString() );
229 case xlColumnClustered:
230 case xlColumnStacked:
231 case xlColumnStacked100:
232 case xl3DColumnClustered:
233 case xl3DColumnStacked:
234 case xl3DColumnStacked100:
238 case xlBarStacked100:
239 case xl3DBarClustered:
241 case xl3DBarStacked100:
242 case xlConeColClustered:
243 case xlConeColStacked:
244 case xlConeColStacked100:
245 case xlConeBarClustered:
246 case xlConeBarStacked:
247 case xlConeBarStacked100:
249 case xlPyramidColClustered:
250 case xlPyramidColStacked:
251 case xlPyramidColStacked100:
252 case xlPyramidBarClustered:
253 case xlPyramidBarStacked:
254 case xlPyramidBarStacked100:
256 case xlCylinderColClustered:
257 case xlCylinderColStacked:
258 case xlCylinderColStacked100:
259 case xlCylinderBarClustered:
260 case xlCylinderBarStacked:
261 case xlCylinderBarStacked100:
264 case xlSurfaceWireframe:
265 case xlSurfaceTopView:
266 case xlSurfaceTopViewWireframe:
272 case xlLineStacked100:
274 case xlLineMarkersStacked:
275 case xlLineMarkersStacked100:
276 setDiagram(
"com.sun.star.chart.LineDiagram");
281 case xlAreaStacked100:
282 case xl3DAreaStacked:
283 case xl3DAreaStacked100:
284 setDiagram(
"com.sun.star.chart.AreaDiagram" );
287 case xlDoughnutExploded:
288 setDiagram(
"com.sun.star.chart.DonutDiagram" );
294 setDiagram(
"com.sun.star.chart.StockDiagram");
301 case xl3DPieExploded:
315 case xlBubble3DEffect:
316 case xlXYScatterLines:
317 case xlXYScatterLinesNoMarkers:
318 case xlXYScatterSmooth:
319 case xlXYScatterSmoothNoMarkers:
325 case xlBubble3DEffect:
328 case xlXYScatterLines:
329 case xlXYScatterLinesNoMarkers:
332 case xlXYScatterSmooth:
333 case xlXYScatterSmoothNoMarkers:
341 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(
ERRCODE_BASIC_CONVERSION), OUString() );
347 case xlLineMarkersStacked:
348 case xlLineMarkersStacked100:
350 case xlXYScatterLines:
351 case xlXYScatterSmooth:
354 case xlBubble3DEffect:
372 case xlSurfaceWireframe:
373 case xlSurfaceTopView:
374 case xlSurfaceTopViewWireframe:
387 case xlConeColClustered:
388 case xlConeColStacked:
389 case xlConeColStacked100:
390 case xlConeBarClustered:
391 case xlConeBarStacked:
392 case xlConeBarStacked100:
396 case xlPyramidColClustered:
397 case xlPyramidColStacked:
398 case xlPyramidColStacked100:
399 case xlPyramidBarClustered:
400 case xlPyramidBarStacked:
401 case xlPyramidBarStacked100:
405 case xlCylinderColClustered:
406 case xlCylinderColStacked:
407 case xlCylinderColStacked100:
408 case xlCylinderBarClustered:
409 case xlCylinderBarStacked:
410 case xlCylinderBarStacked100:
422 switch ( _nChartType)
425 case xlConeColClustered:
426 case xlConeColStacked:
427 case xlConeColStacked100:
428 case xlPyramidColClustered:
429 case xlPyramidColStacked:
430 case xlPyramidColStacked100:
431 case xlCylinderColClustered:
432 case xlCylinderColStacked:
433 case xlCylinderColStacked100:
434 case xlColumnClustered:
435 case xlColumnStacked:
436 case xlColumnStacked100:
437 case xl3DColumnClustered:
438 case xl3DColumnStacked:
439 case xl3DColumnStacked100:
441 case xlSurfaceWireframe:
442 case xlSurfaceTopView:
443 case xlSurfaceTopViewWireframe:
456 case xlColumnStacked:
457 case xl3DColumnStacked:
461 case xlLineMarkersStacked:
463 case xl3DAreaStacked:
464 case xlCylinderColStacked:
465 case xlCylinderBarStacked:
466 case xlConeColStacked:
467 case xlConeBarStacked:
468 case xlPyramidColStacked:
469 case xlPyramidBarStacked:
473 case xlPyramidColStacked100:
474 case xlPyramidBarStacked100:
475 case xlConeColStacked100:
476 case xlConeBarStacked100:
477 case xlCylinderBarStacked100:
478 case xlCylinderColStacked100:
479 case xl3DAreaStacked100:
480 case xlLineMarkersStacked100:
481 case xlAreaStacked100:
482 case xlLineStacked100:
483 case xl3DBarStacked100:
484 case xlBarStacked100:
485 case xl3DColumnStacked100:
486 case xlColumnStacked100:
498 case xl3DAreaStacked:
499 case xl3DAreaStacked100:
500 case xl3DBarClustered:
502 case xl3DBarStacked100:
504 case xl3DColumnClustered:
505 case xl3DColumnStacked:
506 case xl3DColumnStacked100:
509 case xl3DPieExploded:
510 case xlConeColClustered:
511 case xlConeColStacked:
512 case xlConeColStacked100:
513 case xlConeBarClustered:
514 case xlConeBarStacked:
515 case xlConeBarStacked100:
517 case xlPyramidColClustered:
518 case xlPyramidColStacked:
519 case xlPyramidColStacked100:
520 case xlPyramidBarClustered:
521 case xlPyramidBarStacked:
522 case xlPyramidBarStacked100:
524 case xlCylinderColClustered:
525 case xlCylinderColStacked:
526 case xlCylinderColStacked100:
527 case xlCylinderBarClustered:
528 case xlCylinderBarStacked:
529 case xlCylinderBarStacked100:
541 catch (
const uno::Exception& )
543 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(
ERRCODE_BASIC_METHOD_FAILED), OUString() );
554 uno::Reference< XHelperInterface > xParent(
getParent() );
557 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(
ERRCODE_BASIC_METHOD_FAILED),
"no ChartObject as parent" );
568 table::CellRangeAddress aSingleRangeAddress;
570 uno::Reference< sheet::XCellRangeAddressable > xAddressable( _xCalcRange->getCellRange(), uno::UNO_QUERY_THROW );
571 aSingleRangeAddress = xAddressable->getRangeAddress();
575 bool bsetRowHeaders =
false;
576 bool bsetColumnHeaders =
false;
582 bsetRowHeaders = rDoc.
HasRowHeader(
static_cast< SCCOL >( aSingleRangeAddress.StartColumn ),
static_cast< SCROW >( aSingleRangeAddress.StartRow ),
static_cast< SCCOL >( aSingleRangeAddress.EndColumn ),
static_cast< SCROW >( aSingleRangeAddress.EndRow ),
static_cast< SCTAB >( aSingleRangeAddress.Sheet ) );
583 bsetColumnHeaders = rDoc.
HasColHeader(
static_cast< SCCOL >( aSingleRangeAddress.StartColumn ),
static_cast< SCROW >( aSingleRangeAddress.StartRow ),
static_cast< SCCOL >( aSingleRangeAddress.EndColumn ),
static_cast< SCROW >( aSingleRangeAddress.EndRow ),
static_cast< SCTAB >( aSingleRangeAddress.Sheet ));
588 if ((!bsetColumnHeaders) || (!bsetRowHeaders))
590 uno::Reference< chart::XChartDataArray > xChartDataArray(
mxChartDocument->getData(), uno::UNO_QUERY_THROW );
591 if (!bsetColumnHeaders)
601 if ( _aPlotBy.hasValue() )
609 sal_Int32 nRows = aSingleRangeAddress.EndRow - aSingleRangeAddress.StartRow;
610 sal_Int32 nCols = aSingleRangeAddress.EndColumn - aSingleRangeAddress.StartColumn;
614 else if ( nRows <= nCols )
618 catch (
const uno::Exception&)
620 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(
ERRCODE_BASIC_METHOD_FAILED), OUString() );
624uno::Sequence< OUString >
627 uno::Sequence< OUString > sDescriptions ( _nCount );
628 std::generate_n(sDescriptions.getArray(), _nCount,
629 [
i = 1]() mutable -> OUString { return DEFAULTSERIESPREFIX + OUString::number(i++); });
630 return sDescriptions;
655 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(
ERRCODE_BASIC_METHOD_FAILED), OUString() );
658 catch (
const uno::Exception&)
660 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(
ERRCODE_BASIC_METHOD_FAILED), OUString() );
669 chart::ChartDataRowSource aChartDataRowSource;
671 if (aChartDataRowSource == chart::ChartDataRowSource_COLUMNS)
680 catch (
const uno::Exception&)
682 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(
ERRCODE_BASIC_METHOD_FAILED), OUString() );
691 uno::Reference< lang::XMultiServiceFactory > xMSF(
mxChartDocument, uno::UNO_QUERY_THROW );
692 uno::Reference< chart::XDiagram > xDiagram( xMSF->createInstance( _sDiagramType ), uno::UNO_QUERY_THROW );
696 catch (
const uno::Exception& )
698 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(
ERRCODE_BASIC_METHOD_FAILED), OUString() );
807 bool bHasTitle =
false;
812 catch (
const uno::Exception&)
814 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(
ERRCODE_BASIC_METHOD_FAILED), OUString() );
826 catch (
const uno::Exception&)
828 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(
ERRCODE_BASIC_METHOD_FAILED), OUString() );
836 bool bHasLegend =
false;
841 catch (
const uno::Exception&)
843 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(
ERRCODE_BASIC_METHOD_FAILED), OUString() );
855 catch (
const uno::Exception&)
857 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(
ERRCODE_BASIC_METHOD_FAILED), OUString() );
861uno::Reference< excel::XChartTitle > SAL_CALL
864 uno::Reference< drawing::XShape > xTitleShape =
mxChartDocument->getTitle();
874 if ( !
Type.hasValue() )
876 return xAxes->Item(
Type, AxisGroup );
894 return _n100PercentStacked;
906 bool bStacked =
false;
915 bool b100Percent =
false;
921ScVbaChart::getSolidType(sal_Int32 _nDeep, sal_Int32 _nVertiStacked, sal_Int32 _nVerti100PercentStacked, sal_Int32 _nVertiUnStacked, sal_Int32 _nHoriStacked, sal_Int32 _nHori100PercentStacked, sal_Int32 _nHoriUnStacked)
925 bool bIsVertical =
true;
927 bool bIsDeep =
false;
938 return getStackedType(_nVertiStacked, _nVerti100PercentStacked, _nVertiUnStacked);
942 return getStackedType(_nHoriStacked, _nHori100PercentStacked, _nHoriUnStacked);
946 catch (
const uno::Exception&)
948 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(
ERRCODE_BASIC_METHOD_FAILED), OUString() );
957 bool bUpDown =
false;
968 catch (
const uno::Exception&)
970 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(
ERRCODE_BASIC_METHOD_FAILED), OUString() );
977 bool bHasMarkers =
false;
984 catch (
const uno::Exception&)
986 throw script::BasicErrorException( OUString(), uno::Reference< uno::XInterface >(), sal_uInt32(
ERRCODE_BASIC_METHOD_FAILED), OUString() );
995 return _nWithMarkers;
996 return _nWithoutMarkers;
1009uno::Reference< beans::XPropertySet >
1013 uno::Reference< beans::XPropertySet > xAxisProps;
1017 if (_nAxisGroup == xlPrimary)
1021 else if (_nAxisGroup == xlSecondary)
1030 if (_nAxisGroup == xlPrimary)
1032 else if (_nAxisGroup == xlSecondary)
1044 return "ScVbaChart";
1047uno::Sequence< OUString >
1052 "ooo.vba.excel.Chart"
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent() override
SC_DLLPUBLIC bool HasColHeader(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab)
SC_DLLPUBLIC bool HasRowHeader(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab)
virtual void SAL_CALL Activate() override
virtual void SAL_CALL setSourceData(const css::uno::Reference< ::ooo::vba::excel::XRange > &range, const css::uno::Any &PlotBy) override
virtual ::sal_Int32 SAL_CALL getChartType() override
sal_Int32 getStockUpDownValue(sal_Int32 _nUpDown, sal_Int32 _nNotUpDown)
virtual void SAL_CALL setPlotBy(::sal_Int32 xlRowCol) override
virtual void SAL_CALL setChartType(::sal_Int32 _charttype) override
virtual css::uno::Sequence< OUString > getServiceNames() override
css::uno::Reference< css::beans::XPropertySet > mxDiagramPropertySet
bool is100PercentStacked()
virtual sal_Bool SAL_CALL getHasTitle() override
virtual sal_Bool SAL_CALL getHasLegend() override
css::uno::Reference< css::chart::XChartDocument > mxChartDocument
virtual css::uno::Any SAL_CALL SeriesCollection(const css::uno::Any &) override
css::uno::Reference< css::chart::XTwoAxisXSupplier > xTwoAxisXSupplier
virtual void SAL_CALL setHasTitle(sal_Bool bTitle) override
sal_Int32 getMarkerType(sal_Int32 _nWithMarkers, sal_Int32 _nWithoutMarkers)
virtual ::sal_Int32 SAL_CALL Location() override
css::uno::Reference< css::chart::XTwoAxisYSupplier > xTwoAxisYSupplier
virtual ::sal_Int32 SAL_CALL getLocation() override
css::uno::Reference< css::beans::XPropertySet > getAxisPropertySet(sal_Int32 _nAxisType, sal_Int32 _nAxisGroup)
css::uno::Reference< css::beans::XPropertySet > mxChartPropertySet
css::uno::Reference< css::chart::XAxisXSupplier > xAxisXSupplier
static css::uno::Sequence< OUString > getDefaultSeriesDescriptions(sal_Int32 nCount)
void setDefaultChartType()
css::uno::Reference< css::table::XTableChart > mxTableChart
virtual css::uno::Any SAL_CALL Axes(const css::uno::Any &Type, const css::uno::Any &AxisGroup) override
css::uno::Reference< css::chart::XAxisZSupplier > xAxisZSupplier
virtual void SAL_CALL setHasLegend(sal_Bool bLegend) override
css::uno::Reference< css::chart::XAxisYSupplier > xAxisYSupplier
virtual OUString SAL_CALL getName() override
void setDiagram(const OUString &_sDiagramType)
sal_Int32 getStackedType(sal_Int32 _nStacked, sal_Int32 _n100PercentStacked, sal_Int32 _nUnStacked)
virtual void SAL_CALL setLocation(::sal_Int32 where, const css::uno::Any &Name) override
virtual css::uno::Reference< ov::excel::XChartTitle > SAL_CALL getChartTitle() override
virtual ::sal_Int32 SAL_CALL getPlotBy() override
sal_Int32 getSolidType(sal_Int32 _nDeep, sal_Int32 _nVertiStacked, sal_Int32 _nVerti100PercentStacked, sal_Int32 _nVertiUnStacked, sal_Int32 _nHoriStacked, sal_Int32 _nHori100PercentStacked, sal_Int32 _nHoriUnStacked)
void assignDiagramAttributes()
virtual OUString getServiceImplName() override
ScVbaChart(const css::uno::Reference< ov::XHelperInterface > &_xParent, const css::uno::Reference< css::uno::XComponentContext > &_xContext, const css::uno::Reference< css::lang::XComponent > &_xChartComponent, css::uno::Reference< css::table::XTableChart > _xTableChart)
ScDocument & getScDocument()
Sequence< OUString > aServiceNames
#define ERRCODE_BASIC_METHOD_FAILED
#define ERRCODE_BASIC_CONVERSION
Reference< XComponentContext > _xContext
constexpr OUStringLiteral CHART_NAME(u"Name")
constexpr OUStringLiteral UPDOWN(u"UpDown")
constexpr OUStringLiteral DIM3D(u"Dim3D")
constexpr OUStringLiteral HASMAINTITLE(u"HasMainTitle")
constexpr OUStringLiteral HASLEGEND(u"HasLegend")
constexpr OUStringLiteral DEEP(u"Deep")
constexpr OUStringLiteral SYMBOLTYPE(u"SymbolType")
constexpr OUStringLiteral SPLINETYPE(u"SplineType")
constexpr OUStringLiteral VERTICAL(u"Vertical")
constexpr OUStringLiteral SOLIDTYPE(u"SolidType")
constexpr OUStringLiteral STACKED(u"Stacked")
constexpr OUStringLiteral LINES(u"Lines")
constexpr OUStringLiteral PERCENT(u"Percent")
constexpr OUStringLiteral DATAROWSOURCE(u"DataRowSource")
constexpr OUStringLiteral DEFAULTSERIESPREFIX(u"Series")
constexpr OUStringLiteral VOLUME(u"Volume")