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>
59 #define MAP_(name,prefix,token,type,context) { name, sizeof(name)-1, prefix, token, type, context, SvtSaveOptions::ODFSVER_010, false }
60 #define CMAP(name,prefix,token,type,context) MAP_(name,prefix,token,type|XML_TYPE_PROP_TABLE_COLUMN,context)
61 #define RMAP(name,prefix,token,type,context) MAP_(name,prefix,token,type|XML_TYPE_PROP_TABLE_ROW,context)
62 #define CELLMAP(name,prefix,token,type,context) MAP_(name,prefix,token,type|XML_TYPE_PROP_TABLE_CELL,context)
63 #define MAP_END { nullptr, 0, 0, XML_EMPTY, 0, 0, SvtSaveOptions::ODFSVER_010, false }
74 return &aXMLColumnProperties[0];
87 return &aXMLRowProperties[0];
98 return &aXMLCellProperties[0];
103 class StringStatisticHelper
106 std::map< OUString, sal_Int32 > mStats;
109 void add(
const OUString& rStyleName );
110 void clear() { mStats.clear(); }
112 sal_Int32 getModeString( OUString& rModeString );
117 void StringStatisticHelper::add(
const OUString& rStyleName )
119 std::map< OUString, sal_Int32 >::iterator iter( mStats.find( rStyleName ) );
120 if( iter == mStats.end() )
122 mStats[rStyleName] = 1;
130 sal_Int32 StringStatisticHelper::getModeString( OUString& rStyleName )
133 for(
const auto& rStatsEntry : mStats )
135 if( rStatsEntry.second > nMax )
137 rStyleName = rStatsEntry.first;
138 nMax = rStatsEntry.second;
154 const SvXMLNamespaceMap&,
const std::vector<XMLPropertyState>*, sal_uInt32)
const override
164 , mbExportTables( false )
167 Reference< XMultiServiceFactory > xFac( rExp.
GetModel(), UNO_QUERY );
171 const OUString* pSNS = std::find_if(sSNS.begin(), sSNS.end(),
172 [](
const OUString& rSNS) {
173 return rSNS ==
"com.sun.star.drawing.TableShape"
174 || rSNS ==
"com.sun.star.style.TableStyle"; });
175 if (pSNS != sSNS.end())
178 mbWriter = (*pSNS ==
"com.sun.star.style.TableStyle");
217 static bool has_states(
const std::vector< XMLPropertyState >& xPropStates )
219 return std::any_of(xPropStates.cbegin(), xPropStates.cend(),
220 [](
const XMLPropertyState& rPropertyState) {
return rPropertyState.mnIndex != -1; });
228 auto xTableInfo = std::make_shared<XMLTableInfo>();
233 Reference< XIndexAccess > xIndexAccessCols( xColumnRowRange->getColumns(), UNO_QUERY_THROW );
234 const sal_Int32 nColumnCount = xIndexAccessCols->getCount();
235 for( sal_Int32 nColumn = 0; nColumn < nColumnCount; ++nColumn )
try
243 Reference< XInterface > xKey( xPropSet, UNO_QUERY );
244 xTableInfo->maColumnStyleMap[xKey] = sStyleName;
252 Reference< XIndexAccess > xIndexAccessRows( xColumnRowRange->getRows(), UNO_QUERY_THROW );
253 const sal_Int32 nRowCount = xIndexAccessRows->getCount();
254 xTableInfo->maDefaultRowCellStyles.resize(nRowCount);
256 StringStatisticHelper aStringStatistic;
258 for( sal_Int32 nRow = 0; nRow < nRowCount; ++nRow )
267 Reference< XInterface > xKey( xPropSet, UNO_QUERY );
268 xTableInfo->maRowStyleMap[xKey] = sStyleName;
272 Reference< XCellRange > xCellRange( xPropSet, UNO_QUERY_THROW );
273 for ( sal_Int32 nColumn = 0; nColumn < nColumnCount; ++nColumn )
279 OUString sParentStyleName;
280 Reference< XPropertySetInfo > xPropertySetInfo( xCellSet->getPropertySetInfo() );
281 if( xPropertySetInfo.is() && xPropertySetInfo->hasPropertyByName(
"Style") )
283 Reference< XStyle > xStyle( xCellSet->getPropertyValue(
"Style"), UNO_QUERY );
285 sParentStyleName = xStyle->getName();
294 sStyleName = sParentStyleName;
296 if( !sStyleName.isEmpty() )
298 Reference< XInterface > xKey( xCellSet, UNO_QUERY );
299 xTableInfo->maCellStyleMap[xKey] = sStyleName;
303 Reference< XText > xText(xCellSet, UNO_QUERY);
304 if(xText.is() && !xText->getString().isEmpty())
307 aStringStatistic.add( sStyleName );
310 OUString sDefaultCellStyle;
311 if( aStringStatistic.getModeString( sDefaultCellStyle ) > 1 )
312 xTableInfo->maDefaultRowCellStyles[nRow] = sDefaultCellStyle;
314 aStringStatistic.clear();
334 std::shared_ptr< XMLTableInfo > xTableInfo(
maTableInfoMap[xColumnRowRange] );
337 Reference< XIndexAccess > xIndexAccess( xColumnRowRange->getRows(), UNO_QUERY_THROW );
338 Reference< XIndexAccess > xIndexAccessCols( xColumnRowRange->getColumns(), UNO_QUERY_THROW );
340 const sal_Int32 rowCount = xIndexAccess->getCount();
341 const sal_Int32 columnCount = xIndexAccessCols->getCount();
349 for ( sal_Int32 rowIndex = 0; rowIndex < rowCount; rowIndex++ )
352 Reference< XCellRange > xCellRange( xIndexAccess->getByIndex(rowIndex), UNO_QUERY_THROW );
354 OUString sDefaultCellStyle;
359 Reference< XInterface > xKey( xCellRange, UNO_QUERY );
360 const OUString sStyleName( xTableInfo->maRowStyleMap[xKey] );
361 if( !sStyleName.isEmpty() )
364 sDefaultCellStyle = xTableInfo->maDefaultRowCellStyles[rowIndex];
365 if( !sDefaultCellStyle.isEmpty() )
372 for ( sal_Int32 columnIndex = 0; columnIndex < columnCount; columnIndex++ )
375 Reference< XCell > xCell( xCellRange->getCellByPosition(columnIndex, 0), UNO_SET_THROW );
378 Reference< XMergeableCell > xMergeableCell( xCell, UNO_QUERY_THROW );
381 ExportCell( xCell, xTableInfo, sDefaultCellStyle );
395 const sal_Int32 nColumnCount = xtableColumnsIndexAccess->getCount();
396 for( sal_Int32 nColumn = 0; nColumn < nColumnCount; ++nColumn )
399 if ( xColumnProperties.is() )
404 Reference< XInterface > xKey( xColumnProperties, UNO_QUERY );
405 const OUString sStyleName( rTableInfo->maColumnStyleMap[xKey] );
406 if( !sStyleName.isEmpty() )
420 void XMLTableExport::ExportCell(
const Reference < XCell >& xCell,
const std::shared_ptr< XMLTableInfo >& rTableInfo, std::u16string_view rDefaultCellStyle )
422 bool bIsMerged =
false;
423 sal_Int32 nRowSpan = 0;
424 sal_Int32 nColSpan = 0;
431 Reference< XInterface > xKey( xCell, UNO_QUERY );
432 const OUString sStyleName( rTableInfo->maCellStyleMap[xKey] );
433 if( !sStyleName.isEmpty() && (sStyleName != rDefaultCellStyle) )
437 Reference< XMergeableCell > xMerge( xCell, UNO_QUERY );
440 bIsMerged = xMerge->isMerged();
441 nRowSpan = xMerge->getRowSpan();
442 nColSpan = xMerge->getColumnSpan();
444 SAL_WARN_IF( (nRowSpan < 1) || (nColSpan < 1),
"xmloff",
"xmloff::XMLTableExport::ExportCell(), illegal row or col span < 1?" );
475 Reference< XText > xText( xCell, UNO_QUERY );
476 if( xText.is() && !xText->getString().isEmpty())
486 OUString sCellStyleName;
489 sCellStyleName =
"CellStyles";
495 sCellStyleName =
"cell";
533 return &gTableStyleElements[0];
549 return &gWriterSpecificTableStyleElements[0];
563 return &gWriterSpecifitTableStyleAttributes[0];
573 Reference< XStyleFamiliesSupplier > xFamiliesSupp(
mrExport.
GetModel(), UNO_QUERY_THROW );
575 OUString sFamilyName;
577 sFamilyName =
"TableStyles";
579 sFamilyName =
"table";
581 Reference< XIndexAccess > xTableFamily( xFamilies->getByName( sFamilyName ), UNO_QUERY_THROW );
587 Reference< XStyle > xTableStyle( xTableFamily->getByIndex(
nIndex ), UNO_QUERY_THROW );
588 if( !xTableStyle->isInUse() )
602 xTableStylePropSet->getPropertyValue(pElements->
msStyleName) >>= sVal;
607 TOOLS_WARN_EXCEPTION(
"xmloff",
"XMLTableExport::exportTableTemplates(), export Writer specific attributes, exception caught!");
633 Reference< XStyle > xStyle( xStyleNames->getByName( pElements->
msStyleName ), UNO_QUERY );
655 Reference<XStyle> xStyle(xStyleNames->getByName(pElements->
msStyleName), UNO_QUERY);
664 TOOLS_WARN_EXCEPTION(
"xmloff",
"XMLTableExport::exportTableTemplates(), export Writer specific styles, exception caught!");
672 TOOLS_WARN_EXCEPTION(
"xmloff",
"XMLTableExport::exportTableDesigns(), exception caught while exporting a table design!");
691 Reference<XPropertySetInfo> xPropSetInfo(xPropSet->getPropertySetInfo());
692 const OUString sNumberFormat(
"NumberFormat");
693 if (xPropSetInfo->hasPropertyByName(sNumberFormat))
695 Reference<XPropertyState> xPropState(xPropSet, UNO_QUERY);
696 if (xPropState.is() && (PropertyState_DIRECT_VALUE ==
697 xPropState->getPropertyState(sNumberFormat)))
699 sal_Int32 nNumberFormat = 0;
700 if (xPropSet->getPropertyValue(sNumberFormat) >>= nNumberFormat)
702 GetExport().getDataStyleName(nNumberFormat));
const XMLPropertyMapEntry * getRowPropertiesMap()
#define XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME
static bool has_states(const std::vector< XMLPropertyState > &xPropStates)
#define XML_SD_TYPE_CELL_ROTATION_ANGLE
void exportTableTemplates()
void exportTable(const css::uno::Reference< css::table::XColumnRowRange > &xColumnRowRange)
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
rtl::Reference< XMLTextParagraphExport > const & GetTextParagraphExport()
::xmloff::token::XMLTokenEnum meElement
rtl::Reference< SvXMLExportPropertyMapper > mxColumnExportPropertySetMapper
#define XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
virtual void handleSpecialItem(SvXMLAttributeList &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 ...
XMLTableExport(SvXMLExport &rExp, const rtl::Reference< SvXMLExportPropertyMapper > &xCellExportPropertySetMapper, const rtl::Reference< XMLPropertyHandlerFactory > &xFactoryRef)
SvXMLExport & GetExport()
SvXMLExport & GetExport()
#define RMAP(name, prefix, token, type, context)
#define XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX
virtual void exportStyleAttributes(const css::uno::Reference< css::style::XStyle > &rStyle) override
const css::uno::Reference< css::frame::XModel > & GetModel() const
SvXMLExportPropertyMapper(const rtl::Reference< XMLPropertySetMapper > &rMapper)
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
#define CMAP(name, prefix, token, type, context)
#define XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME
SvtSaveOptions::ODFSaneDefaultVersion getSaneDefaultVersion() const
returns the deterministic version for odf export
#define CELLMAP(name, prefix, token, type, context)
void ExportCell(const css::uno::Reference< css::table::XCell > &xCell, const std::shared_ptr< XMLTableInfo > &pTableInfo, std::u16string_view sDefaultCellStyle)
#define TOOLS_WARN_EXCEPTION(area, stream)
constexpr sal_uInt16 XML_NAMESPACE_TEXT
const TableStyleElement * getTableStyleMap()
Represents a property with its API-name, its XML-name and the type of its value.
void collectTableAutoStyles(const css::uno::Reference< css::table::XColumnRowRange > &xColumnRowRange)
const TableStyleElement * getWriterSpecificTableStyleMap()
SAL_DLLPRIVATE void ImpExportText(const css::uno::Reference< css::table::XCell > &xCell)
constexpr sal_uInt16 XML_NAMESPACE_TABLE
std::map< const css::uno::Reference< css::table::XColumnRowRange >, std::shared_ptr< XMLTableInfo > > maTableInfoMap
#define SAL_WARN_IF(condition, area, stream)
static const TableStyleElement * getWriterSpecificTableStyleAttributes()
rtl::Reference< SvXMLExportPropertyMapper > mxRowExportPropertySetMapper
rtl::Reference< SvXMLAutoStylePoolP > const & GetAutoStylePool()
Handling of tokens in XML:
#define XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX
const XMLPropertyMapEntry * getCellPropertiesMap()
Smart struct to transport an Any with an index to the appropriate property-name.
const XMLPropertyMapEntry * getColumnPropertiesMap()
#define XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME
virtual ~XMLTableExport() override
static SvXMLExportPropertyMapper * CreateParaExtPropMapper(SvXMLExport &rExport)
rtl::Reference< SvXMLExportPropertyMapper > mxCellExportPropertySetMapper
constexpr sal_uInt16 XML_NAMESPACE_STYLE
virtual void exportStyleContent(const css::uno::Reference< css::style::XStyle > &rStyle) override
void ExportTableColumns(const css::uno::Reference< css::container::XIndexAccess > &xtableColumns, const std::shared_ptr< XMLTableInfo > &pTableInfo)