25#include <rtl/ustring.hxx>
26#include <com/sun/star/frame/XModel.hpp>
27#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
28#include <com/sun/star/text/XText.hpp>
29#include <com/sun/star/table/XCellRange.hpp>
30#include <com/sun/star/table/XColumnRowRange.hpp>
31#include <com/sun/star/table/XMergeableCell.hpp>
32#include <com/sun/star/style/XStyle.hpp>
33#include <com/sun/star/beans/XPropertyState.hpp>
34#include <com/sun/star/beans/XPropertySet.hpp>
35#include <com/sun/star/beans/XPropertySetInfo.hpp>
36#include <com/sun/star/lang/XMultiServiceFactory.hpp>
60#define MAP_(name,prefix,token,type,context) { name, prefix, token, type, context, SvtSaveOptions::ODFSVER_010, false }
61#define CMAP(name,prefix,token,type,context) MAP_(name,prefix,token,type|XML_TYPE_PROP_TABLE_COLUMN,context)
62#define RMAP(name,prefix,token,type,context) MAP_(name,prefix,token,type|XML_TYPE_PROP_TABLE_ROW,context)
63#define CELLMAP(name,prefix,token,type,context) MAP_(name,prefix,token,type|XML_TYPE_PROP_TABLE_CELL,context)
64#define MAP_END { nullptr }
75 return &aXMLColumnProperties[0];
88 return &aXMLRowProperties[0];
111 return &aXMLCellProperties[0];
116class StringStatisticHelper
119 std::map< OUString, sal_Int32 > mStats;
122 void add(
const OUString& rStyleName );
123 void clear() { mStats.clear(); }
125 sal_Int32 getModeString( OUString& rModeString );
130void StringStatisticHelper::add(
const OUString& rStyleName )
132 std::map< OUString, sal_Int32 >::iterator iter( mStats.find( rStyleName ) );
133 if( iter == mStats.end() )
135 mStats[rStyleName] = 1;
143sal_Int32 StringStatisticHelper::getModeString( OUString& rStyleName )
146 for(
const auto& rStatsEntry : mStats )
148 if( rStatsEntry.second > nMax )
150 rStyleName = rStatsEntry.first;
151 nMax = rStatsEntry.second;
167 const SvXMLNamespaceMap&,
const std::vector<XMLPropertyState>*, sal_uInt32)
const override
177, mbExportTables( false )
180 Reference< XMultiServiceFactory > xFac( rExp.
GetModel(), UNO_QUERY );
183 const Sequence< OUString > sSNS( xFac->getAvailableServiceNames() );
184 const OUString* pSNS = std::find_if(sSNS.begin(), sSNS.end(),
185 [](
const OUString& rSNS) {
186 return rSNS ==
"com.sun.star.drawing.TableShape"
187 || rSNS ==
"com.sun.star.style.TableStyle"; });
188 if (pSNS != sSNS.end())
191 mbWriter = (*pSNS ==
"com.sun.star.style.TableStyle");
230static bool has_states(
const std::vector< XMLPropertyState >& xPropStates )
232 return std::any_of(xPropStates.cbegin(), xPropStates.cend(),
233 [](
const XMLPropertyState& rPropertyState) { return rPropertyState.mnIndex != -1; });
241 auto xTableInfo = std::make_shared<XMLTableInfo>();
246 Reference< XIndexAccess > xIndexAccessCols( xColumnRowRange->getColumns(), UNO_QUERY_THROW );
247 const sal_Int32 nColumnCount = xIndexAccessCols->getCount();
248 for( sal_Int32 nColumn = 0; nColumn < nColumnCount; ++nColumn )
try
250 Reference< XPropertySet > xPropSet( xIndexAccessCols->getByIndex(nColumn) , UNO_QUERY_THROW );
256 Reference< XInterface > xKey( xPropSet, UNO_QUERY );
257 xTableInfo->maColumnStyleMap[xKey] = sStyleName;
265 Reference< XIndexAccess > xIndexAccessRows( xColumnRowRange->getRows(), UNO_QUERY_THROW );
266 const sal_Int32 nRowCount = xIndexAccessRows->getCount();
267 xTableInfo->maDefaultRowCellStyles.resize(nRowCount);
269 StringStatisticHelper aStringStatistic;
271 for( sal_Int32 nRow = 0; nRow < nRowCount; ++nRow )
274 Reference< XPropertySet > xPropSet( xIndexAccessRows->getByIndex(nRow) , UNO_QUERY_THROW );
280 Reference< XInterface > xKey( xPropSet, UNO_QUERY );
281 xTableInfo->maRowStyleMap[xKey] = sStyleName;
285 Reference< XCellRange > xCellRange( xPropSet, UNO_QUERY_THROW );
286 for ( sal_Int32 nColumn = 0; nColumn < nColumnCount; ++nColumn )
289 Reference< XPropertySet > xCellSet( xCellRange->getCellByPosition(nColumn, 0), UNO_QUERY_THROW );
292 OUString sParentStyleName;
293 Reference< XPropertySetInfo > xPropertySetInfo( xCellSet->getPropertySetInfo() );
294 if( xPropertySetInfo.is() && xPropertySetInfo->hasPropertyByName(
"Style") )
296 Reference< XStyle > xStyle( xCellSet->getPropertyValue(
"Style"), UNO_QUERY );
298 sParentStyleName = xStyle->getName();
307 sStyleName = sParentStyleName;
309 if( !sStyleName.isEmpty() )
311 Reference< XInterface > xKey( xCellSet, UNO_QUERY );
312 xTableInfo->maCellStyleMap[xKey] = sStyleName;
316 Reference< XText > xText(xCellSet, UNO_QUERY);
317 if(xText.is() && !xText->getString().isEmpty())
320 aStringStatistic.add( sStyleName );
323 OUString sDefaultCellStyle;
324 if( aStringStatistic.getModeString( sDefaultCellStyle ) > 1 )
325 xTableInfo->maDefaultRowCellStyles[nRow] = sDefaultCellStyle;
327 aStringStatistic.clear();
347 std::shared_ptr< XMLTableInfo > xTableInfo(
maTableInfoMap[xColumnRowRange] );
350 Reference< XIndexAccess > xIndexAccess( xColumnRowRange->getRows(), UNO_QUERY_THROW );
351 Reference< XIndexAccess > xIndexAccessCols( xColumnRowRange->getColumns(), UNO_QUERY_THROW );
353 const sal_Int32 rowCount = xIndexAccess->getCount();
354 const sal_Int32 columnCount = xIndexAccessCols->getCount();
362 for ( sal_Int32 rowIndex = 0; rowIndex < rowCount; rowIndex++ )
365 Reference< XCellRange > xCellRange( xIndexAccess->getByIndex(rowIndex), UNO_QUERY_THROW );
367 OUString sDefaultCellStyle;
372 Reference< XInterface > xKey( xCellRange, UNO_QUERY );
373 const OUString sStyleName( xTableInfo->maRowStyleMap[xKey] );
374 if( !sStyleName.isEmpty() )
377 sDefaultCellStyle = xTableInfo->maDefaultRowCellStyles[rowIndex];
378 if( !sDefaultCellStyle.isEmpty() )
385 for ( sal_Int32 columnIndex = 0; columnIndex < columnCount; columnIndex++ )
388 Reference< XCell > xCell( xCellRange->getCellByPosition(columnIndex, 0), UNO_SET_THROW );
391 Reference< XMergeableCell > xMergeableCell( xCell, UNO_QUERY_THROW );
394 ExportCell( xCell, xTableInfo, sDefaultCellStyle );
408 const sal_Int32 nColumnCount = xtableColumnsIndexAccess->getCount();
409 for( sal_Int32 nColumn = 0; nColumn < nColumnCount; ++nColumn )
411 Reference< XPropertySet > xColumnProperties( xtableColumnsIndexAccess->getByIndex(nColumn) , UNO_QUERY );
412 if ( xColumnProperties.is() )
417 Reference< XInterface > xKey( xColumnProperties, UNO_QUERY );
418 const OUString sStyleName( rTableInfo->maColumnStyleMap[xKey] );
419 if( !sStyleName.isEmpty() )
433 void XMLTableExport::ExportCell(
const Reference < XCell >& xCell,
const std::shared_ptr< XMLTableInfo >& rTableInfo, std::u16string_view rDefaultCellStyle )
435 bool bIsMerged =
false;
436 sal_Int32 nRowSpan = 0;
437 sal_Int32 nColSpan = 0;
444 Reference< XInterface > xKey( xCell, UNO_QUERY );
445 const OUString sStyleName( rTableInfo->maCellStyleMap[xKey] );
446 if( !sStyleName.isEmpty() && (sStyleName != rDefaultCellStyle) )
450 Reference< XMergeableCell > xMerge( xCell, UNO_QUERY );
453 bIsMerged = xMerge->isMerged();
454 nRowSpan = xMerge->getRowSpan();
455 nColSpan = xMerge->getColumnSpan();
457 SAL_WARN_IF( (nRowSpan < 1) || (nColSpan < 1),
"xmloff",
"xmloff::XMLTableExport::ExportCell(), illegal row or col span < 1?" );
488 Reference< XText > xText( xCell, UNO_QUERY );
489 if( xText.is() && !xText->getString().isEmpty())
499 OUString sCellStyleName;
502 sCellStyleName =
"CellStyles";
508 sCellStyleName =
"cell";
546 return &gTableStyleElements[0];
562 return &gWriterSpecificTableStyleElements[0];
576 return &gWriterSpecifitTableStyleAttributes[0];
586 Reference< XStyleFamiliesSupplier > xFamiliesSupp(
mrExport.
GetModel(), UNO_QUERY_THROW );
587 Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
588 OUString sFamilyName;
590 sFamilyName =
"TableStyles";
592 sFamilyName =
"table";
594 Reference< XIndexAccess > xTableFamily( xFamilies->getByName( sFamilyName ), UNO_QUERY_THROW );
600 Reference< XStyle > xTableStyle( xTableFamily->getByIndex(
nIndex ), UNO_QUERY_THROW );
601 Reference<XPropertySet> xTableStylePropSet( xTableStyle, UNO_QUERY_THROW );
602 bool bPhysical =
false;
606 xTableStylePropSet->getPropertyValue(
"IsPhysical") >>= bPhysical;
612 if (!xTableStyle->isInUse() && !bPhysical)
625 xTableStylePropSet->getPropertyValue(pElements->
msStyleName) >>= sVal;
630 TOOLS_WARN_EXCEPTION(
"xmloff",
"XMLTableExport::exportTableTemplates(), export Writer specific attributes, exception caught!");
650 Reference< XNameAccess > xStyleNames( xTableStyle, UNO_QUERY_THROW );
656 Reference< XStyle > xStyle( xStyleNames->getByName( pElements->
msStyleName ), UNO_QUERY );
678 Reference<XStyle> xStyle(xStyleNames->getByName(pElements->
msStyleName), UNO_QUERY);
687 TOOLS_WARN_EXCEPTION(
"xmloff",
"XMLTableExport::exportTableTemplates(), export Writer specific styles, exception caught!");
695 TOOLS_WARN_EXCEPTION(
"xmloff",
"XMLTableExport::exportTableDesigns(), exception caught while exporting a table design!");
710 Reference<XPropertySet> xPropSet(rStyle, UNO_QUERY);
714 Reference<XPropertySetInfo> xPropSetInfo(xPropSet->getPropertySetInfo());
715 static constexpr OUStringLiteral sNumberFormat(
u"NumberFormat");
716 if (xPropSetInfo->hasPropertyByName(sNumberFormat))
718 Reference<XPropertyState> xPropState(xPropSet, UNO_QUERY);
719 if (xPropState.is() && (PropertyState_DIRECT_VALUE ==
720 xPropState->getPropertyState(sNumberFormat)))
722 sal_Int32 nNumberFormat = 0;
723 if (xPropSet->getPropertyValue(sNumberFormat) >>= nNumberFormat)
725 GetExport().getDataStyleName(nNumberFormat));
const XMLPropertyMapEntry * getColumnPropertiesMap()
static const TableStyleElement * getWriterSpecificTableStyleAttributes()
static bool has_states(const std::vector< XMLPropertyState > &xPropStates)
#define CELLMAP(name, prefix, token, type, context)
const TableStyleElement * getTableStyleMap()
const TableStyleElement * getWriterSpecificTableStyleMap()
#define RMAP(name, prefix, token, type, context)
const XMLPropertyMapEntry * getRowPropertiesMap()
const XMLPropertyMapEntry * getCellPropertiesMap()
#define CMAP(name, prefix, token, type, context)
virtual void handleSpecialItem(comphelper::AttributeList &rAttrList, const XMLPropertyState &rProperty, const SvXMLUnitConverter &rUnitConverter, const SvXMLNamespaceMap &rNamespaceMap, const ::std::vector< XMLPropertyState > *pProperties, sal_uInt32 nIdx) const
this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_EXPORT flag set
SvXMLExportPropertyMapper(const rtl::Reference< XMLPropertySetMapper > &rMapper)
rtl::Reference< XMLTextParagraphExport > const & GetTextParagraphExport()
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
const css::uno::Reference< css::frame::XModel > & GetModel() const
SvtSaveOptions::ODFSaneDefaultVersion getSaneDefaultVersion() const
returns the deterministic version for odf export
rtl::Reference< SvXMLAutoStylePoolP > const & GetAutoStylePool()
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
virtual void exportStyleAttributes(const css::uno::Reference< css::style::XStyle > &rStyle) override
virtual void exportStyleContent(const css::uno::Reference< css::style::XStyle > &rStyle) override
SvXMLExport & GetExport()
virtual ~XMLTableExport() override
void collectTableAutoStyles(const css::uno::Reference< css::table::XColumnRowRange > &xColumnRowRange)
void exportTable(const css::uno::Reference< css::table::XColumnRowRange > &xColumnRowRange)
void ExportCell(const css::uno::Reference< css::table::XCell > &xCell, const std::shared_ptr< XMLTableInfo > &pTableInfo, std::u16string_view sDefaultCellStyle)
rtl::Reference< SvXMLExportPropertyMapper > mxColumnExportPropertySetMapper
void ExportTableColumns(const css::uno::Reference< css::container::XIndexAccess > &xtableColumns, const std::shared_ptr< XMLTableInfo > &pTableInfo)
SAL_DLLPRIVATE void ImpExportText(const css::uno::Reference< css::table::XCell > &xCell)
XMLTableExport(SvXMLExport &rExp, const rtl::Reference< SvXMLExportPropertyMapper > &xCellExportPropertySetMapper, const rtl::Reference< XMLPropertyHandlerFactory > &xFactoryRef)
void exportTableTemplates()
rtl::Reference< SvXMLExportPropertyMapper > mxRowExportPropertySetMapper
SvXMLExport & GetExport()
rtl::Reference< SvXMLExportPropertyMapper > mxCellExportPropertySetMapper
std::map< const css::uno::Reference< css::table::XColumnRowRange >, std::shared_ptr< XMLTableInfo > > maTableInfoMap
static SvXMLExportPropertyMapper * CreateParaExtPropMapper(SvXMLExport &rExport)
#define TOOLS_WARN_EXCEPTION(area, stream)
constexpr OUStringLiteral XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX
constexpr OUStringLiteral XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX
constexpr OUStringLiteral XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME
constexpr OUStringLiteral XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX
constexpr OUStringLiteral XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME
constexpr OUStringLiteral XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME
#define SAL_WARN_IF(condition, area, stream)
Handling of tokens in XML:
@ XML_LAST_ROW_EVEN_COLUMN
@ XML_FIRST_ROW_EVEN_COLUMN
@ XML_LAST_ROW_END_COLUMN
@ XML_DEFAULT_CELL_STYLE_NAME
@ XML_FIRST_ROW_START_COLUMN
@ XML_USE_OPTIMAL_ROW_HEIGHT
@ XML_USE_OPTIMAL_COLUMN_WIDTH
@ XML_NUMBER_COLUMNS_SPANNED
@ XML_NUMBER_ROWS_SPANNED
@ XML_FIRST_ROW_END_COLUMN
@ XML_LAST_ROW_START_COLUMN
::xmloff::token::XMLTokenEnum meElement
Represents a property with its API-name, its XML-name and the type of its value.
Smart struct to transport an Any with an index to the appropriate property-name.
#define CTF_CHARBOTTOMBORDER
#define CTF_CHARALLBORDERDISTANCE
#define CTF_CHARTOPBORDER
#define CTF_CHARBOTTOMBORDERDISTANCE
#define CTF_CHARALLBORDER
#define CTF_CHARTOPBORDERDISTANCE
#define CTF_CHARRIGHTBORDER
#define CTF_CHARLEFTBORDER
#define CTF_CHARRIGHTBORDERDISTANCE
#define CTF_CHARLEFTBORDERDISTANCE
constexpr sal_uInt16 XML_NAMESPACE_TEXT
constexpr sal_uInt16 XML_NAMESPACE_TABLE
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
constexpr sal_uInt16 XML_NAMESPACE_STYLE
constexpr sal_uInt16 XML_NAMESPACE_FO
constexpr OUStringLiteral PROP_RightBorder
constexpr OUStringLiteral PROP_RotateAngle
constexpr OUStringLiteral PROP_TextLeftDistance
constexpr OUStringLiteral PROP_TextUpperDistance
constexpr OUStringLiteral PROP_MinHeight
constexpr OUStringLiteral PROP_BackColor
constexpr OUStringLiteral PROP_Height
constexpr OUStringLiteral PROP_LeftBorder
constexpr OUStringLiteral PROP_OptimalWidth
constexpr OUStringLiteral PROP_TextLowerDistance
constexpr OUStringLiteral PROP_TextRightDistance
constexpr OUStringLiteral PROP_OptimalHeight
constexpr OUStringLiteral PROP_TopBorder
constexpr OUStringLiteral PROP_TextVerticalAdjust
constexpr OUStringLiteral PROP_BottomBorder
constexpr OUStringLiteral PROP_Width
#define XML_SD_TYPE_VERTICAL_ALIGN
#define XML_SD_TYPE_CELL_ROTATION_ANGLE
#define XML_TYPE_COLORTRANSPARENT
#define MID_FLAG_SPECIAL_ITEM
#define MID_FLAG_SPECIAL_ITEM_EXPORT