LibreOffice Module xmloff (master)  1
XMLTableExport.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
21 
22 #include <sal/config.h>
23 #include <sal/log.hxx>
24 #include <osl/diagnose.h>
25 
26 #include <rtl/ustring.hxx>
27 
28 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
29 #include <com/sun/star/text/XText.hpp>
30 #include <com/sun/star/table/XCellRange.hpp>
31 #include <com/sun/star/table/XColumnRowRange.hpp>
32 #include <com/sun/star/table/XMergeableCell.hpp>
33 #include <com/sun/star/style/XStyle.hpp>
34 #include <com/sun/star/beans/XPropertyState.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/beans/XPropertySetInfo.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <tools/diagnose_ex.h>
39 
40 #include <xmloff/xmlnmspe.hxx>
41 #include <xmloff/xmlprmap.hxx>
42 #include <xmloff/xmlexppr.hxx>
43 #include <xmloff/xmlexp.hxx>
44 #include <xmloff/xmltypes.hxx>
45 #include <xmlsdtypes.hxx>
46 #include <xmloff/maptype.hxx>
47 #include <xmloff/prhdlfac.hxx>
48 #include <xmloff/txtprmap.hxx>
49 #include "table.hxx"
50 
51 using namespace ::xmloff::token;
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::lang;
54 using namespace ::com::sun::star::table;
55 using namespace ::com::sun::star::beans;
56 using namespace ::com::sun::star::container;
57 using namespace ::com::sun::star::text;
58 using namespace ::com::sun::star::style;
59 
60 #define MAP_(name,prefix,token,type,context) { name, sizeof(name)-1, prefix, token, type, context, SvtSaveOptions::ODFVER_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, 0, 0, XML_EMPTY, 0, 0, SvtSaveOptions::ODFVER_010, false }
65 
67 {
68  static const XMLPropertyMapEntry aXMLColumnProperties[] =
69  {
72  MAP_END
73  };
74 
75  return &aXMLColumnProperties[0];
76 }
77 
79 {
80  static const XMLPropertyMapEntry aXMLRowProperties[] =
81  {
85  MAP_END
86  };
87 
88  return &aXMLRowProperties[0];
89 }
90 
92 {
93  static const XMLPropertyMapEntry aXMLCellProperties[] =
94  {
96  MAP_END
97  };
98 
99  return &aXMLCellProperties[0];
100 }
101 
102 namespace {
103 
104 class StringStatisticHelper
105 {
106 private:
107  std::map< OUString, sal_Int32 > mStats;
108 
109 public:
110  void add( const OUString& rStyleName );
111  void clear() { mStats.clear(); }
112 
113  sal_Int32 getModeString( /* out */ OUString& rModeString );
114 };
115 
116 }
117 
118 void StringStatisticHelper::add( const OUString& rStyleName )
119 {
120  std::map< OUString, sal_Int32 >::iterator iter( mStats.find( rStyleName ) );
121  if( iter == mStats.end() )
122  {
123  mStats[rStyleName] = 1;
124  }
125  else
126  {
127  (*iter).second += 1;
128  }
129 }
130 
131 sal_Int32 StringStatisticHelper::getModeString( OUString& rStyleName )
132 {
133  sal_Int32 nMax = 0;
134  for( const auto& rStatsEntry : mStats )
135  {
136  if( rStatsEntry.second > nMax )
137  {
138  rStyleName = rStatsEntry.first;
139  nMax = rStatsEntry.second;
140  }
141  }
142 
143  return nMax;
144 }
145 
146 namespace {
147 
148 class XMLCellExportPropertyMapper : public SvXMLExportPropertyMapper
149 {
150 public:
155  const SvXMLNamespaceMap&, const std::vector<XMLPropertyState>*, sal_uInt32) const override
156  {
157  // the SpecialItem NumberFormat must not be handled by this method
158  }
159 };
160 
161 }
162 
164 : mrExport( rExp )
165 , mbExportTables( false )
166 , mbWriter( false )
167 {
168  Reference< XMultiServiceFactory > xFac( rExp.GetModel(), UNO_QUERY );
169  if( xFac.is() ) try
170  {
171  Sequence< OUString > sSNS( xFac->getAvailableServiceNames() );
172  const OUString* pSNS = std::find_if(sSNS.begin(), sSNS.end(),
173  [](const OUString& rSNS) {
174  return rSNS == "com.sun.star.drawing.TableShape"
175  || rSNS == "com.sun.star.style.TableStyle"; });
176  if (pSNS != sSNS.end())
177  {
178  mbExportTables = true;
179  mbWriter = (*pSNS == "com.sun.star.style.TableStyle");
180  }
181  }
182  catch(const Exception&)
183  {
184  }
185 
186  if (mbWriter)
187  {
188  mxCellExportPropertySetMapper = new XMLCellExportPropertyMapper(new XMLTextPropertySetMapper(TextPropMap::CELL, true));
189  }
190  else
191  {
192  mxCellExportPropertySetMapper = xExportPropertyMapper;
194  mxCellExportPropertySetMapper->ChainExportMapper(new SvXMLExportPropertyMapper(new XMLPropertySetMapper(getCellPropertiesMap(), xFactoryRef.get(), true)));
195  }
196 
199 
212 }
213 
215 {
216 }
217 
218 static bool has_states( const std::vector< XMLPropertyState >& xPropStates )
219 {
220  return std::any_of(xPropStates.cbegin(), xPropStates.cend(),
221  [](const XMLPropertyState& rPropertyState) { return rPropertyState.mnIndex != -1; });
222 }
223 
224  void XMLTableExport::collectTableAutoStyles(const Reference < XColumnRowRange >& xColumnRowRange)
225  {
226  if( !mbExportTables )
227  return;
228 
229  auto xTableInfo = std::make_shared<XMLTableInfo>();
230  maTableInfoMap[xColumnRowRange] = xTableInfo;
231 
232  try
233  {
234  Reference< XIndexAccess > xIndexAccessCols( xColumnRowRange->getColumns(), UNO_QUERY_THROW );
235  const sal_Int32 nColumnCount = xIndexAccessCols->getCount();
236  for( sal_Int32 nColumn = 0; nColumn < nColumnCount; ++nColumn ) try
237  {
238  Reference< XPropertySet > xPropSet( xIndexAccessCols->getByIndex(nColumn) , UNO_QUERY_THROW );
239  std::vector< XMLPropertyState > aPropStates( mxColumnExportPropertySetMapper->Filter( xPropSet ) );
240 
241  if( has_states( aPropStates ) )
242  {
243  const OUString sStyleName( mrExport.GetAutoStylePool()->Add(XmlStyleFamily::TABLE_COLUMN, aPropStates) );
244  Reference< XInterface > xKey( xPropSet, UNO_QUERY );
245  xTableInfo->maColumnStyleMap[xKey] = sStyleName;
246  }
247  }
248  catch(const Exception&)
249  {
250  OSL_FAIL("xmloff::XMLTableExport::collectTableAutoStyles(), exception during column style collection!");
251  }
252 
253  Reference< XIndexAccess > xIndexAccessRows( xColumnRowRange->getRows(), UNO_QUERY_THROW );
254  const sal_Int32 nRowCount = xIndexAccessRows->getCount();
255  xTableInfo->maDefaultRowCellStyles.resize(nRowCount);
256 
257  StringStatisticHelper aStringStatistic;
258 
259  for( sal_Int32 nRow = 0; nRow < nRowCount; ++nRow )
260  try
261  {
262  Reference< XPropertySet > xPropSet( xIndexAccessRows->getByIndex(nRow) , UNO_QUERY_THROW );
263  std::vector< XMLPropertyState > aRowPropStates( mxRowExportPropertySetMapper->Filter( xPropSet ) );
264 
265  if( has_states( aRowPropStates ) )
266  {
267  const OUString sStyleName( mrExport.GetAutoStylePool()->Add(XmlStyleFamily::TABLE_ROW, aRowPropStates) );
268  Reference< XInterface > xKey( xPropSet, UNO_QUERY );
269  xTableInfo->maRowStyleMap[xKey] = sStyleName;
270  }
271 
272  // get the current row
273  Reference< XCellRange > xCellRange( xPropSet, UNO_QUERY_THROW );
274  for ( sal_Int32 nColumn = 0; nColumn < nColumnCount; ++nColumn )
275  {
276  // get current cell, remarks row index is 0, because we get the range for each row separate
277  Reference< XPropertySet > xCellSet( xCellRange->getCellByPosition(nColumn, 0), UNO_QUERY_THROW );
278 
279  // get style
280  OUString sParentStyleName;
281  Reference< XPropertySetInfo > xPropertySetInfo( xCellSet->getPropertySetInfo() );
282  if( xPropertySetInfo.is() && xPropertySetInfo->hasPropertyByName("Style") )
283  {
284  Reference< XStyle > xStyle( xCellSet->getPropertyValue("Style"), UNO_QUERY );
285  if( xStyle.is() )
286  sParentStyleName = xStyle->getName();
287  }
288 
289  // create auto style, if needed
290  OUString sStyleName;
291  std::vector< XMLPropertyState > aCellPropStates( mxCellExportPropertySetMapper->Filter( xCellSet ) );
292  if( has_states( aCellPropStates ) )
293  sStyleName = mrExport.GetAutoStylePool()->Add(XmlStyleFamily::TABLE_CELL, aCellPropStates);
294  else
295  sStyleName = sParentStyleName;
296 
297  if( !sStyleName.isEmpty() )
298  {
299  Reference< XInterface > xKey( xCellSet, UNO_QUERY );
300  xTableInfo->maCellStyleMap[xKey] = sStyleName;
301  }
302 
303  // create auto style for text
304  Reference< XText > xText(xCellSet, UNO_QUERY);
305  if(xText.is() && !xText->getString().isEmpty())
306  GetExport().GetTextParagraphExport()->collectTextAutoStyles( xText );
307 
308  aStringStatistic.add( sStyleName );
309  }
310 
311  OUString sDefaultCellStyle;
312  if( aStringStatistic.getModeString( sDefaultCellStyle ) > 1 )
313  xTableInfo->maDefaultRowCellStyles[nRow] = sDefaultCellStyle;
314 
315  aStringStatistic.clear();
316  }
317  catch(const Exception&)
318  {
319  OSL_FAIL("xmloff::XMLTableExport::collectTableAutoStyles(), exception during column style collection!");
320  }
321  }
322  catch(const Exception&)
323  {
324  OSL_FAIL("xmloff::XMLTableExport::collectTableAutoStyles(), exception caught!");
325  }
326  }
327 
328  void XMLTableExport::exportTable( const Reference < XColumnRowRange >& xColumnRowRange )
329  {
330  if( !mbExportTables )
331  return;
332 
333  try
334  {
335  std::shared_ptr< XMLTableInfo > xTableInfo( maTableInfoMap[xColumnRowRange] );
336 
337  // get row and column count
338  Reference< XIndexAccess > xIndexAccess( xColumnRowRange->getRows(), UNO_QUERY_THROW );
339  Reference< XIndexAccess > xIndexAccessCols( xColumnRowRange->getColumns(), UNO_QUERY_THROW );
340 
341  const sal_Int32 rowCount = xIndexAccess->getCount();
342  const sal_Int32 columnCount = xIndexAccessCols->getCount();
343 
344  SvXMLElementExport tableElement( mrExport, XML_NAMESPACE_TABLE, XML_TABLE, true, true );
345 
346  // export table columns
347  ExportTableColumns( xIndexAccessCols, xTableInfo );
348 
349  // start iterating rows and columns
350  for ( sal_Int32 rowIndex = 0; rowIndex < rowCount; rowIndex++ )
351  {
352  // get the current row
353  Reference< XCellRange > xCellRange( xIndexAccess->getByIndex(rowIndex), UNO_QUERY_THROW );
354 
355  OUString sDefaultCellStyle;
356 
357  // table:style-name
358  if( xTableInfo.get() )
359  {
360  Reference< XInterface > xKey( xCellRange, UNO_QUERY );
361  const OUString sStyleName( xTableInfo->maRowStyleMap[xKey] );
362  if( !sStyleName.isEmpty() )
364 
365  sDefaultCellStyle = xTableInfo->maDefaultRowCellStyles[rowIndex];
366  if( !sDefaultCellStyle.isEmpty() )
368  }
369 
370  // write row element
371  SvXMLElementExport tableRowElement( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_ROW, true, true );
372 
373  for ( sal_Int32 columnIndex = 0; columnIndex < columnCount; columnIndex++ )
374  {
375  // get current cell, remarks row index is 0, because we get the range for each row separate
376  Reference< XCell > xCell( xCellRange->getCellByPosition(columnIndex, 0), UNO_SET_THROW );
377 
378  // use XMergeableCell interface from offapi
379  Reference< XMergeableCell > xMergeableCell( xCell, UNO_QUERY_THROW );
380 
381  // export cell
382  ExportCell( xCell, xTableInfo, sDefaultCellStyle );
383  }
384  }
385  }
386  catch(const Exception&)
387  {
388  OSL_FAIL( "XMLTableExport::exportTable(), exception caught!" );
389  }
390  }
391 
392 // Export the table columns
393 
394  void XMLTableExport::ExportTableColumns( const Reference < XIndexAccess >& xtableColumnsIndexAccess, const std::shared_ptr< XMLTableInfo >& rTableInfo )
395  {
396  const sal_Int32 nColumnCount = xtableColumnsIndexAccess->getCount();
397  for( sal_Int32 nColumn = 0; nColumn < nColumnCount; ++nColumn )
398  {
399  Reference< XPropertySet > xColumnProperties( xtableColumnsIndexAccess->getByIndex(nColumn) , UNO_QUERY );
400  if ( xColumnProperties.is() )
401  {
402  // table:style-name
403  if( rTableInfo.get() )
404  {
405  Reference< XInterface > xKey( xColumnProperties, UNO_QUERY );
406  const OUString sStyleName( rTableInfo->maColumnStyleMap[xKey] );
407  if( !sStyleName.isEmpty() )
409  }
410 
411  // TODO: all columns first have to be checked if someone
412  // have identical properties. If yes, attr table:number-columns-repeated
413  // has to be written.
414  SvXMLElementExport tableColumnElement( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_COLUMN, true, true );
415  }
416  }
417  }
418 
419 // ODF export for a table cell.
420 
421  void XMLTableExport::ExportCell( const Reference < XCell >& xCell, const std::shared_ptr< XMLTableInfo >& rTableInfo, const OUString& rDefaultCellStyle )
422  {
423  bool bIsMerged = false;
424  sal_Int32 nRowSpan = 0;
425  sal_Int32 nColSpan = 0;
426 
427  try
428  {
429  if( rTableInfo.get() )
430  {
431  // table:style-name
432  Reference< XInterface > xKey( xCell, UNO_QUERY );
433  const OUString sStyleName( rTableInfo->maCellStyleMap[xKey] );
434  if( !sStyleName.isEmpty() && (sStyleName != rDefaultCellStyle) )
436  }
437 
438  Reference< XMergeableCell > xMerge( xCell, UNO_QUERY );
439  if( xMerge.is() )
440  {
441  bIsMerged = xMerge->isMerged();
442  nRowSpan = xMerge->getRowSpan();
443  nColSpan = xMerge->getColumnSpan();
444  }
445  SAL_WARN_IF( (nRowSpan < 1) || (nColSpan < 1), "xmloff", "xmloff::XMLTableExport::ExportCell(), illegal row or col span < 1?" );
446  }
447  catch (const Exception&)
448  {
449  OSL_FAIL( "exception while exporting a table cell" );
450  }
451 
452  // table:number-columns-repeated
453  // todo
454 
455  // table:number-columns-spanned
456  if( nColSpan > 1 )
457  mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_SPANNED, OUString::number( nColSpan ) );
458 
459  // table:number-rows-spanned
460  if( nRowSpan > 1 )
461  mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_ROWS_SPANNED, OUString::number( nRowSpan ) );
462 
463  // <table:table-cell> or <table:covered-table-cell>
464  SvXMLElementExport tableCellElement( mrExport, XML_NAMESPACE_TABLE, bIsMerged ? XML_COVERED_TABLE_CELL : XML_TABLE_CELL, true, true );
465 
466  // export cells text content
467  ImpExportText( xCell );
468  }
469 
470 // ODF export of the text contents of a table cell.
471 // Remarks: Up to now we only export text contents!
472 // TODO: Check against nested tables...
473 
474  void XMLTableExport::ImpExportText( const Reference< XCell >& xCell )
475  {
476  Reference< XText > xText( xCell, UNO_QUERY );
477  if( xText.is() && !xText->getString().isEmpty())
478  mrExport.GetTextParagraphExport()->exportText( xText );
479  }
480 
482 {
483  if( !mbExportTables )
484  return;
485 
487  OUString sCellStyleName;
488  if (mbWriter)
489  {
490  sCellStyleName = "CellStyles";
491  aStEx.set(new XMLCellStyleExport(mrExport));
492  }
493  else
494  {
495  // write graphic family styles
496  sCellStyleName = "cell";
497  aStEx.set(new XMLStyleExport(mrExport, mrExport.GetAutoStylePool().get()));
498  }
499 
500  aStEx->exportStyleFamily(sCellStyleName, OUString(XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME), mxCellExportPropertySetMapper.get(), true, XmlStyleFamily::TABLE_CELL);
501 
503 }
504 
505 // Export the collected automatic styles
506 
508 {
509  if( !mbExportTables )
510  return;
511 
515 }
516 
518 {
519  static const struct TableStyleElement gTableStyleElements[] =
520  {
521  { XML_FIRST_ROW, OUString("first-row") },
522  { XML_LAST_ROW, OUString("last-row") },
523  { XML_FIRST_COLUMN, OUString("first-column") },
524  { XML_LAST_COLUMN, OUString("last-column") },
525  { XML_BODY, OUString("body") },
526  { XML_EVEN_ROWS, OUString("even-rows") },
527  { XML_ODD_ROWS, OUString("odd-rows") },
528  { XML_EVEN_COLUMNS, OUString("even-columns") },
529  { XML_ODD_COLUMNS, OUString("odd-columns") },
530  { XML_BACKGROUND, OUString("background") },
531  { XML_TOKEN_END, OUString() }
532  };
533 
534  return &gTableStyleElements[0];
535 }
536 
538 {
539  static const struct TableStyleElement gWriterSpecificTableStyleElements[] =
540  {
541  { XML_FIRST_ROW_EVEN_COLUMN, OUString("first-row-even-column") },
542  { XML_LAST_ROW_EVEN_COLUMN, OUString("last-row-even-column") },
543  { XML_FIRST_ROW_END_COLUMN, OUString("first-row-end-column") },
544  { XML_FIRST_ROW_START_COLUMN, OUString("first-row-start-column") },
545  { XML_LAST_ROW_END_COLUMN, OUString("last-row-end-column") },
546  { XML_LAST_ROW_START_COLUMN, OUString("last-row-start-column") },
547  { XML_TOKEN_END, OUString() }
548  };
549 
550  return &gWriterSpecificTableStyleElements[0];
551 }
552 
554 {
555  static const struct TableStyleElement gWriterSpecifitTableStyleAttributes[] =
556  {
557  { XML_FIRST_ROW_END_COLUMN, OUString("FirstRowEndColumn") },
558  { XML_FIRST_ROW_START_COLUMN, OUString("FirstRowStartColumn") },
559  { XML_LAST_ROW_END_COLUMN, OUString("LastRowEndColumn") },
560  { XML_LAST_ROW_START_COLUMN, OUString("LastRowStartColumn") },
561  { XML_TOKEN_END, OUString() }
562  };
563 
564  return &gWriterSpecifitTableStyleAttributes[0];
565 }
566 
568 {
569  if( !mbExportTables )
570  return;
571 
572  try
573  {
574  Reference< XStyleFamiliesSupplier > xFamiliesSupp( mrExport.GetModel(), UNO_QUERY_THROW );
575  Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
576  OUString sFamilyName;
577  if (mbWriter)
578  sFamilyName = "TableStyles";
579  else
580  sFamilyName = "table";
581 
582  Reference< XIndexAccess > xTableFamily( xFamilies->getByName( sFamilyName ), UNO_QUERY_THROW );
583 
584  for( sal_Int32 nIndex = 0; nIndex < xTableFamily->getCount(); nIndex++ ) try
585  {
587 
588  Reference< XStyle > xTableStyle( xTableFamily->getByIndex( nIndex ), UNO_QUERY_THROW );
589  if( !xTableStyle->isInUse() )
590  continue;
591 
592  const TableStyleElement* pElements;
593  if (mbWriter)
594  {
595  mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, xTableStyle->getName());
596  Reference<XPropertySet> xTableStylePropSet(xTableStyle, UNO_QUERY_THROW);
598  while(pElements->meElement != XML_TOKEN_END)
599  {
600  try
601  {
602  OUString sVal;
603  xTableStylePropSet->getPropertyValue(pElements->msStyleName) >>= sVal;
605  }
606  catch(const Exception&)
607  {
608  TOOLS_WARN_EXCEPTION("xmloff", "XMLTableExport::exportTableTemplates(), export Writer specific attributes, exception caught!");
609  }
610  pElements++;
611  }
612  }
613  else
614  {
615  // checks if any of the extended version of ODF are set
616  if ((eVersion & SvtSaveOptions::ODFSVER_EXTENDED) != 0)
617  {
618  // tdf#106780 historically this wrong attribute was used
619  // for the name; write it if extended because LO < 5.3 can
620  // read only text:style-name, not the correct table:name
621  mrExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME, GetExport().EncodeStyleName( xTableStyle->getName() ) );
622  }
623  mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_NAME, GetExport().EncodeStyleName(xTableStyle->getName()));
624  }
625 
626  SvXMLElementExport tableTemplate( mrExport, XML_NAMESPACE_TABLE, XML_TABLE_TEMPLATE, true, true );
627 
628  Reference< XNameAccess > xStyleNames( xTableStyle, UNO_QUERY_THROW );
629  pElements = getTableStyleMap();
630  while( pElements->meElement != XML_TOKEN_END )
631  {
632  try
633  {
634  Reference< XStyle > xStyle( xStyleNames->getByName( pElements->msStyleName ), UNO_QUERY );
635  if( xStyle.is() )
636  {
637  mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, GetExport().EncodeStyleName( xStyle->getName() ) );
638  SvXMLElementExport element( mrExport, XML_NAMESPACE_TABLE, pElements->meElement, true, true );
639  }
640  }
641  catch(const Exception&)
642  {
643  OSL_FAIL("xmloff::XMLTableExport::exportTableTemplates(), exception caught!");
644  }
645 
646  pElements++;
647  }
648 
649  if (mbWriter && ((eVersion & SvtSaveOptions::ODFSVER_EXTENDED) != 0))
650  {
651  pElements = getWriterSpecificTableStyleMap();
652  while(pElements->meElement != XML_TOKEN_END)
653  {
654  try
655  {
656  Reference<XStyle> xStyle(xStyleNames->getByName(pElements->msStyleName), UNO_QUERY);
657  if(xStyle.is())
658  {
659  mrExport.AddAttribute(XML_NAMESPACE_TABLE, XML_STYLE_NAME, GetExport().EncodeStyleName(xStyle->getName()));
660  SvXMLElementExport element(mrExport, XML_NAMESPACE_LO_EXT, pElements->meElement, true, true);
661  }
662  }
663  catch(const Exception&)
664  {
665  TOOLS_WARN_EXCEPTION("xmloff", "XMLTableExport::exportTableTemplates(), export Writer specific styles, exception caught!");
666  }
667  pElements++;
668  }
669  }
670  }
671  catch(const Exception&)
672  {
673  TOOLS_WARN_EXCEPTION("xmloff", "XMLTableExport::exportTableDesigns(), exception caught while exporting a table design!");
674  }
675  }
676  catch(const Exception&)
677  {
678  TOOLS_WARN_EXCEPTION("xmloff", "XMLTableExport::exportTableDesigns()");
679  }
680 }
681 
682 void XMLCellStyleExport::exportStyleContent(const Reference<XStyle>& /*rStyle*/)
683 {
684 }
685 
686 void XMLCellStyleExport::exportStyleAttributes(const Reference<XStyle>& rStyle)
687 {
688  Reference<XPropertySet> xPropSet(rStyle, UNO_QUERY);
689  if (xPropSet.is())
690  {
691  Reference<XPropertySetInfo> xPropSetInfo(xPropSet->getPropertySetInfo());
692  const OUString sNumberFormat("NumberFormat");
693  if (xPropSetInfo->hasPropertyByName(sNumberFormat))
694  {
695  Reference<XPropertyState> xPropState(xPropSet, UNO_QUERY);
696  if (xPropState.is() && (PropertyState_DIRECT_VALUE ==
697  xPropState->getPropertyState(sNumberFormat)))
698  {
699  sal_Int32 nNumberFormat = 0;
700  if (xPropSet->getPropertyValue(sNumberFormat) >>= nNumberFormat)
702  GetExport().getDataStyleName(nNumberFormat));
703  }
704  }
705  }
706 }
707 
708 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const XMLPropertyMapEntry * getRowPropertiesMap()
constexpr sal_uInt16 XML_NAMESPACE_LO_EXT
Definition: xmlnmspe.hxx:74
#define XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME
Definition: families.hxx:30
static bool has_states(const std::vector< XMLPropertyState > &xPropStates)
#define XML_SD_TYPE_CELL_ROTATION_ANGLE
Definition: xmlsdtypes.hxx:122
constexpr sal_uInt16 XML_NAMESPACE_STYLE
Definition: xmlnmspe.hxx:29
void exportTableTemplates()
sal_Int32 nIndex
void exportTable(const css::uno::Reference< css::table::XColumnRowRange > &xColumnRowRange)
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:77
rtl::Reference< XMLTextParagraphExport > const & GetTextParagraphExport()
Definition: xmlexp.hxx:561
::xmloff::token::XMLTokenEnum meElement
Definition: table.hxx:29
rtl::Reference< SvXMLExportPropertyMapper > mxColumnExportPropertySetMapper
#define XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX
Definition: families.hxx:31
constexpr sal_uInt16 XML_NAMESPACE_TEXT
Definition: xmlnmspe.hxx:30
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 ...
Definition: xmlexppr.cxx:823
XMLTableExport(SvXMLExport &rExp, const rtl::Reference< SvXMLExportPropertyMapper > &xCellExportPropertySetMapper, const rtl::Reference< XMLPropertyHandlerFactory > &xFactoryRef)
SvXMLExport & GetExport()
Definition: styleexp.hxx:59
SvXMLExport & GetExport()
#define RMAP(name, prefix, token, type, context)
#define XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX
Definition: families.hxx:35
virtual void exportStyleAttributes(const css::uno::Reference< css::style::XStyle > &rStyle) override
const css::uno::Reference< css::frame::XModel > & GetModel() const
Definition: xmlexp.hxx:415
SvXMLExportPropertyMapper(const rtl::Reference< XMLPropertySetMapper > &rMapper)
Definition: xmlexppr.cxx:502
void ExportCell(const css::uno::Reference< css::table::XCell > &xCell, const std::shared_ptr< XMLTableInfo > &pTableInfo, const OUString &sDefaultCellStyle)
SvXMLExport & mrExport
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
Definition: xmlexp.cxx:925
#define CMAP(name, prefix, token, type, context)
#define XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME
Definition: families.hxx:34
SvtSaveOptions::ODFSaneDefaultVersion getSaneDefaultVersion() const
returns the deterministic version for odf export
Definition: xmlexp.cxx:2311
#define CELLMAP(name, prefix, token, type, context)
#define TOOLS_WARN_EXCEPTION(area, stream)
const TableStyleElement * getTableStyleMap()
#define MAP_END
Represents a property with its API-name, its XML-name and the type of its value.
Definition: maptype.hxx:31
OUString msStyleName
Definition: table.hxx:30
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)
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()
Definition: xmlexp.hxx:577
constexpr sal_uInt16 XML_NAMESPACE_TABLE
Definition: xmlnmspe.hxx:31
#define XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX
Definition: families.hxx:33
#define XML_TYPE_MEASURE
Definition: xmltypes.hxx:126
const XMLPropertyMapEntry * getCellPropertiesMap()
Smart struct to transport an Any with an index to the appropriate property-name.
Definition: maptype.hxx:104
const XMLPropertyMapEntry * getColumnPropertiesMap()
#define XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME
Definition: families.hxx:32
virtual ~XMLTableExport() override
static SvXMLExportPropertyMapper * CreateParaExtPropMapper(SvXMLExport &rExport)
Definition: txtparae.cxx:1353
#define XML_TYPE_BOOL
Definition: xmltypes.hxx:125
rtl::Reference< SvXMLExportPropertyMapper > mxCellExportPropertySetMapper
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)