LibreOffice Module sc (master) 1
xmlexprt.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
20#include <sal/config.h>
21#include <sal/log.hxx>
22
23#include "xmlexprt.hxx"
24#include "XMLConverter.hxx"
25#include "xmlstyle.hxx"
26#include <unonames.hxx>
27#include <document.hxx>
28#include <olinetab.hxx>
29#include <formulacell.hxx>
30#include <rangenam.hxx>
32#include <drwlayer.hxx>
35#include "XMLExportDDELinks.hxx"
36#include "XMLExportIterator.hxx"
40#include <sheetdata.hxx>
41#include <docoptio.hxx>
43#include <chgviset.hxx>
44#include <docuno.hxx>
45#include <textuno.hxx>
46#include <chartlis.hxx>
47#include <scitems.hxx>
48#include <docpool.hxx>
49#include <userdat.hxx>
50#include <chgtrack.hxx>
51#include <rangeutl.hxx>
52#include <postit.hxx>
53#include <externalrefmgr.hxx>
54#include <editutil.hxx>
55#include <tabprotection.hxx>
56#include "cachedattraccess.hxx"
57#include <colorscale.hxx>
58#include <conditio.hxx>
59#include <cellvalue.hxx>
60#include <stylehelper.hxx>
61#include <edittextiterator.hxx>
62#include "editattributemap.hxx"
63#include <arealink.hxx>
64#include <datastream.hxx>
65#include <documentlinkmgr.hxx>
67#include <cellform.hxx>
68#include <datamapper.hxx>
71#include <SparklineList.hxx>
72
73#include <xmloff/xmltoken.hxx>
75#include <xmloff/xmluconv.hxx>
77#include <xmloff/families.hxx>
78#include <xmloff/numehelp.hxx>
79#include <xmloff/txtparae.hxx>
83#include <editeng/colritem.hxx>
88#include <editeng/fhgtitem.hxx>
89#include <editeng/fontitem.hxx>
90#include <editeng/kernitem.hxx>
91#include <editeng/langitem.hxx>
92#include <editeng/postitem.hxx>
93#include <editeng/section.hxx>
94#include <editeng/shdditem.hxx>
95#include <editeng/udlnitem.hxx>
96#include <editeng/wghtitem.hxx>
97#include <editeng/wrlmitem.hxx>
98#include <editeng/xmlcnitm.hxx>
99#include <editeng/flditem.hxx>
100#include <editeng/eeitem.hxx>
101#include <formula/errorcodes.hxx>
102#include <xmloff/xmlerror.hxx>
104#include <xmloff/xmlprmap.hxx>
107
109#include <tools/fldunit.hxx>
110
111#include <rtl/ustring.hxx>
112
113#include <tools/color.hxx>
115#include <rtl/math.hxx>
116#include <svl/numformat.hxx>
117#include <svl/zforlist.hxx>
118#include <comphelper/base64.hxx>
119#include <comphelper/extract.hxx>
120#include <svx/svdoashp.hxx>
121#include <svx/svdobj.hxx>
122#include <svx/svdocapt.hxx>
123#include <svx/svdomeas.hxx>
124#include <vcl/svapp.hxx>
125
127#include <com/sun/star/beans/XPropertySet.hpp>
128#include <com/sun/star/container/XNamed.hpp>
129#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
130#include <com/sun/star/form/XFormsSupplier2.hpp>
131#include <com/sun/star/io/XActiveDataSource.hpp>
132#include <com/sun/star/io/XSeekable.hpp>
133#include <com/sun/star/sheet/XUsedAreaCursor.hpp>
134#include <com/sun/star/sheet/XCellRangeAddressable.hpp>
135#include <com/sun/star/sheet/XPrintAreas.hpp>
136#include <com/sun/star/sheet/XUniqueCellFormatRangesSupplier.hpp>
137#include <com/sun/star/sheet/XLabelRange.hpp>
138#include <com/sun/star/sheet/NamedRangeFlag.hpp>
139#include <com/sun/star/sheet/XSheetCellCursor.hpp>
140#include <com/sun/star/sheet/XSheetCellRanges.hpp>
141#include <com/sun/star/sheet/XSheetLinkable.hpp>
142#include <com/sun/star/sheet/GlobalSheetSettings.hpp>
143#include <com/sun/star/table/XColumnRowRange.hpp>
144#include <com/sun/star/util/XProtectable.hpp>
145#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
146#include <com/sun/star/chart2/XChartDocument.hpp>
147#include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
148#include <com/sun/star/chart2/data/XDataReceiver.hpp>
149
150#include <com/sun/star/document/XDocumentProperties.hpp>
151#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
152
154
155#include <sfx2/linkmgr.hxx>
156#include <sfx2/objsh.hxx>
157
158#include <memory>
159#include <vector>
161#include <officecfg/Office/Common.hxx>
162
163namespace com::sun::star::uno { class XComponentContext; }
164
165
166
168constexpr OUStringLiteral SC_LAYERID = u"LayerID";
169
170#define SC_VIEWCHANGES_COUNT 13
171#define SC_SHOW_CHANGES 0
172#define SC_SHOW_ACCEPTED_CHANGES 1
173#define SC_SHOW_REJECTED_CHANGES 2
174#define SC_SHOW_CHANGES_BY_DATETIME 3
175#define SC_SHOW_CHANGES_BY_DATETIME_MODE 4
176#define SC_SHOW_CHANGES_BY_DATETIME_FIRST_DATETIME 5
177#define SC_SHOW_CHANGES_BY_DATETIME_SECOND_DATETIME 6
178#define SC_SHOW_CHANGES_BY_AUTHOR 7
179#define SC_SHOW_CHANGES_BY_AUTHOR_NAME 8
180#define SC_SHOW_CHANGES_BY_COMMENT 9
181#define SC_SHOW_CHANGES_BY_COMMENT_TEXT 10
182#define SC_SHOW_CHANGES_BY_RANGES 11
183#define SC_SHOW_CHANGES_BY_RANGES_LIST 12
184
185using namespace formula;
186using namespace com::sun::star;
187using namespace xmloff::token;
188using ::std::vector;
189using ::com::sun::star::uno::UNO_QUERY;
190
191namespace
192{
193OUString lcl_RangeSequenceToString(
194 const uno::Sequence< OUString > & rRanges,
195 const uno::Reference< chart2::data::XRangeXMLConversion > & xFormatConverter )
196{
197 OUStringBuffer aResult;
198 const sal_Int32 nMaxIndex( rRanges.getLength() - 1 );
199 const sal_Unicode cSep(' ');
200 for( sal_Int32 i=0; i<=nMaxIndex; ++i )
201 {
202 OUString aRange( rRanges[i] );
203 if( xFormatConverter.is())
204 aRange = xFormatConverter->convertRangeToXML( aRange );
205 aResult.append( aRange );
206 if( i < nMaxIndex )
207 aResult.append( cSep );
208 }
209 return aResult.makeStringAndClear();
210}
211
212OUString lcl_GetFormattedString(ScDocument* pDoc, const ScRefCellValue& rCell, const ScAddress& rAddr)
213{
214 // return text/edit cell string content, with line feeds in edit cells
215
216 if (!pDoc)
217 return OUString();
218
219 switch (rCell.getType())
220 {
221 case CELLTYPE_STRING:
222 {
223 const Color* pColor;
224 SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
225
226 sal_uInt32 nFormat = pDoc->GetNumberFormat(rAddr);
227 return ScCellFormat::GetString(rCell, nFormat, &pColor, *pFormatter, *pDoc);
228 }
229 case CELLTYPE_EDIT:
230 {
231 const EditTextObject* pData = rCell.getEditText();
232 if (!pData)
233 return OUString();
234
235 EditEngine& rEngine = pDoc->GetEditEngine();
236 rEngine.SetText(*pData);
237 return rEngine.GetText();
238 }
239 break;
240 default:
241 ;
242 }
243
244 return OUString();
245}
246
247} // anonymous namespace
248
249extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
250Calc_XMLExporter_get_implementation(css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const &)
251{
252 return cppu::acquire(new ScXMLExport(context, "com.sun.star.comp.Calc.XMLExporter", SvXMLExportFlags::ALL));
253}
254
255extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
256Calc_XMLMetaExporter_get_implementation(css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const &)
257{
258 return cppu::acquire(new ScXMLExport(context, "com.sun.star.comp.Calc.XMLMetaExporter", SvXMLExportFlags::META));
259}
260
261extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
262Calc_XMLStylesExporter_get_implementation(css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const &)
263{
264 return cppu::acquire(new ScXMLExport(context, "com.sun.star.comp.Calc.XMLStylesExporter", SvXMLExportFlags::STYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::FONTDECLS));
265}
266
267extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
268Calc_XMLContentExporter_get_implementation(css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const &)
269{
270 return cppu::acquire(new ScXMLExport(context, "com.sun.star.comp.Calc.XMLContentExporter", SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::CONTENT|SvXMLExportFlags::SCRIPTS|SvXMLExportFlags::FONTDECLS));
271}
272
273extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
274Calc_XMLSettingsExporter_get_implementation(css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const &)
275{
276 return cppu::acquire(new ScXMLExport(context, "com.sun.star.comp.Calc.XMLSettingsExporter", SvXMLExportFlags::SETTINGS));
277}
278
279extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
280Calc_XMLOasisExporter_get_implementation(css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const &)
281{
282 return cppu::acquire(new ScXMLExport(context, "com.sun.star.comp.Calc.XMLOasisExporter", SvXMLExportFlags::ALL|SvXMLExportFlags::OASIS));
283}
284
285extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
286Calc_XMLOasisMetaExporter_get_implementation(css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const &)
287{
288 return cppu::acquire(new ScXMLExport(context, "com.sun.star.comp.Calc.XMLOasisMetaExporter", SvXMLExportFlags::META|SvXMLExportFlags::OASIS));
289}
290
291extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
292Calc_XMLOasisStylesExporter_get_implementation(css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const &)
293{
294 return cppu::acquire(new ScXMLExport(context, "com.sun.star.comp.Calc.XMLOasisStylesExporter", SvXMLExportFlags::STYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::FONTDECLS|SvXMLExportFlags::OASIS));
295}
296
297extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
298Calc_XMLOasisContentExporter_get_implementation(css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const &)
299{
300 return cppu::acquire(new ScXMLExport(context, "com.sun.star.comp.Calc.XMLOasisContentExporter", SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::CONTENT|SvXMLExportFlags::SCRIPTS|SvXMLExportFlags::FONTDECLS|SvXMLExportFlags::OASIS));
301}
302
303extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
304Calc_XMLOasisSettingsExporter_get_implementation(css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const &)
305{
306 return cppu::acquire(new ScXMLExport(context, "com.sun.star.comp.Calc.XMLOasisSettingsExporter", SvXMLExportFlags::SETTINGS|SvXMLExportFlags::OASIS));
307}
308
309namespace {
310
311class ScXMLShapeExport : public XMLShapeExport
312{
313public:
314 explicit ScXMLShapeExport(SvXMLExport& rExp)
315 : XMLShapeExport(rExp,
316 // chain text attributes
317 XMLTextParagraphExport::CreateParaExtPropMapper(rExp))
318 {
319 }
320
322 virtual void onExport( const uno::Reference < drawing::XShape >& xShape ) override;
323};
324
325}
326
327void ScXMLShapeExport::onExport( const uno::Reference < drawing::XShape >& xShape )
328{
329 uno::Reference< beans::XPropertySet > xShapeProp( xShape, uno::UNO_QUERY );
330 if( xShapeProp.is() )
331 {
332 sal_Int16 nLayerID = 0;
333 if( (xShapeProp->getPropertyValue( SC_LAYERID ) >>= nLayerID) && (SdrLayerID(nLayerID) == SC_LAYER_BACK) )
334 GetExport().AddAttribute(XML_NAMESPACE_TABLE, XML_TABLE_BACKGROUND, XML_TRUE);
335 }
336}
337
339{
340 css::uno::Reference<css::sheet::XGlobalSheetSettings> xProperties =
341 css::sheet::GlobalSheetSettings::create( comphelper::getProcessComponentContext() );
342 const FieldUnit eFieldUnit = static_cast<FieldUnit>(xProperties->getMetric());
343 return SvXMLUnitConverter::GetMeasureUnit(eFieldUnit);
344}
345
347 const css::uno::Reference< css::uno::XComponentContext >& rContext,
348 OUString const & implementationName, SvXMLExportFlags nExportFlag)
350 rContext, implementationName, GetMeasureUnit(), XML_SPREADSHEET, nExportFlag ),
351 pDoc(nullptr),
352 nSourceStreamPos(0),
353 pCurrentCell(nullptr),
354 nOpenRow(-1),
355 nProgressCount(0),
356 nCurrentTable(0),
357 bHasRowHeader(false),
358 bRowHeaderOpen(false)
359{
360 if (getExportFlags() & SvXMLExportFlags::CONTENT)
361 {
364 pColumnStyles.reset( new ScColumnStyles() );
365 pRowStyles.reset( new ScRowStyles() );
366 pRowFormatRanges.reset( new ScRowFormatRanges() );
369 mpCellsItr.reset(new ScMyNotEmptyCellsIterator(*this));
370 pDefaults.reset( new ScMyDefaultStyles );
371 }
372 pCellStyles.reset( new ScFormatRangeStyles() );
373
374 // document is not set here - create ScChangeTrackingExportHelper later
375
386
387 GetAutoStylePool()->AddFamily(XmlStyleFamily::TABLE_CELL, XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME,
389 GetAutoStylePool()->AddFamily(XmlStyleFamily::TABLE_COLUMN, XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_NAME,
391 GetAutoStylePool()->AddFamily(XmlStyleFamily::TABLE_ROW, XML_STYLE_FAMILY_TABLE_ROW_STYLES_NAME,
393 GetAutoStylePool()->AddFamily(XmlStyleFamily::TABLE_TABLE, XML_STYLE_FAMILY_TABLE_TABLE_STYLES_NAME,
395
396 GetShapeExport(); // make sure the graphics styles family is added
397
398 if( !(getExportFlags() & (SvXMLExportFlags::STYLES|SvXMLExportFlags::AUTOSTYLES|SvXMLExportFlags::MASTERSTYLES|SvXMLExportFlags::CONTENT)) )
399 return;
400
401 // This name is reserved for the external ref cache tables. This
402 // should not conflict with user-defined styles since this name is
403 // used for a table style which is not available in the UI.
404 sExternalRefTabStyleName = "ta_extref";
405 GetAutoStylePool()->RegisterName(XmlStyleFamily::TABLE_TABLE, sExternalRefTabStyleName);
406
419}
420
422{
423 pGroupColumns.reset();
424 pGroupRows.reset();
425 pColumnStyles.reset();
426 pRowStyles.reset();
427 pCellStyles.reset();
428 pRowFormatRanges.reset();
430 pValidationsContainer.reset();
432 pDefaults.reset();
434}
435
436void ScXMLExport::SetSourceStream( const uno::Reference<io::XInputStream>& xNewStream )
437{
438 xSourceStream = xNewStream;
439
440 if ( !xSourceStream.is() )
441 return;
442
443 // make sure it's a plain UTF-8 stream as written by OOo itself
444
445 const char pXmlHeader[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
446 sal_Int32 nLen = strlen(pXmlHeader);
447
448 uno::Sequence<sal_Int8> aFileStart(nLen);
449 sal_Int32 nRead = xSourceStream->readBytes( aFileStart, nLen );
450
451 if ( nRead != nLen || memcmp( aFileStart.getConstArray(), pXmlHeader, nLen ) != 0 )
452 {
453 // invalid - ignore stream, save normally
454 xSourceStream.clear();
455 }
456 else
457 {
458 // keep track of the bytes already read
459 nSourceStreamPos = nRead;
460
461 const ScSheetSaveData* pSheetData = comphelper::getFromUnoTunnel<ScModelObj>(GetModel())->GetSheetSaveData();
462 if (pSheetData)
463 {
464 // add the loaded namespaces to the name space map
465
466 if ( !pSheetData->AddLoadedNamespaces( GetNamespaceMap_() ) )
467 {
468 // conflicts in the namespaces - ignore the stream, save normally
469 xSourceStream.clear();
470 }
471 }
472 }
473}
474
475sal_Int32 ScXMLExport::GetNumberFormatStyleIndex(sal_Int32 nNumFmt) const
476{
477 NumberFormatIndexMap::const_iterator itr = aNumFmtIndexMap.find(nNumFmt);
478 if (itr == aNumFmtIndexMap.end())
479 return -1;
480
481 return itr->second;
482}
483
484void ScXMLExport::CollectSharedData(SCTAB& nTableCount, sal_Int32& nShapesCount)
485{
486 if (!GetModel().is())
487 return;
488
489 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc(GetModel(), uno::UNO_QUERY);
490 if (!xSpreadDoc.is())
491 return;
492
493 uno::Reference<container::XIndexAccess> xIndex(xSpreadDoc->getSheets(), uno::UNO_QUERY);
494 if (!xIndex.is())
495 return;
496
497 nTableCount = xIndex->getCount();
498 if (!pSharedData)
499 pSharedData.reset(new ScMySharedData(nTableCount));
500
501 pCellStyles->AddNewTable(nTableCount - 1);
502
503 for (SCTAB nTable = 0; nTable < nTableCount; ++nTable)
504 {
505 nCurrentTable = sal::static_int_cast<sal_uInt16>(nTable);
506 uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xIndex->getByIndex(nTable), uno::UNO_QUERY);
507 if (!xDrawPageSupplier.is())
508 continue;
509
510 uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage());
511 ScMyDrawPage aDrawPage;
512 aDrawPage.bHasForms = false;
513 aDrawPage.xDrawPage.set(xDrawPage);
514 pSharedData->AddDrawPage(aDrawPage, nTable);
515 if (!xDrawPage.is())
516 continue;
517
518 sal_Int32 nShapes = xDrawPage->getCount();
519 for (sal_Int32 nShape = 0; nShape < nShapes; ++nShape)
520 {
521 uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(nShape), uno::UNO_QUERY);
522 if (!xShape.is())
523 continue;
524
525 uno::Reference<beans::XPropertySet> xShapeProp(xShape, uno::UNO_QUERY);
526 if (!xShapeProp.is())
527 continue;
528
529 sal_Int16 nLayerID = 0;
530 bool bExtracted = xShapeProp->getPropertyValue(SC_LAYERID) >>= nLayerID;
531 if (!bExtracted)
532 continue;
533
534 if ((SdrLayerID(nLayerID) == SC_LAYER_INTERN) || (SdrLayerID(nLayerID) == SC_LAYER_HIDDEN))
535 {
536 CollectInternalShape(xShape);
537 continue;
538 }
539
540 ++nShapesCount;
541
543 if (!pSdrObj)
544 continue;
545
546 if (ScDrawObjData *pAnchor = ScDrawLayer::GetNonRotatedObjData(pSdrObj))
547 {
548 ScMyShape aMyShape;
549 aMyShape.aAddress = pAnchor->maStart;
550 SAL_WARN_IF(aMyShape.aAddress.Tab() != nTable, "sc", "not anchored to current sheet!");
551 aMyShape.aAddress.SetTab(nTable);
552 aMyShape.aEndAddress = pAnchor->maEnd;
553 aMyShape.aEndAddress.SetTab( nTable );
554 aMyShape.nEndX = pAnchor->maEndOffset.X();
555 aMyShape.nEndY = pAnchor->maEndOffset.Y();
556 aMyShape.xShape = xShape;
557 pSharedData->AddNewShape(aMyShape);
558 pSharedData->SetLastColumn(nTable, pAnchor->maStart.Col());
559 pSharedData->SetLastRow(nTable, pAnchor->maStart.Row());
560 }
561 else
562 pSharedData->AddTableShape(nTable, xShape);
563 }
564 }
565}
566
568{
569 // #i84077# To avoid compiler warnings about uninitialized aShapeItr,
570 // it's initialized using this dummy list. The iterator contains shapes
571 // from all sheets, so it can't be declared inside the nTable loop where
572 // it is used.
573 ScMyShapeList aDummyInitList;
574
575 pSharedData->SortShapesContainer();
576 pSharedData->SortNoteShapes();
577 const ScMyShapeList* pShapeList(nullptr);
578 ScMyShapeList::const_iterator aShapeItr = aDummyInitList.end();
579 if (pSharedData->GetShapesContainer())
580 {
581 pShapeList = &pSharedData->GetShapesContainer()->GetShapes();
582 aShapeItr = pShapeList->begin();
583 }
584 if (pSharedData->HasDrawPage())
585 {
586 for (SCTAB nTable = 0; nTable < nTableCount; ++nTable)
587 {
588 uno::Reference<drawing::XDrawPage> xDrawPage(pSharedData->GetDrawPage(nTable));
589
590 if (xDrawPage.is())
591 {
592 GetShapeExport()->seekShapes(xDrawPage);
593 uno::Reference< form::XFormsSupplier2 > xFormsSupplier( xDrawPage, uno::UNO_QUERY );
594 if( xFormsSupplier.is() && xFormsSupplier->hasForms() )
595 {
596 GetFormExport()->examineForms(xDrawPage);
597 pSharedData->SetDrawPageHasForms(nTable, true);
598 }
599 ScMyTableShapes* pTableShapes(pSharedData->GetTableShapes());
600 if (pTableShapes)
601 {
602 for (const auto& rxShape : (*pTableShapes)[nTable])
603 {
604 GetShapeExport()->collectShapeAutoStyles(rxShape);
606 }
607 }
608 if (pShapeList)
609 {
610 ScMyShapeList::const_iterator aEndItr(pShapeList->end());
611 while ( aShapeItr != aEndItr && ( aShapeItr->aAddress.Tab() == nTable ) )
612 {
613 GetShapeExport()->collectShapeAutoStyles(aShapeItr->xShape);
615 ++aShapeItr;
616 }
617 }
618 if (pSharedData->GetNoteShapes())
619 {
620 const ScMyNoteShapeList& rNoteShapes = pSharedData->GetNoteShapes()->GetNotes();
621 for (const auto& rNoteShape : rNoteShapes)
622 {
623 if ( rNoteShape.aPos.Tab() == nTable )
624 GetShapeExport()->collectShapeAutoStyles(rNoteShape.xShape);
625 }
626 }
627 }
628 }
629 }
630 pSharedData->SortNoteShapes(); // sort twice, because some more shapes are added
631}
632
634{
635 sal_Int32 nCellCount(pDoc ? pDoc->GetCellCount() : 0);
636 SCTAB nTableCount(0);
637 sal_Int32 nShapesCount(0);
638 GetAutoStylePool()->ClearEntries();
639 CollectSharedData(nTableCount, nShapesCount);
640
641 uno::Sequence<beans::NamedValue> stats
642 {
643 { "TableCount", uno::Any(static_cast<sal_Int32>(nTableCount)) },
644 { "CellCount", uno::Any(nCellCount) },
645 { "ObjectCount", uno::Any(nShapesCount) }
646 };
647
648 // update document statistics at the model
649 uno::Reference<document::XDocumentPropertiesSupplier> xPropSup(GetModel(),
650 uno::UNO_QUERY_THROW);
651 uno::Reference<document::XDocumentProperties> xDocProps(
652 xPropSup->getDocumentProperties());
653 if (xDocProps.is()) {
654 xDocProps->setDocumentStatistics(stats);
655 }
656
657 // export document properties
659}
660
662{
663 GetFontAutoStylePool(); // make sure the pool is created
665}
666
667table::CellRangeAddress ScXMLExport::GetEndAddress(const uno::Reference<sheet::XSpreadsheet>& xTable)
668{
669 table::CellRangeAddress aCellAddress;
670 uno::Reference<sheet::XSheetCellCursor> xCursor(xTable->createCursor());
671 uno::Reference<sheet::XUsedAreaCursor> xUsedArea (xCursor, uno::UNO_QUERY);
672 uno::Reference<sheet::XCellRangeAddressable> xCellAddress (xCursor, uno::UNO_QUERY);
673 if (xUsedArea.is() && xCellAddress.is())
674 {
675 xUsedArea->gotoEndOfUsedArea(true);
676 aCellAddress = xCellAddress->getRangeAddress();
677 }
678 return aCellAddress;
679}
680
682{
683 if (pDoc->GetLinkManager())
684 {
685 const sfx2::SvBaseLinks& rLinks = pDoc->GetLinkManager()->GetLinks();
686 for (const auto & rLink : rLinks)
687 {
688 ScAreaLink *pLink = dynamic_cast<ScAreaLink*>(rLink.get());
689 if (pLink)
690 {
691 ScMyAreaLink aAreaLink;
692 aAreaLink.aDestRange = pLink->GetDestArea();
693 aAreaLink.sSourceStr = pLink->GetSource();
694 aAreaLink.sFilter = pLink->GetFilter();
695 aAreaLink.sFilterOptions = pLink->GetOptions();
696 aAreaLink.sURL = pLink->GetFile();
697 aAreaLink.nRefreshDelaySeconds = pLink->GetRefreshDelaySeconds();
698 rAreaLinks.AddNewAreaLink( aAreaLink );
699 }
700 }
701 }
702 rAreaLinks.Sort();
703}
704
705// core implementation
707{
708 if (!pDoc)
709 return;
710
711 ScDetOpList* pOpList(pDoc->GetDetOpList());
712 if( !pOpList )
713 return;
714
715 size_t nCount = pOpList->Count();
716 for (size_t nIndex = 0; nIndex < nCount; ++nIndex )
717 {
718 const ScDetOpData& rDetData = pOpList->GetObject( nIndex);
719 const ScAddress& rDetPos = rDetData.GetPos();
720 SCTAB nTab = rDetPos.Tab();
721 if ( nTab < pDoc->GetTableCount() )
722 {
723 rDetOp.AddOperation( rDetData.GetOperation(), rDetPos, static_cast<sal_uInt32>( nIndex) );
724
725 // cells with detective operations are written even if empty
726 pSharedData->SetLastColumn( nTab, rDetPos.Col() );
727 pSharedData->SetLastRow( nTab, rDetPos.Row() );
728 }
729 }
730 rDetOp.Sort();
731}
732
733void ScXMLExport::WriteSingleColumn(const sal_Int32 nRepeatColumns, const sal_Int32 nStyleIndex,
734 const sal_Int32 nIndex, const bool bIsAutoStyle, const bool bIsVisible)
735{
737 // tdf#138466
738 if (nStyleIndex != -1)
739 AddAttribute(sAttrStyleName, pColumnStyles->GetStyleNameByIndex(nStyleIndex));
740 if (!bIsVisible)
742 if (nRepeatColumns > 1)
743 {
744 OUString sOUEndCol(OUString::number(nRepeatColumns));
746 }
747 if (nIndex != -1)
749 SvXMLElementExport aElemC(*this, sElemCol, true, true);
750}
751
752void ScXMLExport::WriteColumn(const sal_Int32 nColumn, const sal_Int32 nRepeatColumns,
753 const sal_Int32 nStyleIndex, const bool bIsVisible)
754{
755 sal_Int32 nRepeat(1);
756 sal_Int32 nPrevIndex(pDefaults->GetColDefaults()[nColumn].nIndex);
757 bool bPrevAutoStyle(pDefaults->GetColDefaults()[nColumn].bIsAutoStyle);
758 for (sal_Int32 i = nColumn + 1; i < nColumn + nRepeatColumns; ++i)
759 {
760 if ((pDefaults->GetColDefaults()[i].nIndex != nPrevIndex) ||
761 (pDefaults->GetColDefaults()[i].bIsAutoStyle != bPrevAutoStyle))
762 {
763 WriteSingleColumn(nRepeat, nStyleIndex, nPrevIndex, bPrevAutoStyle, bIsVisible);
764 nPrevIndex = pDefaults->GetColDefaults()[i].nIndex;
765 bPrevAutoStyle = pDefaults->GetColDefaults()[i].bIsAutoStyle;
766 nRepeat = 1;
767 }
768 else
769 ++nRepeat;
770 }
771 WriteSingleColumn(nRepeat, nStyleIndex, nPrevIndex, bPrevAutoStyle, bIsVisible);
772}
773
775{
777}
778
780{
782}
783
784void ScXMLExport::ExportColumns(const sal_Int32 nTable, const ScRange& aColumnHeaderRange, const bool bHasColumnHeader)
785{
786 sal_Int32 nColsRepeated (1);
787 sal_Int32 nIndex;
788 sal_Int32 nPrevColumn(0);
789 bool bPrevIsVisible (true);
790 bool bWasHeader (false);
791 bool bIsClosed (true);
792 sal_Int32 nPrevIndex (-1);
793 sal_Int32 nColumn;
794 for (nColumn = 0; nColumn <= pSharedData->GetLastColumn(nTable); ++nColumn)
795 {
797 bool bIsVisible(true);
798 nIndex = pColumnStyles->GetStyleNameIndex(nTable, nColumn, bIsVisible);
799
800 const bool bIsHeader = bHasColumnHeader && (aColumnHeaderRange.aStart.Col() <= nColumn) && (nColumn <= aColumnHeaderRange.aEnd.Col());
801 if (bIsHeader != bWasHeader)
802 {
803 if (bIsHeader)
804 {
805 if (nColumn > 0)
806 {
807 WriteColumn(nPrevColumn, nColsRepeated, nPrevIndex, bPrevIsVisible);
808 if (pGroupColumns->IsGroupEnd(nColumn - 1))
809 pGroupColumns->CloseGroups(nColumn - 1);
810 }
811 bPrevIsVisible = bIsVisible;
812 nPrevIndex = nIndex;
813 nPrevColumn = nColumn;
814 nColsRepeated = 1;
815 if(pGroupColumns->IsGroupStart(nColumn))
816 pGroupColumns->OpenGroups(nColumn);
818 bWasHeader = true;
819 bIsClosed = false;
820 }
821 else
822 {
823 WriteColumn(nPrevColumn, nColsRepeated, nPrevIndex, bPrevIsVisible);
825 if (pGroupColumns->IsGroupEnd(nColumn - 1))
826 pGroupColumns->CloseGroups(nColumn - 1);
827 if(pGroupColumns->IsGroupStart(nColumn))
828 pGroupColumns->OpenGroups(nColumn);
829 bPrevIsVisible = bIsVisible;
830 nPrevIndex = nIndex;
831 nPrevColumn = nColumn;
832 nColsRepeated = 1;
833 bWasHeader = false;
834 bIsClosed = true;
835 }
836 }
837 else if (nColumn == 0)
838 {
839 if (pGroupColumns->IsGroupStart(nColumn))
840 pGroupColumns->OpenGroups(nColumn);
841 bPrevIsVisible = bIsVisible;
842 nPrevIndex = nIndex;
843 }
844 else if ((bIsVisible == bPrevIsVisible) && (nIndex == nPrevIndex) &&
845 !pGroupColumns->IsGroupStart(nColumn) && !pGroupColumns->IsGroupEnd(nColumn - 1))
846 ++nColsRepeated;
847 else
848 {
849 WriteColumn(nPrevColumn, nColsRepeated, nPrevIndex, bPrevIsVisible);
850 if (pGroupColumns->IsGroupEnd(nColumn - 1))
851 {
852 if (bIsHeader)
854 pGroupColumns->CloseGroups(nColumn - 1);
855 if (bIsHeader)
857 }
858 if (pGroupColumns->IsGroupStart(nColumn))
859 {
860 if (bIsHeader)
862 pGroupColumns->OpenGroups(nColumn);
863 if (bIsHeader)
865 }
866 bPrevIsVisible = bIsVisible;
867 nPrevIndex = nIndex;
868 nPrevColumn = nColumn;
869 nColsRepeated = 1;
870 }
871 }
872 WriteColumn(nPrevColumn, nColsRepeated, nPrevIndex, bPrevIsVisible);
873 if (!bIsClosed)
875 if (pGroupColumns->IsGroupEnd(nColumn - 1))
876 pGroupColumns->CloseGroups(nColumn - 1);
877}
878
880{
881 sal_Int32 nEntryIndex = GetCellStylesPropertySetMapper()->FindEntryIndex(
882 "NumberFormat", XML_NAMESPACE_STYLE, u"data-style-name");
883
884 if (nEntryIndex < 0)
885 // No entry index for the number format is found.
886 return;
887
889 if (!pRefMgr->hasExternalData())
890 // No external reference data cached.
891 return;
892
893 // Export each unique number format used in the external ref cache.
894 vector<sal_uInt32> aNumFmts;
895 pRefMgr->getAllCachedNumberFormats(aNumFmts);
896 static constexpr OUStringLiteral aDefaultStyle(u"Default");
897 for (const auto& rNumFmt : aNumFmts)
898 {
899 sal_Int32 nNumFmt = static_cast<sal_Int32>(rNumFmt);
900
901 addDataStyle(nNumFmt);
902
903 uno::Any aVal;
904 aVal <<= nNumFmt;
905 vector<XMLPropertyState> aProps;
906 aVal <<= OUString(aDefaultStyle);
907 aProps.emplace_back(nEntryIndex, aVal);
908
909 OUString aName;
910 sal_Int32 nIndex;
911 if (GetAutoStylePool()->Add(aName, XmlStyleFamily::TABLE_CELL, aDefaultStyle, std::move(aProps)))
912 {
913 pCellStyles->AddStyleName(aName, nIndex);
914 }
915 else
916 {
917 bool bIsAuto;
918 nIndex = pCellStyles->GetIndexOfStyleName(
920 }
921
922 // store the number format to index mapping for later use.
923 aNumFmtIndexMap.emplace(nNumFmt, nIndex);
924 }
925}
926
927namespace {
928
929void handleFont(
930 SvXMLExport & rExport,
931 std::vector<XMLPropertyState>& rPropStates,
932 const SfxPoolItem* p, const rtl::Reference<XMLPropertySetMapper>& xMapper, std::u16string_view rXMLName )
933{
934 sal_Int32 nEntryCount = xMapper->GetEntryCount();
935
936 // Apparently font info needs special handling.
937 const SvxFontItem* pItem = static_cast<const SvxFontItem*>(p);
938
939 sal_Int32 nIndexFontName = xMapper->GetEntryIndex(XML_NAMESPACE_STYLE, rXMLName, 0);
940
941 if (nIndexFontName == -1 || nIndexFontName >= nEntryCount)
942 return;
943
944 OUString const sFamilyName(pItem->GetFamilyName());
945 OUString const sStyleName(pItem->GetStyleName());
946 auto const nFamily(pItem->GetFamily());
947 auto const nPitch(pItem->GetPitch());
948 auto const eEnc(pItem->GetCharSet());
949 OUString const sName(rExport.GetFontAutoStylePool()->Find(
950 sFamilyName, sStyleName, nFamily, nPitch, eEnc));
951 if (sName.isEmpty())
952 {
953 assert(false); // fallback to fo:font-family etc. probably not needed
954 }
955
956 rPropStates.emplace_back(nIndexFontName, uno::Any(sName));
957}
958
959const SvxFieldData* toXMLPropertyStates(
960 SvXMLExport & rExport,
961 std::vector<XMLPropertyState>& rPropStates, const std::vector<const SfxPoolItem*>& rSecAttrs,
962 const rtl::Reference<XMLPropertySetMapper>& xMapper, const ScXMLEditAttributeMap& rAttrMap )
963{
964 const SvxFieldData* pField = nullptr;
965 sal_Int32 nEntryCount = xMapper->GetEntryCount();
966 rPropStates.reserve(rSecAttrs.size());
967 for (const SfxPoolItem* p : rSecAttrs)
968 {
969 if (p->Which() == EE_FEATURE_FIELD)
970 {
971 pField = static_cast<const SvxFieldItem*>(p)->GetField();
972 continue;
973 }
974
975 const ScXMLEditAttributeMap::Entry* pEntry = rAttrMap.getEntryByItemID(p->Which());
976 if (!pEntry)
977 continue;
978
979 sal_Int32 nIndex = xMapper->GetEntryIndex(
980 pEntry->nmXMLNS, OUString::createFromAscii(pEntry->mpXMLName), 0);
981
982 if (nIndex == -1 || nIndex >= nEntryCount)
983 continue;
984
985 uno::Any aAny;
986 switch (p->Which())
987 {
988 case EE_CHAR_FONTINFO:
989 handleFont(rExport, rPropStates, p, xMapper, u"font-name");
990 break;
992 handleFont(rExport, rPropStates, p, xMapper, u"font-name-asian");
993 break;
995 handleFont(rExport, rPropStates, p, xMapper, u"font-name-complex");
996 break;
997 case EE_CHAR_WEIGHT:
1000 {
1001 if (!static_cast<const SvxWeightItem*>(p)->QueryValue(aAny, pEntry->mnFlag))
1002 continue;
1003
1004 rPropStates.emplace_back(nIndex, aAny);
1005 }
1006 break;
1007 case EE_CHAR_FONTHEIGHT:
1010 {
1011 if (!static_cast<const SvxFontHeightItem*>(p)->QueryValue(aAny, pEntry->mnFlag))
1012 continue;
1013
1014 rPropStates.emplace_back(nIndex, aAny);
1015 }
1016 break;
1017 case EE_CHAR_ITALIC:
1018 case EE_CHAR_ITALIC_CJK:
1019 case EE_CHAR_ITALIC_CTL:
1020 {
1021 if (!static_cast<const SvxPostureItem*>(p)->QueryValue(aAny, pEntry->mnFlag))
1022 continue;
1023
1024 rPropStates.emplace_back(nIndex, aAny);
1025 }
1026 break;
1027 case EE_CHAR_UNDERLINE:
1028 {
1029 // Underline attribute needs to export multiple entries.
1030 sal_Int32 nIndexStyle = xMapper->GetEntryIndex(XML_NAMESPACE_STYLE, u"text-underline-style", 0);
1031 if (nIndexStyle == -1 || nIndexStyle > nEntryCount)
1032 break;
1033
1034 sal_Int32 nIndexWidth = xMapper->GetEntryIndex(XML_NAMESPACE_STYLE, u"text-underline-width", 0);
1035 if (nIndexWidth == -1 || nIndexWidth > nEntryCount)
1036 break;
1037
1038 sal_Int32 nIndexType = xMapper->GetEntryIndex(XML_NAMESPACE_STYLE, u"text-underline-type", 0);
1039 if (nIndexType == -1 || nIndexType > nEntryCount)
1040 break;
1041
1042 sal_Int32 nIndexColor = xMapper->FindEntryIndex("CharUnderlineColor", XML_NAMESPACE_STYLE, u"text-underline-color");
1043 if (nIndexColor == -1 || nIndexColor > nEntryCount)
1044 break;
1045
1046 sal_Int32 nIndexHasColor = xMapper->FindEntryIndex("CharUnderlineHasColor", XML_NAMESPACE_STYLE, u"text-underline-color");
1047 if (nIndexHasColor == -1 || nIndexHasColor > nEntryCount)
1048 break;
1049
1050 const SvxUnderlineItem* pUL = static_cast<const SvxUnderlineItem*>(p);
1051 pUL->QueryValue(aAny, MID_TL_STYLE);
1052 rPropStates.emplace_back(nIndexStyle, aAny);
1053 rPropStates.emplace_back(nIndexType, aAny);
1054 rPropStates.emplace_back(nIndexWidth, aAny);
1055
1056 pUL->QueryValue(aAny, MID_TL_COLOR);
1057 rPropStates.emplace_back(nIndexColor, aAny);
1058
1059 pUL->QueryValue(aAny, MID_TL_HASCOLOR);
1060 rPropStates.emplace_back(nIndexHasColor, aAny);
1061 }
1062 break;
1063 case EE_CHAR_OVERLINE:
1064 {
1065 // Same with overline. Do just as we do with underline attributes.
1066 sal_Int32 nIndexStyle = xMapper->GetEntryIndex(XML_NAMESPACE_STYLE, u"text-overline-style", 0);
1067 if (nIndexStyle == -1 || nIndexStyle > nEntryCount)
1068 break;
1069
1070 sal_Int32 nIndexWidth = xMapper->GetEntryIndex(XML_NAMESPACE_STYLE, u"text-overline-width", 0);
1071 if (nIndexWidth == -1 || nIndexWidth > nEntryCount)
1072 break;
1073
1074 sal_Int32 nIndexType = xMapper->GetEntryIndex(XML_NAMESPACE_STYLE, u"text-overline-type", 0);
1075 if (nIndexType == -1 || nIndexType > nEntryCount)
1076 break;
1077
1078 sal_Int32 nIndexColor = xMapper->FindEntryIndex("CharOverlineColor", XML_NAMESPACE_STYLE, u"text-overline-color");
1079 if (nIndexColor == -1 || nIndexColor > nEntryCount)
1080 break;
1081
1082 sal_Int32 nIndexHasColor = xMapper->FindEntryIndex("CharOverlineHasColor", XML_NAMESPACE_STYLE, u"text-overline-color");
1083 if (nIndexHasColor == -1 || nIndexHasColor > nEntryCount)
1084 break;
1085
1086 const SvxOverlineItem* pOL = static_cast<const SvxOverlineItem*>(p);
1087 pOL->QueryValue(aAny, MID_TL_STYLE);
1088 rPropStates.emplace_back(nIndexStyle, aAny);
1089 rPropStates.emplace_back(nIndexType, aAny);
1090 rPropStates.emplace_back(nIndexWidth, aAny);
1091
1092 pOL->QueryValue(aAny, MID_TL_COLOR);
1093 rPropStates.emplace_back(nIndexColor, aAny);
1094
1095 pOL->QueryValue(aAny, MID_TL_HASCOLOR);
1096 rPropStates.emplace_back(nIndexHasColor, aAny);
1097 }
1098 break;
1099 case EE_CHAR_COLOR:
1100 {
1101 if (!static_cast<const SvxColorItem*>(p)->QueryValue(aAny, pEntry->mnFlag))
1102 continue;
1103
1104 ::Color nColor;
1105 if ( aAny >>= nColor )
1106 {
1107 sal_Int32 nIndexColor = ( nColor == COL_AUTO ) ? xMapper->GetEntryIndex(
1108 XML_NAMESPACE_STYLE, GetXMLToken( XML_USE_WINDOW_FONT_COLOR ), 0 ) : nIndex;
1109 rPropStates.emplace_back( nIndexColor, aAny );
1110 }
1111 }
1112 break;
1113 case EE_CHAR_WLM:
1114 {
1115 if (!static_cast<const SvxWordLineModeItem*>(p)->QueryValue(aAny, pEntry->mnFlag))
1116 continue;
1117
1118 rPropStates.emplace_back(nIndex, aAny);
1119 }
1120 break;
1121 case EE_CHAR_STRIKEOUT:
1122 {
1123 if (!static_cast<const SvxCrossedOutItem*>(p)->QueryValue(aAny, pEntry->mnFlag))
1124 continue;
1125
1126 rPropStates.emplace_back(nIndex, aAny);
1127 }
1128 break;
1129 case EE_CHAR_RELIEF:
1130 {
1131 if (!static_cast<const SvxCharReliefItem*>(p)->QueryValue(aAny, pEntry->mnFlag))
1132 continue;
1133
1134 rPropStates.emplace_back(nIndex, aAny);
1135 }
1136 break;
1137 case EE_CHAR_OUTLINE:
1138 {
1139 if (!static_cast<const SvxContourItem*>(p)->QueryValue(aAny, pEntry->mnFlag))
1140 continue;
1141
1142 rPropStates.emplace_back(nIndex, aAny);
1143 }
1144 break;
1145 case EE_CHAR_SHADOW:
1146 {
1147 if (!static_cast<const SvxShadowedItem*>(p)->QueryValue(aAny, pEntry->mnFlag))
1148 continue;
1149
1150 rPropStates.emplace_back(nIndex, aAny);
1151 }
1152 break;
1153 case EE_CHAR_KERNING:
1154 {
1155 if (!static_cast<const SvxKerningItem*>(p)->QueryValue(aAny, pEntry->mnFlag))
1156 continue;
1157
1158 rPropStates.emplace_back(nIndex, aAny);
1159 }
1160 break;
1162 {
1163 if (!static_cast<const SvxAutoKernItem*>(p)->QueryValue(aAny, pEntry->mnFlag))
1164 continue;
1165
1166 rPropStates.emplace_back(nIndex, aAny);
1167 }
1168 break;
1169 case EE_CHAR_FONTWIDTH:
1170 {
1171 if (!static_cast<const SvxCharScaleWidthItem*>(p)->QueryValue(aAny, pEntry->mnFlag))
1172 continue;
1173
1174 rPropStates.emplace_back(nIndex, aAny);
1175 }
1176 break;
1177 case EE_CHAR_ESCAPEMENT:
1178 {
1179 sal_Int32 nIndexEsc = xMapper->FindEntryIndex("CharEscapement", XML_NAMESPACE_STYLE, u"text-position");
1180 if (nIndexEsc == -1 || nIndexEsc > nEntryCount)
1181 break;
1182
1183 sal_Int32 nIndexEscHeight = xMapper->FindEntryIndex("CharEscapementHeight", XML_NAMESPACE_STYLE, u"text-position");
1184 if (nIndexEscHeight == -1 || nIndexEscHeight > nEntryCount)
1185 break;
1186
1187 const SvxEscapementItem* pEsc = static_cast<const SvxEscapementItem*>(p);
1188
1189 pEsc->QueryValue(aAny);
1190 rPropStates.emplace_back(nIndexEsc, aAny);
1191
1192 pEsc->QueryValue(aAny, MID_ESC_HEIGHT);
1193 rPropStates.emplace_back(nIndexEscHeight, aAny);
1194
1195 }
1196 break;
1198 {
1199 if (!static_cast<const SvxEmphasisMarkItem*>(p)->QueryValue(aAny, pEntry->mnFlag))
1200 continue;
1201
1202 rPropStates.emplace_back(nIndex, aAny);
1203 }
1204 break;
1205 case EE_CHAR_LANGUAGE:
1208 {
1209 if (!static_cast<const SvxLanguageItem*>(p)->QueryValue(aAny, pEntry->mnFlag))
1210 continue;
1211
1212 // Export multiple entries.
1213 sal_Int32 nIndexLanguage, nIndexCountry, nIndexScript, nIndexTag;
1214 switch (p->Which())
1215 {
1216 case EE_CHAR_LANGUAGE:
1217 nIndexLanguage = xMapper->GetEntryIndex( XML_NAMESPACE_FO, u"language", 0);
1218 nIndexCountry = xMapper->GetEntryIndex( XML_NAMESPACE_FO, u"country", 0);
1219 nIndexScript = xMapper->GetEntryIndex( XML_NAMESPACE_FO, u"script", 0);
1220 nIndexTag = xMapper->GetEntryIndex( XML_NAMESPACE_STYLE, u"rfc-language-tag", 0);
1221 break;
1223 nIndexLanguage = xMapper->GetEntryIndex( XML_NAMESPACE_STYLE, u"language-asian", 0);
1224 nIndexCountry = xMapper->GetEntryIndex( XML_NAMESPACE_STYLE, u"country-asian", 0);
1225 nIndexScript = xMapper->GetEntryIndex( XML_NAMESPACE_STYLE, u"script-asian", 0);
1226 nIndexTag = xMapper->GetEntryIndex( XML_NAMESPACE_STYLE, u"rfc-language-tag-asian", 0);
1227 break;
1229 nIndexLanguage = xMapper->GetEntryIndex( XML_NAMESPACE_STYLE, u"language-complex", 0);
1230 nIndexCountry = xMapper->GetEntryIndex( XML_NAMESPACE_STYLE, u"country-complex", 0);
1231 nIndexScript = xMapper->GetEntryIndex( XML_NAMESPACE_STYLE, u"script-complex", 0);
1232 nIndexTag = xMapper->GetEntryIndex( XML_NAMESPACE_STYLE, u"rfc-language-tag-complex", 0);
1233 break;
1234 default:
1235 nIndexLanguage = nIndexCountry = nIndexScript = nIndexTag = -1;
1236 }
1237 assert( nIndexLanguage >= 0 && nIndexCountry >= 0 && nIndexScript >= 0 && nIndexTag >= 0);
1238 rPropStates.emplace_back( nIndexLanguage, aAny);
1239 rPropStates.emplace_back( nIndexCountry, aAny);
1240 rPropStates.emplace_back( nIndexScript, aAny);
1241 rPropStates.emplace_back( nIndexTag, aAny);
1242 }
1243 break;
1244 default:
1245 continue;
1246 }
1247 }
1248
1249 return pField;
1250}
1251
1252}
1253
1255{
1256 if (!ValidTab(nTable))
1257 return;
1258
1259 rtl::Reference<XMLPropertySetMapper> xMapper = GetTextParagraphExport()->GetTextPropMapper()->getPropertySetMapper();
1261 const ScXMLEditAttributeMap& rAttrMap = GetEditAttributeMap();
1262
1263 sc::EditTextIterator aIter(*pDoc, nTable);
1264 sal_Int32 nCellCount = 0;
1265 for (const EditTextObject* pEdit = aIter.first(); pEdit; pEdit = aIter.next(), ++nCellCount)
1266 {
1267 std::vector<editeng::Section> aAttrs;
1268 pEdit->GetAllSections(aAttrs);
1269 if (aAttrs.empty())
1270 continue;
1271
1272 for (const auto& rSec : aAttrs)
1273 {
1274 const std::vector<const SfxPoolItem*>& rSecAttrs = rSec.maAttributes;
1275 if (rSecAttrs.empty())
1276 // No formats applied to this section. Skip it.
1277 continue;
1278
1279 std::vector<XMLPropertyState> aPropStates;
1280 toXMLPropertyStates(*this, aPropStates, rSecAttrs, xMapper, rAttrMap);
1281 if (!aPropStates.empty())
1282 xStylePool->Add(XmlStyleFamily::TEXT_TEXT, OUString(), std::move(aPropStates));
1283 }
1284 }
1285
1286 GetProgressBarHelper()->ChangeReference(GetProgressBarHelper()->GetReference() + nCellCount);
1287}
1288
1290{
1291 ScMyRowFormatRange aRange;
1292 sal_Int32 nIndex(-1);
1293#if OSL_DEBUG_LEVEL > 0
1294 sal_Int32 nPrevCol(0);
1295#endif
1296 sal_Int32 nCols(0);
1297 sal_Int32 nPrevValidationIndex(-1);
1298 bool bIsAutoStyle(true);
1299 bool bIsFirst(true);
1300 while (pRowFormatRanges->GetNext(aRange))
1301 {
1302#if OSL_DEBUG_LEVEL > 0
1303 OSL_ENSURE(bIsFirst || (!bIsFirst && (nPrevCol + nCols == aRange.nStartColumn)), "here are some columns missing");
1304#endif
1305 if (bIsFirst)
1306 {
1307 nIndex = aRange.nIndex;
1308 nPrevValidationIndex = aRange.nValidationIndex;
1309 bIsAutoStyle = aRange.bIsAutoStyle;
1310 nCols = aRange.nRepeatColumns;
1311 bIsFirst = false;
1312#if OSL_DEBUG_LEVEL > 0
1313 nPrevCol = aRange.nStartColumn;
1314#endif
1315 }
1316 else
1317 {
1318 if (((aRange.nIndex == nIndex && aRange.bIsAutoStyle == bIsAutoStyle) ||
1319 (aRange.nIndex == nIndex && nIndex == -1)) &&
1320 nPrevValidationIndex == aRange.nValidationIndex)
1321 nCols += aRange.nRepeatColumns;
1322 else
1323 {
1324 if (nIndex != -1)
1325 AddAttribute(sAttrStyleName, pCellStyles->GetStyleNameByIndex(nIndex, bIsAutoStyle));
1326 if (nPrevValidationIndex > -1)
1327 AddAttribute(XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATION_NAME, pValidationsContainer->GetValidationName(nPrevValidationIndex));
1328 if (nCols > 1)
1329 {
1330 AddAttribute(sAttrColumnsRepeated, OUString::number(nCols));
1331 }
1332 SvXMLElementExport aElemC(*this, sElemCell, true, true);
1333 nIndex = aRange.nIndex;
1334 bIsAutoStyle = aRange.bIsAutoStyle;
1335 nCols = aRange.nRepeatColumns;
1336 nPrevValidationIndex = aRange.nValidationIndex;
1337#if OSL_DEBUG_LEVEL > 0
1338 nPrevCol = aRange.nStartColumn;
1339#endif
1340 }
1341 }
1342 }
1343 if (!bIsFirst)
1344 {
1345 if (nIndex != -1)
1346 AddAttribute(sAttrStyleName, pCellStyles->GetStyleNameByIndex(nIndex, bIsAutoStyle));
1347 if (nPrevValidationIndex > -1)
1348 AddAttribute(XML_NAMESPACE_TABLE, XML_CONTENT_VALIDATION_NAME, pValidationsContainer->GetValidationName(nPrevValidationIndex));
1349 if (nCols > 1)
1350 {
1351 AddAttribute(sAttrColumnsRepeated, OUString::number(nCols));
1352 }
1353 SvXMLElementExport aElemC(*this, sElemCell, true, true);
1354 }
1355}
1356
1358 const sal_Int32 nIndex, const sal_Int32 nEqualRows,
1359 bool bHidden, bool bFiltered)
1360{
1361 // tdf#143940
1362 if (nIndex != -1)
1363 AddAttribute(sAttrStyleName, pRowStyles->GetStyleNameByIndex(nIndex));
1364 if (bHidden)
1365 {
1366 if (bFiltered)
1368 else
1370 }
1371 if (nEqualRows > 1)
1372 {
1373 AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_ROWS_REPEATED, OUString::number(nEqualRows));
1374 }
1375
1376 StartElement( sElemRow, true);
1377}
1378
1380{
1382 bRowHeaderOpen = true;
1383}
1384
1386{
1388}
1389
1391 const sal_Int32 nIndex, const sal_Int32 nStartRow, const sal_Int32 nEqualRows,
1392 bool bHidden, bool bFiltered)
1393{
1394 nOpenRow = nStartRow;
1395 if (pGroupRows->IsGroupStart(nStartRow))
1396 {
1399 pGroupRows->OpenGroups(nStartRow);
1402 }
1403 if (bHasRowHeader && !bRowHeaderOpen && nStartRow >= aRowHeaderRange.aStart.Row() && nStartRow <= aRowHeaderRange.aEnd.Row())
1404 {
1405 if (nStartRow == aRowHeaderRange.aStart.Row())
1407 sal_Int32 nEquals;
1408 if (aRowHeaderRange.aEnd.Row() < nStartRow + nEqualRows - 1)
1409 nEquals = aRowHeaderRange.aEnd.Row() - nStartRow + 1;
1410 else
1411 nEquals = nEqualRows;
1412 WriteRowStartTag(nIndex, nEquals, bHidden, bFiltered);
1413 nOpenRow = nStartRow + nEquals - 1;
1414 if (nEquals < nEqualRows)
1415 {
1416 CloseRow(nStartRow + nEquals - 1);
1417 WriteRowStartTag(nIndex, nEqualRows - nEquals, bHidden, bFiltered);
1418 nOpenRow = nStartRow + nEqualRows - 1;
1419 }
1420 }
1421 else
1422 WriteRowStartTag(nIndex, nEqualRows, bHidden, bFiltered);
1423}
1424
1426 const sal_Int32 nIndex, const sal_Int32 nStartRow, const sal_Int32 nEqualRows,
1427 bool bHidden, bool bFiltered)
1428{
1429 OpenNewRow(nIndex, nStartRow, nEqualRows, bHidden, bFiltered);
1431 CloseRow(nStartRow + nEqualRows - 1);
1432 pRowFormatRanges->Clear();
1433}
1434
1435void ScXMLExport::OpenRow(const sal_Int32 nTable, const sal_Int32 nStartRow, const sal_Int32 nRepeatRow, ScXMLCachedRowAttrAccess& rRowAttr)
1436{
1437 if (nRepeatRow > 1)
1438 {
1439 sal_Int32 nPrevIndex(0), nIndex;
1440 bool bPrevHidden = false;
1441 bool bPrevFiltered = false;
1442 bool bHidden = false;
1443 bool bFiltered = false;
1444 sal_Int32 nEqualRows(1);
1445 sal_Int32 nEndRow(nStartRow + nRepeatRow);
1446 sal_Int32 nEndRowHidden = nStartRow - 1;
1447 sal_Int32 nEndRowFiltered = nStartRow - 1;
1448 sal_Int32 nRow;
1449 for (nRow = nStartRow; nRow < nEndRow; ++nRow)
1450 {
1451 if (nRow == nStartRow)
1452 {
1453 nPrevIndex = pRowStyles->GetStyleNameIndex(nTable, nRow);
1454 if (pDoc)
1455 {
1456 if (nRow > nEndRowHidden)
1457 {
1458 bPrevHidden = rRowAttr.rowHidden(nTable, nRow, nEndRowHidden);
1459 bHidden = bPrevHidden;
1460 }
1461 if (nRow > nEndRowFiltered)
1462 {
1463 bPrevFiltered = rRowAttr.rowFiltered(nTable, nRow, nEndRowFiltered);
1464 bFiltered = bPrevFiltered;
1465 }
1466 }
1467
1468 }
1469 else
1470 {
1471 nIndex = pRowStyles->GetStyleNameIndex(nTable, nRow);
1472 if (pDoc)
1473 {
1474 if (nRow > nEndRowHidden)
1475 bHidden = rRowAttr.rowHidden(nTable, nRow, nEndRowHidden);
1476 if (nRow > nEndRowFiltered)
1477 bFiltered = rRowAttr.rowFiltered(nTable, nRow, nEndRowFiltered);
1478 }
1479 if (nIndex == nPrevIndex && bHidden == bPrevHidden && bFiltered == bPrevFiltered &&
1480 !(bHasRowHeader && ((nRow == aRowHeaderRange.aStart.Row()) || (nRow - 1 == aRowHeaderRange.aEnd.Row()))) &&
1481 !(pGroupRows->IsGroupStart(nRow)) &&
1482 !(pGroupRows->IsGroupEnd(nRow - 1)))
1483 ++nEqualRows;
1484 else
1485 {
1486 assert(nPrevIndex >= 0 && "coverity#1438402");
1487 ScRowFormatRanges* pTempRowFormatRanges = new ScRowFormatRanges(pRowFormatRanges.get());
1488 OpenAndCloseRow(nPrevIndex, nRow - nEqualRows, nEqualRows, bPrevHidden, bPrevFiltered);
1489 pRowFormatRanges.reset(pTempRowFormatRanges);
1490 nEqualRows = 1;
1491 nPrevIndex = nIndex;
1492 bPrevHidden = bHidden;
1493 bPrevFiltered = bFiltered;
1494 }
1495 }
1496 }
1497 assert(nPrevIndex >= 0 && "coverity#1438402");
1498 OpenNewRow(nPrevIndex, nRow - nEqualRows, nEqualRows, bPrevHidden, bPrevFiltered);
1499 }
1500 else
1501 {
1502 sal_Int32 nIndex = pRowStyles->GetStyleNameIndex(nTable, nStartRow);
1503 bool bHidden = false;
1504 bool bFiltered = false;
1505 if (pDoc)
1506 {
1507 sal_Int32 nEndRowHidden;
1508 sal_Int32 nEndRowFiltered;
1509 bHidden = rRowAttr.rowHidden(nTable, nStartRow, nEndRowHidden);
1510 bFiltered = rRowAttr.rowFiltered(nTable, nStartRow, nEndRowFiltered);
1511 }
1512 assert(nIndex >= 0 && "coverity#1438402");
1513 OpenNewRow(nIndex, nStartRow, 1, bHidden, bFiltered);
1514 }
1515 nOpenRow = nStartRow + nRepeatRow - 1;
1516}
1517
1518void ScXMLExport::CloseRow(const sal_Int32 nRow)
1519{
1520 if (nOpenRow > -1)
1521 {
1522 EndElement(sElemRow, true);
1523 if (bHasRowHeader && nRow == aRowHeaderRange.aEnd.Row())
1524 {
1526 bRowHeaderOpen = false;
1527 }
1528 if (pGroupRows->IsGroupEnd(nRow))
1529 {
1532 pGroupRows->CloseGroups(nRow);
1535 }
1536 }
1537 nOpenRow = -1;
1538}
1539
1540void ScXMLExport::ExportFormatRanges(const sal_Int32 nStartCol, const sal_Int32 nStartRow,
1541 const sal_Int32 nEndCol, const sal_Int32 nEndRow, const sal_Int32 nSheet)
1542{
1543 pRowFormatRanges->Clear();
1545 if (nStartRow == nEndRow)
1546 {
1547 pCellStyles->GetFormatRanges(nStartCol, nEndCol, nStartRow, nSheet, pRowFormatRanges.get());
1548 if (nOpenRow == - 1)
1549 OpenRow(nSheet, nStartRow, 1, aRowAttr);
1551 pRowFormatRanges->Clear();
1552 }
1553 else
1554 {
1555 if (nOpenRow > -1)
1556 {
1557 pCellStyles->GetFormatRanges(nStartCol, pSharedData->GetLastColumn(nSheet), nStartRow, nSheet, pRowFormatRanges.get());
1559 CloseRow(nStartRow);
1560 sal_Int32 nRows(1);
1561 sal_Int32 nTotalRows(nEndRow - nStartRow + 1 - 1);
1562 while (nRows < nTotalRows)
1563 {
1564 pRowFormatRanges->Clear();
1565 pCellStyles->GetFormatRanges(0, pSharedData->GetLastColumn(nSheet), nStartRow + nRows, nSheet, pRowFormatRanges.get());
1566 sal_Int32 nMaxRows = pRowFormatRanges->GetMaxRows();
1567 OSL_ENSURE(nMaxRows, "something went wrong");
1568 if (nMaxRows >= nTotalRows - nRows)
1569 {
1570 OpenRow(nSheet, nStartRow + nRows, nTotalRows - nRows, aRowAttr);
1571 nRows += nTotalRows - nRows;
1572 }
1573 else
1574 {
1575 OpenRow(nSheet, nStartRow + nRows, nMaxRows, aRowAttr);
1576 nRows += nMaxRows;
1577 }
1578 if (!pRowFormatRanges->GetSize())
1579 pCellStyles->GetFormatRanges(0, pSharedData->GetLastColumn(nSheet), nStartRow + nRows, nSheet, pRowFormatRanges.get());
1581 CloseRow(nStartRow + nRows - 1);
1582 }
1583 if (nTotalRows == 1)
1584 CloseRow(nStartRow);
1585 OpenRow(nSheet, nEndRow, 1, aRowAttr);
1586 pRowFormatRanges->Clear();
1587 pCellStyles->GetFormatRanges(0, nEndCol, nEndRow, nSheet, pRowFormatRanges.get());
1589 }
1590 else
1591 {
1592 sal_Int32 nRows(0);
1593 sal_Int32 nTotalRows(nEndRow - nStartRow + 1 - 1);
1594 while (nRows < nTotalRows)
1595 {
1596 pCellStyles->GetFormatRanges(0, pSharedData->GetLastColumn(nSheet), nStartRow + nRows, nSheet, pRowFormatRanges.get());
1597 sal_Int32 nMaxRows = pRowFormatRanges->GetMaxRows();
1598 OSL_ENSURE(nMaxRows, "something went wrong");
1599 if (nMaxRows >= nTotalRows - nRows)
1600 {
1601 OpenRow(nSheet, nStartRow + nRows, nTotalRows - nRows, aRowAttr);
1602 nRows += nTotalRows - nRows;
1603 }
1604 else
1605 {
1606 OpenRow(nSheet, nStartRow + nRows, nMaxRows, aRowAttr);
1607 nRows += nMaxRows;
1608 }
1609 if (!pRowFormatRanges->GetSize())
1610 pCellStyles->GetFormatRanges(0, pSharedData->GetLastColumn(nSheet), nStartRow + nRows, nSheet, pRowFormatRanges.get());
1612 CloseRow(nStartRow + nRows - 1);
1613 }
1614 OpenRow(nSheet, nEndRow, 1, aRowAttr);
1615 pRowFormatRanges->Clear();
1616 pCellStyles->GetFormatRanges(0, nEndCol, nEndRow, nSheet, pRowFormatRanges.get());
1618 }
1619 }
1620}
1621
1622void ScXMLExport::GetColumnRowHeader(bool& rHasColumnHeader, ScRange& rColumnHeaderRange,
1623 bool& rHasRowHeader, ScRange& rRowHeaderRange,
1624 OUString& rPrintRanges) const
1625{
1626 uno::Reference <sheet::XPrintAreas> xPrintAreas (xCurrentTable, uno::UNO_QUERY);
1627 if (!xPrintAreas.is())
1628 return;
1629
1630 rHasRowHeader = xPrintAreas->getPrintTitleRows();
1631 rHasColumnHeader = xPrintAreas->getPrintTitleColumns();
1632 table::CellRangeAddress rTempRowHeaderRange = xPrintAreas->getTitleRows();
1633 rRowHeaderRange = ScRange(rTempRowHeaderRange.StartColumn,
1634 rTempRowHeaderRange.StartRow,
1635 rTempRowHeaderRange.Sheet,
1636 rTempRowHeaderRange.EndColumn,
1637 rTempRowHeaderRange.EndRow,
1638 rTempRowHeaderRange.Sheet);
1639 table::CellRangeAddress rTempColumnHeaderRange = xPrintAreas->getTitleColumns();
1640 rColumnHeaderRange = ScRange(rTempColumnHeaderRange.StartColumn,
1641 rTempColumnHeaderRange.StartRow,
1642 rTempColumnHeaderRange.Sheet,
1643 rTempColumnHeaderRange.EndColumn,
1644 rTempColumnHeaderRange.EndRow,
1645 rTempColumnHeaderRange.Sheet);
1646 uno::Sequence< table::CellRangeAddress > aRangeList( xPrintAreas->getPrintAreas() );
1647 ScRangeStringConverter::GetStringFromRangeList( rPrintRanges, aRangeList, pDoc, FormulaGrammar::CONV_OOO );
1648}
1649
1651{
1652 size_t nDepth = pFields->GetDepth();
1653 for (size_t i = 0; i < nDepth; ++i)
1654 {
1655 size_t nFields = pFields->GetCount(i);
1656 for (size_t j = 0; j < nFields; ++j)
1657 {
1658 ScMyColumnRowGroup aGroup;
1659 const ScOutlineEntry* pEntry = pFields->GetEntry(i, j);
1660 aGroup.nField = pEntry->GetStart();
1661 aGroup.nLevel = static_cast<sal_Int16>(i);
1662 aGroup.bDisplay = !(pEntry->IsHidden());
1663 pGroups->AddGroup(aGroup, pEntry->GetEnd());
1664 }
1665 }
1666 if (nDepth)
1667 pGroups->Sort();
1668}
1669
1671{
1672 if (!pDoc)
1673 return;
1674
1675 ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable( static_cast<SCTAB>(nCurrentTable) );
1676 if(pOutlineTable)
1677 {
1678 ScOutlineArray& rCols(pOutlineTable->GetColArray());
1679 ScOutlineArray& rRows(pOutlineTable->GetRowArray());
1680 FillFieldGroup(&rCols, pGroupColumns.get());
1681 FillFieldGroup(&rRows, pGroupRows.get());
1682 pSharedData->SetLastColumn(nCurrentTable, pGroupColumns->GetLast());
1683 pSharedData->SetLastRow(nCurrentTable, pGroupRows->GetLast());
1684 }
1685}
1686
1688{
1689 if (!(pDoc && pDoc->IsDocProtected()))
1690 return;
1691
1693 OUStringBuffer aBuffer;
1694 uno::Sequence<sal_Int8> aPassHash;
1697 if (p)
1698 {
1699 if (p->hasPasswordHash(PASSHASH_SHA1))
1700 {
1701 aPassHash = p->getPasswordHash(PASSHASH_SHA1);
1702 eHashUsed = PASSHASH_SHA1;
1703 }
1704 else if (p->hasPasswordHash(PASSHASH_SHA256))
1705 {
1706 aPassHash = p->getPasswordHash(PASSHASH_SHA256);
1707 eHashUsed = PASSHASH_SHA256;
1708 }
1709 else if (p->hasPasswordHash(PASSHASH_XL, PASSHASH_SHA1))
1710 {
1711 aPassHash = p->getPasswordHash(PASSHASH_XL, PASSHASH_SHA1);
1712 eHashUsed = PASSHASH_XL;
1713 }
1714 }
1716 if (aBuffer.isEmpty())
1717 return;
1718
1721 return;
1722
1723 if (eHashUsed == PASSHASH_XL)
1724 {
1730 }
1731 else if (eHashUsed == PASSHASH_SHA1)
1732 {
1735 }
1736 else if (eHashUsed == PASSHASH_SHA256)
1737 {
1740 }
1741}
1742
1743static bool lcl_CopyStreamElement( const uno::Reference< io::XInputStream >& xInput,
1744 const uno::Reference< io::XOutputStream >& xOutput,
1745 sal_Int32 nCount )
1746{
1747 const sal_Int32 nBufSize = 16*1024;
1748 uno::Sequence<sal_Int8> aSequence(nBufSize);
1749
1750 sal_Int32 nRemaining = nCount;
1751 bool bFirst = true;
1752
1753 while ( nRemaining > 0 )
1754 {
1755 sal_Int32 nRead = xInput->readBytes( aSequence, std::min( nRemaining, nBufSize ) );
1756 if (bFirst)
1757 {
1758 // safety check: Make sure the copied part actually points to the start of an element
1759 if ( nRead < 1 || aSequence[0] != static_cast<sal_Int8>('<') )
1760 {
1761 return false; // abort and set an error
1762 }
1763 bFirst = false;
1764 }
1765 if (nRead == nRemaining)
1766 {
1767 // safety check: Make sure the copied part also ends at the end of an element
1768 if ( aSequence[nRead-1] != static_cast<sal_Int8>('>') )
1769 {
1770 return false; // abort and set an error
1771 }
1772 }
1773
1774 if ( nRead == nBufSize )
1775 {
1776 xOutput->writeBytes( aSequence );
1777 nRemaining -= nRead;
1778 }
1779 else
1780 {
1781 if ( nRead > 0 )
1782 {
1783 uno::Sequence<sal_Int8> aTempBuf( aSequence.getConstArray(), nRead );
1784 xOutput->writeBytes( aTempBuf );
1785 }
1786 nRemaining = 0;
1787 }
1788 }
1789 return true; // successful
1790}
1791
1792static void lcl_SkipBytesInBlocks( const uno::Reference< io::XInputStream >& xInput, sal_Int32 nBytesToSkip )
1793{
1794 // skipBytes in zip stream is implemented as reading.
1795 // For now, split into several calls to avoid allocating a large buffer.
1796 // Later, skipBytes should be changed.
1797
1798 const sal_Int32 nMaxSize = 32*1024;
1799
1800 if ( nBytesToSkip > 0 )
1801 {
1802 sal_Int32 nRemaining = nBytesToSkip;
1803 while ( nRemaining > 0 )
1804 {
1805 sal_Int32 nSkip = std::min( nRemaining, nMaxSize );
1806 xInput->skipBytes( nSkip );
1807 nRemaining -= nSkip;
1808 }
1809 }
1810}
1811
1812void ScXMLExport::CopySourceStream( sal_Int32 nStartOffset, sal_Int32 nEndOffset, sal_Int32& rNewStart, sal_Int32& rNewEnd )
1813{
1814 uno::Reference<xml::sax::XDocumentHandler> xHandler = GetDocHandler();
1815 uno::Reference<io::XActiveDataSource> xDestSource( xHandler, uno::UNO_QUERY );
1816 if ( !xDestSource.is() )
1817 return;
1818
1819 uno::Reference<io::XOutputStream> xDestStream = xDestSource->getOutputStream();
1820 uno::Reference<io::XSeekable> xDestSeek( xDestStream, uno::UNO_QUERY );
1821 if ( !xDestSeek.is() )
1822 return;
1823
1824 // temporary: set same stream again to clear buffer
1825 xDestSource->setOutputStream( xDestStream );
1826
1827 if ( getExportFlags() & SvXMLExportFlags::PRETTY )
1828 {
1829 static constexpr OStringLiteral aOutStr("\n ");
1830 uno::Sequence<sal_Int8> aOutSeq( reinterpret_cast<sal_Int8 const *>(aOutStr.getStr()), aOutStr.getLength() );
1831 xDestStream->writeBytes( aOutSeq );
1832 }
1833
1834 rNewStart = static_cast<sal_Int32>(xDestSeek->getPosition());
1835
1836 if ( nStartOffset > nSourceStreamPos )
1838
1839 if ( !lcl_CopyStreamElement( xSourceStream, xDestStream, nEndOffset - nStartOffset ) )
1840 {
1841 // If copying went wrong, set an error.
1842 // ScXMLImportWrapper then resets all stream flags, so the next save attempt will use normal saving.
1843
1844 uno::Sequence<OUString> aEmptySeq;
1846 }
1847 nSourceStreamPos = nEndOffset;
1848
1849 rNewEnd = static_cast<sal_Int32>(xDestSeek->getPosition());
1850}
1851
1853{
1854 if (!mpEditAttrMap)
1856 return *mpEditAttrMap;
1857}
1858
1859void ScXMLExport::RegisterDefinedStyleNames( const uno::Reference< css::sheet::XSpreadsheetDocument > & xSpreadDoc )
1860{
1861 ScFormatSaveData* pFormatData = comphelper::getFromUnoTunnel<ScModelObj>(xSpreadDoc)->GetFormatSaveData();
1862 auto xAutoStylePool = GetAutoStylePool();
1863 for (const auto& rFormatInfo : pFormatData->maIDToName)
1864 {
1865 xAutoStylePool->RegisterDefinedName(XmlStyleFamily::TABLE_CELL, rFormatInfo.second);
1866 }
1867}
1868
1870{
1871 nCurrentTable = 0;
1872 if (!pSharedData)
1873 {
1874 SCTAB nTableCount(0);
1875 sal_Int32 nShapesCount(0);
1876 CollectSharedData(nTableCount, nShapesCount);
1877 OSL_FAIL("no shared data set");
1878 if (!pSharedData)
1879 return;
1880 }
1881 ScXMLExportDatabaseRanges aExportDatabaseRanges(*this);
1882 if (!GetModel().is())
1883 return;
1884
1885 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( GetModel(), uno::UNO_QUERY );
1886 if ( !xSpreadDoc.is() )
1887 return;
1888
1889 ScSheetSaveData* pSheetData = comphelper::getFromUnoTunnel<ScModelObj>(xSpreadDoc)->GetSheetSaveData();
1890 if (pSheetData)
1891 pSheetData->ResetSaveEntries();
1892
1893 uno::Reference<container::XIndexAccess> xIndex( xSpreadDoc->getSheets(), uno::UNO_QUERY );
1894 if ( xIndex.is() )
1895 {
1896 //_GetNamespaceMap().ClearQNamesCache();
1897 pChangeTrackingExportHelper->CollectAndWriteChanges();
1898 WriteCalculationSettings(xSpreadDoc);
1899 sal_Int32 nTableCount(xIndex->getCount());
1900 ScMyAreaLinksContainer aAreaLinks;
1901 GetAreaLinks( aAreaLinks );
1902 ScMyEmptyDatabaseRangesContainer aEmptyRanges(aExportDatabaseRanges.GetEmptyDatabaseRanges());
1903 ScMyDetectiveOpContainer aDetectiveOpContainer;
1904 GetDetectiveOpList( aDetectiveOpContainer );
1905
1906 pCellStyles->Sort();
1907 pMergedRangesContainer->Sort();
1908 pSharedData->GetDetectiveObjContainer()->Sort();
1909
1910 mpCellsItr->Clear();
1911 mpCellsItr->SetShapes( pSharedData->GetShapesContainer() );
1912 mpCellsItr->SetNoteShapes( pSharedData->GetNoteShapes() );
1913 mpCellsItr->SetMergedRanges( pMergedRangesContainer.get() );
1914 mpCellsItr->SetAreaLinks( &aAreaLinks );
1915 mpCellsItr->SetEmptyDatabaseRanges( &aEmptyRanges );
1916 mpCellsItr->SetDetectiveObj( pSharedData->GetDetectiveObjContainer() );
1917 mpCellsItr->SetDetectiveOp( &aDetectiveOpContainer );
1918
1919 if (nTableCount > 0)
1920 pValidationsContainer->WriteValidations(*this);
1921 WriteTheLabelRanges( xSpreadDoc );
1922 for (sal_Int32 nTable = 0; nTable < nTableCount; ++nTable)
1923 {
1924 sal_Int32 nStartOffset = -1;
1925 sal_Int32 nEndOffset = -1;
1926 if (pSheetData && pDoc && pDoc->IsStreamValid(static_cast<SCTAB>(nTable)) && !pDoc->GetChangeTrack())
1927 pSheetData->GetStreamPos( nTable, nStartOffset, nEndOffset );
1928
1929 if ( nStartOffset >= 0 && nEndOffset >= 0 && xSourceStream.is() )
1930 {
1931 sal_Int32 nNewStart = -1;
1932 sal_Int32 nNewEnd = -1;
1933 CopySourceStream( nStartOffset, nEndOffset, nNewStart, nNewEnd );
1934
1935 // store position of copied sheet in output
1936 pSheetData->AddSavePos( nTable, nNewStart, nNewEnd );
1937
1938 // skip iterator entries for this sheet
1939 mpCellsItr->SkipTable(static_cast<SCTAB>(nTable));
1940 }
1941 else
1942 {
1943 uno::Reference<sheet::XSpreadsheet> xTable(xIndex->getByIndex(nTable), uno::UNO_QUERY);
1944 WriteTable(nTable, xTable);
1945 }
1946 IncrementProgressBar(false);
1947 }
1948 }
1952 aExportDatabaseRanges.WriteDatabaseRanges();
1954 ScXMLExportDataPilot aExportDataPilot(*this);
1955 aExportDataPilot.WriteDataPilots();
1957 ScXMLExportDDELinks aExportDDELinks(*this);
1958 aExportDDELinks.WriteDDELinks(xSpreadDoc);
1959 IncrementProgressBar(true, 0);
1961}
1962
1964{
1965 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( GetModel(), uno::UNO_QUERY );
1966 if (xSpreadDoc.is())
1967 RegisterDefinedStyleNames( xSpreadDoc);
1968
1969 if (!pSharedData)
1970 {
1971 SCTAB nTableCount(0);
1972 sal_Int32 nShapesCount(0);
1973 CollectSharedData(nTableCount, nShapesCount);
1974 }
1976 if (GetModel().is())
1977 {
1978 uno::Reference <lang::XMultiServiceFactory> xMultiServiceFactory(GetModel(), uno::UNO_QUERY);
1979 if (xMultiServiceFactory.is())
1980 {
1981 uno::Reference <beans::XPropertySet> xProperties(xMultiServiceFactory->createInstance("com.sun.star.sheet.Defaults"), uno::UNO_QUERY);
1982 if (xProperties.is())
1983 aStylesExp->exportDefaultStyle(xProperties, XML_STYLE_FAMILY_TABLE_CELL_STYLES_NAME, xCellStylesExportPropertySetMapper);
1984 GetShapeExport()->ExportGraphicDefaults();
1985 }
1986 collectDataStyles(false);
1987 }
1989
1990 aStylesExp->exportStyleFamily("CellStyles",
1992
1994}
1995
1996void ScXMLExport::AddStyleFromCells(const uno::Reference<beans::XPropertySet>& xProperties,
1997 const uno::Reference<sheet::XSpreadsheet>& xTable,
1998 sal_Int32 nTable, const OUString* pOldName)
1999{
2000 css::uno::Any aAny = xProperties->getPropertyValue("FormatID");
2001 sal_uInt64 nKey = 0;
2002 aAny >>= nKey;
2003
2005 uno::Reference<sheet::XSheetCellRanges> xCellRanges( xProperties, uno::UNO_QUERY );
2006
2007 OUString sStyleName;
2008 sal_Int32 nNumberFormat(-1);
2009 sal_Int32 nValidationIndex(-1);
2010 std::vector<XMLPropertyState> aPropStates(xCellStylesExportPropertySetMapper->Filter(*this, xProperties));
2011 std::vector< XMLPropertyState >::iterator aItr(aPropStates.begin());
2012 std::vector< XMLPropertyState >::iterator aEndItr(aPropStates.end());
2013 sal_Int32 nCount(0);
2014 while (aItr != aEndItr)
2015 {
2016 if (aItr->mnIndex != -1)
2017 {
2018 switch (xCellStylesPropertySetMapper->GetEntryContextId(aItr->mnIndex))
2019 {
2020 case CTF_SC_VALIDATION :
2021 {
2022 pValidationsContainer->AddValidation(aItr->maValue, nValidationIndex);
2023 // this is not very slow, because it is most the last property or
2024 // if it is not the last property it is the property before the last property,
2025 // so in the worst case only one property has to be copied, but in the best case no
2026 // property has to be copied
2027 aItr = aPropStates.erase(aItr);
2028 aEndItr = aPropStates.end(); // old aEndItr is invalidated!
2029 }
2030 break;
2031 case CTF_SC_CELLSTYLE :
2032 {
2033 aItr->maValue >>= sStyleName;
2034 aItr->mnIndex = -1;
2035 ++aItr;
2036 ++nCount;
2037 }
2038 break;
2039 case CTF_SC_NUMBERFORMAT :
2040 {
2041 if (aItr->maValue >>= nNumberFormat)
2042 addDataStyle(nNumberFormat);
2043 ++aItr;
2044 ++nCount;
2045 }
2046 break;
2047 default:
2048 {
2049 ++aItr;
2050 ++nCount;
2051 }
2052 break;
2053 }
2054 }
2055 else
2056 {
2057 ++aItr;
2058 ++nCount;
2059 }
2060 }
2061 if (nCount == 1) // this is the CellStyle and should be removed if alone
2062 aPropStates.clear();
2063 if (nNumberFormat == -1)
2064 xProperties->getPropertyValue(SC_UNONAME_NUMFMT) >>= nNumberFormat;
2065 if (sStyleName.isEmpty())
2066 return;
2067
2068 if (!aPropStates.empty())
2069 {
2070 sal_Int32 nIndex;
2071 if (pOldName)
2072 {
2073 if (GetAutoStylePool()->AddNamed(*pOldName, XmlStyleFamily::TABLE_CELL, sStyleName, std::move(aPropStates)))
2074 {
2075 GetAutoStylePool()->RegisterName(XmlStyleFamily::TABLE_CELL, *pOldName);
2076 // add to pCellStyles, so the name is found for normal sheets
2077 pCellStyles->AddStyleName(*pOldName, nIndex);
2078 }
2079 }
2080 else
2081 {
2082 OUString sName;
2083 bool bAdded = false;
2084 if (nKey)
2085 {
2086 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( GetModel(), uno::UNO_QUERY );
2087 ScFormatSaveData* pFormatData = comphelper::getFromUnoTunnel<ScModelObj>(xSpreadDoc)->GetFormatSaveData();
2088 auto itr = pFormatData->maIDToName.find(nKey);
2089 if (itr != pFormatData->maIDToName.end())
2090 {
2091 sName = itr->second;
2092 bAdded = GetAutoStylePool()->AddNamed(sName, XmlStyleFamily::TABLE_CELL, sStyleName, aPropStates);
2093 if (bAdded)
2094 GetAutoStylePool()->RegisterName(XmlStyleFamily::TABLE_CELL, sName);
2095 }
2096 }
2097 bool bIsAutoStyle(true);
2098 if (bAdded || GetAutoStylePool()->Add(sName, XmlStyleFamily::TABLE_CELL, sStyleName, std::move(aPropStates)))
2099 {
2100 pCellStyles->AddStyleName(sName, nIndex);
2101 }
2102 else
2103 nIndex = pCellStyles->GetIndexOfStyleName(sName, XML_STYLE_FAMILY_TABLE_CELL_STYLES_PREFIX, bIsAutoStyle);
2104
2105 const uno::Sequence<table::CellRangeAddress> aAddresses(xCellRanges->getRangeAddresses());
2106 bool bGetMerge(true);
2107 for (table::CellRangeAddress const & address : aAddresses)
2108 {
2109 pSharedData->SetLastColumn(nTable, address.EndColumn);
2110 pSharedData->SetLastRow(nTable, address.EndRow);
2111 pCellStyles->AddRangeStyleName(address, nIndex, bIsAutoStyle, nValidationIndex, nNumberFormat);
2112 if (bGetMerge)
2113 bGetMerge = GetMerged(&address, xTable);
2114 }
2115 }
2116 }
2117 else
2118 {
2119 OUString sEncodedStyleName(EncodeStyleName(sStyleName));
2120 sal_Int32 nIndex(0);
2121 pCellStyles->AddStyleName(sEncodedStyleName, nIndex, false);
2122 if ( !pOldName )
2123 {
2124 const uno::Sequence<table::CellRangeAddress> aAddresses(xCellRanges->getRangeAddresses());
2125 bool bGetMerge(true);
2126 for (table::CellRangeAddress const & address : aAddresses)
2127 {
2128 if (bGetMerge)
2129 bGetMerge = GetMerged(&address, xTable);
2130 pCellStyles->AddRangeStyleName(address, nIndex, false, nValidationIndex, nNumberFormat);
2131 if( sStyleName != "Default" || nValidationIndex != -1 )
2132 {
2133 pSharedData->SetLastColumn(nTable, address.EndColumn);
2134 pSharedData->SetLastRow(nTable, address.EndRow);
2135 }
2136 }
2137 }
2138 }
2139}
2140
2141void ScXMLExport::AddStyleFromColumn(const uno::Reference<beans::XPropertySet>& xColumnProperties,
2142 const OUString* pOldName, sal_Int32& rIndex, bool& rIsVisible)
2143{
2144 std::vector<XMLPropertyState> aPropStates(xColumnStylesExportPropertySetMapper->Filter(*this, xColumnProperties));
2145 if(aPropStates.empty())
2146 return;
2147
2148 auto aItr = std::find_if(aPropStates.begin(), aPropStates.end(),
2149 [this](const XMLPropertyState& rPropState) {
2150 return xColumnStylesPropertySetMapper->GetEntryContextId(rPropState.mnIndex) == CTF_SC_ISVISIBLE; });
2151 if (aItr != aPropStates.end())
2152 {
2153 aItr->maValue >>= rIsVisible;
2154 }
2155
2156 const OUString sParent;
2157 if (pOldName)
2158 {
2159 if (GetAutoStylePool()->AddNamed(*pOldName, XmlStyleFamily::TABLE_COLUMN, sParent, std::move(aPropStates)))
2160 {
2161 GetAutoStylePool()->RegisterName(XmlStyleFamily::TABLE_COLUMN, *pOldName);
2162 // add to pColumnStyles, so the name is found for normal sheets
2163 rIndex = pColumnStyles->AddStyleName(*pOldName);
2164 }
2165 }
2166 else
2167 {
2168 OUString sName;
2169 if (GetAutoStylePool()->Add(sName, XmlStyleFamily::TABLE_COLUMN, sParent, std::move(aPropStates)))
2170 {
2171 rIndex = pColumnStyles->AddStyleName(sName);
2172 }
2173 else
2174 rIndex = pColumnStyles->GetIndexOfStyleName(sName, XML_STYLE_FAMILY_TABLE_COLUMN_STYLES_PREFIX);
2175 }
2176}
2177
2178void ScXMLExport::AddStyleFromRow(const uno::Reference<beans::XPropertySet>& xRowProperties,
2179 const OUString* pOldName, sal_Int32& rIndex)
2180{
2181 std::vector<XMLPropertyState> aPropStates(xRowStylesExportPropertySetMapper->Filter(*this, xRowProperties));
2182 if(aPropStates.empty())
2183 return;
2184
2185 const OUString sParent;
2186 if (pOldName)
2187 {
2188 if (GetAutoStylePool()->AddNamed(*pOldName, XmlStyleFamily::TABLE_ROW, sParent, std::move(aPropStates)))
2189 {
2190 GetAutoStylePool()->RegisterName(XmlStyleFamily::TABLE_ROW, *pOldName);
2191 // add to pRowStyles, so the name is found for normal sheets
2192 rIndex = pRowStyles->AddStyleName(*pOldName);
2193 }
2194 }
2195 else
2196 {
2197 OUString sName;
2198 if (GetAutoStylePool()->Add(sName, XmlStyleFamily::TABLE_ROW, sParent, std::move(aPropStates)))
2199 {
2200 rIndex = pRowStyles->AddStyleName(sName);
2201 }
2202 else
2203 rIndex = pRowStyles->GetIndexOfStyleName(sName, XML_STYLE_FAMILY_TABLE_ROW_STYLES_PREFIX);
2204 }
2205}
2206
2207static uno::Any lcl_GetEnumerated( uno::Reference<container::XEnumerationAccess> const & xEnumAccess, sal_Int32 nIndex )
2208{
2209 uno::Any aRet;
2210 uno::Reference<container::XEnumeration> xEnum( xEnumAccess->createEnumeration() );
2211 try
2212 {
2213 sal_Int32 nSkip = nIndex;
2214 while ( nSkip > 0 )
2215 {
2216 (void) xEnum->nextElement();
2217 --nSkip;
2218 }
2219 aRet = xEnum->nextElement();
2220 }
2221 catch (container::NoSuchElementException&)
2222 {
2223 // leave aRet empty
2224 }
2225 return aRet;
2226}
2227
2229{
2231
2233 return;
2234
2235 if (!GetModel().is())
2236 return;
2237
2238 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( GetModel(), uno::UNO_QUERY );
2239 if (!xSpreadDoc.is())
2240 return;
2241
2242 uno::Reference<container::XIndexAccess> xIndex( xSpreadDoc->getSheets(), uno::UNO_QUERY );
2243 if (!xIndex.is())
2244 return;
2245
2246 if (getExportFlags() & SvXMLExportFlags::CONTENT)
2247 {
2248 // Reserve the loaded cell style names.
2249 RegisterDefinedStyleNames( xSpreadDoc);
2250
2251 // re-create automatic styles with old names from stored data
2252 ScSheetSaveData* pSheetData = comphelper::getFromUnoTunnel<ScModelObj>(xSpreadDoc)->GetSheetSaveData();
2253 if (pSheetData && pDoc)
2254 {
2255 // formulas have to be calculated now, to detect changed results
2256 // (during normal save, they will be calculated anyway)
2257 SCTAB nTabCount = pDoc->GetTableCount();
2258 for (SCTAB nTab=0; nTab<nTabCount; ++nTab)
2259 if (pDoc->IsStreamValid(nTab))
2260 pDoc->InterpretDirtyCells(ScRange(0, 0, nTab, pDoc->MaxCol(), pDoc->MaxRow(), nTab));
2261
2262 // stored cell styles
2263 const std::vector<ScCellStyleEntry>& rCellEntries = pSheetData->GetCellStyles();
2264 for (const auto& rCellEntry : rCellEntries)
2265 {
2266 ScAddress aPos = rCellEntry.maCellPos;
2267 sal_Int32 nTable = aPos.Tab();
2268 bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
2269 if (bCopySheet)
2270 {
2271 uno::Reference <sheet::XSpreadsheet> xTable(xIndex->getByIndex(nTable), uno::UNO_QUERY);
2272 uno::Reference <beans::XPropertySet> xProperties(
2273 xTable->getCellByPosition( aPos.Col(), aPos.Row() ), uno::UNO_QUERY );
2274
2275 AddStyleFromCells(xProperties, xTable, nTable, &rCellEntry.maName);
2276 }
2277 }
2278
2279 // stored column styles
2280 const std::vector<ScCellStyleEntry>& rColumnEntries = pSheetData->GetColumnStyles();
2281 for (const auto& rColumnEntry : rColumnEntries)
2282 {
2283 ScAddress aPos = rColumnEntry.maCellPos;
2284 sal_Int32 nTable = aPos.Tab();
2285 bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
2286 if (bCopySheet)
2287 {
2288 uno::Reference<table::XColumnRowRange> xColumnRowRange(xIndex->getByIndex(nTable), uno::UNO_QUERY);
2289 uno::Reference<table::XTableColumns> xTableColumns(xColumnRowRange->getColumns());
2290 uno::Reference<beans::XPropertySet> xColumnProperties(xTableColumns->getByIndex( aPos.Col() ), uno::UNO_QUERY);
2291
2292 sal_Int32 nIndex(-1);
2293 bool bIsVisible(true);
2294 AddStyleFromColumn( xColumnProperties, &rColumnEntry.maName, nIndex, bIsVisible );
2295 }
2296 }
2297
2298 // stored row styles
2299 const std::vector<ScCellStyleEntry>& rRowEntries = pSheetData->GetRowStyles();
2300 for (const auto& rRowEntry : rRowEntries)
2301 {
2302 ScAddress aPos = rRowEntry.maCellPos;
2303 sal_Int32 nTable = aPos.Tab();
2304 bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
2305 if (bCopySheet)
2306 {
2307 uno::Reference<table::XColumnRowRange> xColumnRowRange(xIndex->getByIndex(nTable), uno::UNO_QUERY);
2308 uno::Reference<table::XTableRows> xTableRows(xColumnRowRange->getRows());
2309 uno::Reference<beans::XPropertySet> xRowProperties(xTableRows->getByIndex( aPos.Row() ), uno::UNO_QUERY);
2310
2311 sal_Int32 nIndex(-1);
2312 AddStyleFromRow( xRowProperties, &rRowEntry.maName, nIndex );
2313 }
2314 }
2315
2316 // stored table styles
2317 const std::vector<ScCellStyleEntry>& rTableEntries = pSheetData->GetTableStyles();
2318 for (const auto& rTableEntry : rTableEntries)
2319 {
2320 ScAddress aPos = rTableEntry.maCellPos;
2321 sal_Int32 nTable = aPos.Tab();
2322 bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
2323 if (bCopySheet)
2324 {
2326 uno::Reference<beans::XPropertySet> xTableProperties(xIndex->getByIndex(nTable), uno::UNO_QUERY);
2327 if (xTableProperties.is())
2328 {
2329 std::vector<XMLPropertyState> aPropStates(xTableStylesExportPropertySetMapper->Filter(*this, xTableProperties));
2330 OUString sName( rTableEntry.maName );
2331 GetAutoStylePool()->AddNamed(sName, XmlStyleFamily::TABLE_TABLE, OUString(), std::move(aPropStates));
2332 GetAutoStylePool()->RegisterName(XmlStyleFamily::TABLE_TABLE, sName);
2333 }
2334 }
2335 }
2336
2337 // stored styles for notes
2338
2340
2341 const std::vector<ScNoteStyleEntry>& rNoteEntries = pSheetData->GetNoteStyles();
2342 for (const auto& rNoteEntry : rNoteEntries)
2343 {
2344 ScAddress aPos = rNoteEntry.maCellPos;
2345 SCTAB nTable = aPos.Tab();
2346 bool bCopySheet = pDoc->IsStreamValid( nTable );
2347 if (bCopySheet)
2348 {
2350
2351 ScPostIt* pNote = pDoc->GetNote(aPos);
2352 OSL_ENSURE( pNote, "note not found" );
2353 if (pNote)
2354 {
2355 SdrCaptionObj* pDrawObj = pNote->GetOrCreateCaption( aPos );
2356 // all uno shapes are created anyway in CollectSharedData
2357 uno::Reference<beans::XPropertySet> xShapeProperties( pDrawObj->getUnoShape(), uno::UNO_QUERY );
2358 if (xShapeProperties.is())
2359 {
2360 if ( !rNoteEntry.maStyleName.isEmpty() )
2361 {
2362 std::vector<XMLPropertyState> aPropStates(xShapeMapper->Filter(*this, xShapeProperties));
2363 OUString sName( rNoteEntry.maStyleName );
2364 GetAutoStylePool()->AddNamed(sName, XmlStyleFamily::SD_GRAPHICS_ID, OUString(), std::move(aPropStates));
2365 GetAutoStylePool()->RegisterName(XmlStyleFamily::SD_GRAPHICS_ID, sName);
2366 }
2367 if ( !rNoteEntry.maTextStyle.isEmpty() )
2368 {
2369 std::vector<XMLPropertyState> aPropStates(
2370 GetTextParagraphExport()->GetParagraphPropertyMapper()->Filter(*this, xShapeProperties));
2371 OUString sName( rNoteEntry.maTextStyle );
2372 GetAutoStylePool()->AddNamed(sName, XmlStyleFamily::TEXT_PARAGRAPH, OUString(), std::move(aPropStates));
2373 GetAutoStylePool()->RegisterName(XmlStyleFamily::TEXT_PARAGRAPH, sName);
2374 }
2375 }
2376 }
2377 }
2378 }
2379
2380 // note paragraph styles
2381
2382 rtl::Reference<SvXMLExportPropertyMapper> xParaPropMapper = GetTextParagraphExport()->GetParagraphPropertyMapper();
2383
2384 const std::vector<ScTextStyleEntry>& rNoteParaEntries = pSheetData->GetNoteParaStyles();
2385 for (const auto& rNoteParaEntry : rNoteParaEntries)
2386 {
2387 ScAddress aPos = rNoteParaEntry.maCellPos;
2388 SCTAB nTable = aPos.Tab();
2389 bool bCopySheet = pDoc->IsStreamValid( nTable );
2390 if (bCopySheet)
2391 {
2392 ScPostIt* pNote = pDoc->GetNote( aPos );
2393 OSL_ENSURE( pNote, "note not found" );
2394 if (pNote)
2395 {
2396 SdrCaptionObj* pDrawObj = pNote->GetOrCreateCaption( aPos );
2397 uno::Reference<container::XEnumerationAccess> xCellText(pDrawObj->getUnoShape(), uno::UNO_QUERY);
2398 uno::Reference<beans::XPropertySet> xParaProp(
2399 lcl_GetEnumerated( xCellText, rNoteParaEntry.maSelection.nStartPara ), uno::UNO_QUERY );
2400 if ( xParaProp.is() )
2401 {
2402 std::vector<XMLPropertyState> aPropStates(xParaPropMapper->Filter(*this, xParaProp));
2403 OUString sName( rNoteParaEntry.maName );
2404 GetAutoStylePool()->AddNamed(sName, XmlStyleFamily::TEXT_PARAGRAPH, OUString(), std::move(aPropStates));
2405 GetAutoStylePool()->RegisterName(XmlStyleFamily::TEXT_PARAGRAPH, sName);
2406 }
2407 }
2408 }
2409 }
2410
2411 // note text styles
2412
2414
2415 const std::vector<ScTextStyleEntry>& rNoteTextEntries = pSheetData->GetNoteTextStyles();
2416 for (const auto& rNoteTextEntry : rNoteTextEntries)
2417 {
2418 ScAddress aPos = rNoteTextEntry.maCellPos;
2419 SCTAB nTable = aPos.Tab();
2420 bool bCopySheet = pDoc->IsStreamValid( nTable );
2421 if (bCopySheet)
2422 {
2423 ScPostIt* pNote = pDoc->GetNote( aPos );
2424 OSL_ENSURE( pNote, "note not found" );
2425 if (pNote)
2426 {
2427 SdrCaptionObj* pDrawObj = pNote->GetOrCreateCaption( aPos );
2428 uno::Reference<text::XSimpleText> xCellText(pDrawObj->getUnoShape(), uno::UNO_QUERY);
2429 uno::Reference<beans::XPropertySet> xCursorProp(xCellText->createTextCursor(), uno::UNO_QUERY);
2430 ScDrawTextCursor* pCursor = comphelper::getFromUnoTunnel<ScDrawTextCursor>( xCursorProp );
2431 if (pCursor)
2432 {
2433 pCursor->SetSelection( rNoteTextEntry.maSelection );
2434
2435 std::vector<XMLPropertyState> aPropStates(xTextPropMapper->Filter(*this, xCursorProp));
2436 OUString sName( rNoteTextEntry.maName );
2437 GetAutoStylePool()->AddNamed(sName, XmlStyleFamily::TEXT_TEXT, OUString(), std::move(aPropStates));
2438 GetAutoStylePool()->RegisterName(XmlStyleFamily::TEXT_TEXT, sName);
2439 }
2440 }
2441 }
2442 }
2443
2444 // stored text styles
2445
2446 // Calling createTextCursor fires up editeng, which is very slow, and often subsequent style entries
2447 // refer to the same cell, so cache it.
2448 ScAddress aPrevPos;
2449 uno::Reference<beans::XPropertySet> xPrevCursorProp;
2450 const std::vector<ScTextStyleEntry>& rTextEntries = pSheetData->GetTextStyles();
2451 for (const auto& rTextEntry : rTextEntries)
2452 {
2453 ScAddress aPos = rTextEntry.maCellPos;
2454 sal_Int32 nTable = aPos.Tab();
2455 bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
2456 if (!bCopySheet)
2457 continue;
2458
2461
2462 uno::Reference<beans::XPropertySet> xCursorProp;
2463 if (xPrevCursorProp && aPrevPos == aPos)
2464 xCursorProp = xPrevCursorProp;
2465 else
2466 {
2467 uno::Reference<table::XCellRange> xCellRange(xIndex->getByIndex(nTable), uno::UNO_QUERY);
2468 uno::Reference<text::XSimpleText> xCellText(xCellRange->getCellByPosition(aPos.Col(), aPos.Row()), uno::UNO_QUERY);
2469 xCursorProp.set(xCellText->createTextCursor(), uno::UNO_QUERY);
2470 }
2471 ScCellTextCursor* pCursor = comphelper::getFromUnoTunnel<ScCellTextCursor>( xCursorProp );
2472 if (!pCursor)
2473 continue;
2474 pCursor->SetSelection( rTextEntry.maSelection );
2475
2476 std::vector<XMLPropertyState> aPropStates(xTextPropMapper->Filter(*this, xCursorProp));
2477 OUString sName( rTextEntry.maName );
2478 GetAutoStylePool()->AddNamed(sName, XmlStyleFamily::TEXT_TEXT, OUString(), std::move(aPropStates));
2479 GetAutoStylePool()->RegisterName(XmlStyleFamily::TEXT_TEXT, sName);
2480 xPrevCursorProp = xCursorProp;
2481 aPrevPos = aPos;
2482 }
2483 }
2484
2486
2487 if (!pSharedData)
2488 {
2489 SCTAB nTableCount(0);
2490 sal_Int32 nShapesCount(0);
2491 CollectSharedData(nTableCount, nShapesCount);
2492 }
2493 sal_Int32 nTableCount(xIndex->getCount());
2494 pCellStyles->AddNewTable(nTableCount - 1);
2495 CollectShapesAutoStyles(nTableCount);
2496 for (sal_Int32 nTable = 0; nTable < nTableCount; ++nTable, IncrementProgressBar(false))
2497 {
2498 uno::Reference <sheet::XSpreadsheet> xTable(xIndex->getByIndex(nTable), uno::UNO_QUERY);
2499 if (!xTable.is())
2500 continue;
2501
2502 // table styles array must be complete, including copied tables - Add should find the stored style
2503 uno::Reference<beans::XPropertySet> xTableProperties(xTable, uno::UNO_QUERY);
2504 if (xTableProperties.is())
2505 {
2506 std::vector<XMLPropertyState> aPropStates(xTableStylesExportPropertySetMapper->Filter(*this, xTableProperties));
2507 if(!aPropStates.empty())
2508 {
2509 OUString sName;
2510 GetAutoStylePool()->Add(sName, XmlStyleFamily::TABLE_TABLE, OUString(), std::move(aPropStates));
2511 aTableStyles.push_back(sName);
2512 }
2513 }
2514
2515 // collect other auto-styles only for non-copied sheets
2516 uno::Reference<sheet::XUniqueCellFormatRangesSupplier> xCellFormatRanges ( xTable, uno::UNO_QUERY );
2517 if ( xCellFormatRanges.is() )
2518 {
2519 uno::Reference<container::XIndexAccess> xFormatRangesIndex(xCellFormatRanges->getUniqueCellFormatRanges());
2520 if (xFormatRangesIndex.is())
2521 {
2522 sal_Int32 nFormatRangesCount(xFormatRangesIndex->getCount());
2523 GetProgressBarHelper()->ChangeReference(GetProgressBarHelper()->GetReference() + nFormatRangesCount);
2524 for (sal_Int32 nFormatRange = 0; nFormatRange < nFormatRangesCount; ++nFormatRange)
2525 {
2526 uno::Reference< sheet::XSheetCellRanges> xCellRanges(xFormatRangesIndex->getByIndex(nFormatRange), uno::UNO_QUERY);
2527 if (xCellRanges.is())
2528 {
2529 uno::Reference <beans::XPropertySet> xProperties (xCellRanges, uno::UNO_QUERY);
2530 if (xProperties.is())
2531 {
2532 AddStyleFromCells(xProperties, xTable, nTable, nullptr);
2533 IncrementProgressBar(false);
2534 }
2535 }
2536 }
2537 }
2538 }
2539 uno::Reference<table::XColumnRowRange> xColumnRowRange (xTable, uno::UNO_QUERY);
2540 if (xColumnRowRange.is() && pDoc)
2541 {
2543 uno::Reference<table::XTableColumns> xTableColumns(xColumnRowRange->getColumns());
2544 if (xTableColumns.is())
2545 {
2546 sal_Int32 nColumns(pDoc->GetLastChangedColFlagsWidth(sal::static_int_cast<SCTAB>(nTable)));
2547 pSharedData->SetLastColumn(nTable, nColumns);
2548 table::CellRangeAddress aCellAddress(GetEndAddress(xTable));
2549 if (aCellAddress.EndColumn > nColumns)
2550 {
2551 ++nColumns;
2552 pColumnStyles->AddNewTable(nTable, aCellAddress.EndColumn);
2553 }
2554 else
2555 pColumnStyles->AddNewTable(nTable, nColumns);
2556 sal_Int32 nColumn = 0;
2557 while (nColumn <= pDoc->MaxCol())
2558 {
2559 sal_Int32 nIndex(-1);
2560 bool bIsVisible(true);
2561 uno::Reference <beans::XPropertySet> xColumnProperties(xTableColumns->getByIndex(nColumn), uno::UNO_QUERY);
2562 if (xColumnProperties.is())
2563 {
2564 AddStyleFromColumn( xColumnProperties, nullptr, nIndex, bIsVisible );
2565 pColumnStyles->AddFieldStyleName(nTable, nColumn, nIndex, bIsVisible);
2566 }
2567 sal_Int32 nOld(nColumn);
2568 nColumn = pDoc->GetNextDifferentChangedColFlagsWidth(sal::static_int_cast<SCTAB>(nTable), static_cast<SCCOL>(nColumn));
2569 for (sal_Int32 i = nOld + 1; i < nColumn; ++i)
2570 pColumnStyles->AddFieldStyleName(nTable, i, nIndex, bIsVisible);
2571 }
2572 if (aCellAddress.EndColumn > nColumns)
2573 {
2574 bool bIsVisible(true);
2575 sal_Int32 nIndex(pColumnStyles->GetStyleNameIndex(nTable, nColumns, bIsVisible));
2576 for (sal_Int32 i = nColumns + 1; i <= aCellAddress.EndColumn; ++i)
2577 pColumnStyles->AddFieldStyleName(nTable, i, nIndex, bIsVisible);
2578 }
2579 }
2580 uno::Reference<table::XTableRows> xTableRows(xColumnRowRange->getRows());
2581 if (xTableRows.is())
2582 {
2583 sal_Int32 nRows(pDoc->GetLastChangedRowFlagsWidth(sal::static_int_cast<SCTAB>(nTable)));
2584 pSharedData->SetLastRow(nTable, nRows);
2585
2586 pRowStyles->AddNewTable(nTable, pDoc->MaxRow());
2587 sal_Int32 nRow = 0;
2588 while (nRow <= pDoc->MaxRow())
2589 {
2590 sal_Int32 nIndex = 0;
2591 uno::Reference <beans::XPropertySet> xRowProperties(xTableRows->getByIndex(nRow), uno::UNO_QUERY);
2592 if(xRowProperties.is())
2593 {
2594 AddStyleFromRow( xRowProperties, nullptr, nIndex );
2595 pRowStyles->AddFieldStyleName(nTable, nRow, nIndex);
2596 }
2597 sal_Int32 nOld(nRow);
2598 nRow = pDoc->GetNextDifferentChangedRowFlagsWidth(sal::static_int_cast<SCTAB>(nTable), static_cast<SCROW>(nRow));
2599 if (nRow > nOld + 1)
2600 pRowStyles->AddFieldStyleName(nTable, nOld + 1, nIndex, nRow - 1);
2601 }
2602 }
2603 }
2605 }
2606
2607 pChangeTrackingExportHelper->CollectAutoStyles();
2608 }
2609
2610 if (getExportFlags() & SvXMLExportFlags::MASTERSTYLES)
2611 // tdf#154445 - export all page styles even if they are not in use
2612 GetPageExport()->collectAutoStyles(false);
2613
2614 mbAutoStylesCollected = true;
2615}
2616
2618{
2619 if (!GetModel().is())
2620 return;
2621
2622 uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( GetModel(), uno::UNO_QUERY );
2623 if (!xSpreadDoc.is())
2624 return;
2625
2626 uno::Reference<container::XIndexAccess> xIndex( xSpreadDoc->getSheets(), uno::UNO_QUERY );
2627 if (!xIndex.is())
2628 return;
2629
2631
2632 if (getExportFlags() & SvXMLExportFlags::CONTENT)
2633 {
2634 GetAutoStylePool()->exportXML(XmlStyleFamily::TABLE_COLUMN);
2635 GetAutoStylePool()->exportXML(XmlStyleFamily::TABLE_ROW);
2636 GetAutoStylePool()->exportXML(XmlStyleFamily::TABLE_TABLE);
2638 GetAutoStylePool()->exportXML(XmlStyleFamily::TABLE_CELL);
2639
2640 GetShapeExport()->exportAutoStyles();
2641 GetFormExport()->exportAutoStyles( );
2642
2643 if (pDoc)
2644 {
2646 // #i100879# write the table style for cached tables only if there are cached tables
2647 // (same logic as in ExportExternalRefCacheStyles)
2648 if (pRefMgr->hasExternalData())
2649 {
2650 // Special table style for the external ref cache tables.
2653 SvXMLElementExport aElemStyle(*this, XML_NAMESPACE_STYLE, XML_STYLE, true, true);
2655 SvXMLElementExport aElemStyleTabProps(*this, XML_NAMESPACE_STYLE, XML_TABLE_PROPERTIES, true, true);
2656 }
2657 }
2658 }
2659
2660 if (getExportFlags() & SvXMLExportFlags::MASTERSTYLES)
2661 {
2663 GetPageExport()->exportAutoStyles();
2664 }
2665
2666 // #i30251#; only write Text Styles once
2667
2668 if ((getExportFlags() & SvXMLExportFlags::CONTENT) || (getExportFlags() & SvXMLExportFlags::MASTERSTYLES))
2669 GetTextParagraphExport()->exportTextAutoStyles();
2670}
2671
2673{
2674 // tdf#154445 - export all page styles even if they are not in use
2675 GetPageExport()->exportMasterStyles( false );
2676}
2677
2678void ScXMLExport::CollectInternalShape( uno::Reference< drawing::XShape > const & xShape )
2679{
2680 // detective objects and notes
2682 if( !pObject )
2683 return;
2684
2685 // collect note caption objects from all layers (internal or hidden)
2686 if( ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObject, static_cast< SCTAB >( nCurrentTable ) ) )
2687 {
2688 if(pDoc->GetNote(pCaptData->maStart))
2689 {
2690 pSharedData->AddNoteObj( xShape, pCaptData->maStart );
2691
2692 // #i60851# When the file is saved while editing a new note,
2693 // the cell is still empty -> last column/row must be updated
2694 OSL_ENSURE( pCaptData->maStart.Tab() == nCurrentTable, "invalid table in object data" );
2695 pSharedData->SetLastColumn( nCurrentTable, pCaptData->maStart.Col() );
2696 pSharedData->SetLastRow( nCurrentTable, pCaptData->maStart.Row() );
2697 }
2698 }
2699 // other objects from internal layer only (detective)
2700 else if( pObject->GetLayer() == SC_LAYER_INTERN )
2701 {
2702 ScDetectiveFunc aDetFunc( *pDoc, static_cast<SCTAB>(nCurrentTable) );
2703 ScAddress aPosition;
2704 ScRange aSourceRange;
2705 bool bRedLine;
2706 ScDetectiveObjType eObjType = aDetFunc.GetDetectiveObjectType(
2707 pObject, nCurrentTable, aPosition, aSourceRange, bRedLine );
2708 pSharedData->GetDetectiveObjContainer()->AddObject( eObjType, static_cast<SCTAB>(nCurrentTable), aPosition, aSourceRange, bRedLine );
2709 }
2710}
2711
2712bool ScXMLExport::GetMerged (const table::CellRangeAddress* pCellAddress,
2713 const uno::Reference <sheet::XSpreadsheet>& xTable)
2714{
2715 bool bReady(false);
2716 sal_Int32 nRow(pCellAddress->StartRow);
2717 sal_Int32 nCol(pCellAddress->StartColumn);
2718 sal_Int32 nEndRow(pCellAddress->EndRow);
2719 sal_Int32 nEndCol(pCellAddress->EndColumn);
2720 bool bRowInc(nEndRow > nRow);
2721 while(!bReady && nRow <= nEndRow && nCol <= nEndCol)
2722 {
2723 uno::Reference<sheet::XSheetCellRange> xSheetCellRange(xTable->getCellRangeByPosition(nCol, nRow, nCol, nRow), uno::UNO_QUERY);
2724 if (xSheetCellRange.is())
2725 {
2726 uno::Reference<sheet::XSheetCellCursor> xCursor(xTable->createCursorByRange(xSheetCellRange));
2727 if(xCursor.is())
2728 {
2729 uno::Reference<sheet::XCellRangeAddressable> xCellAddress (xCursor, uno::UNO_QUERY);
2730 xCursor->collapseToMergedArea();
2731 table::CellRangeAddress aCellAddress2(xCellAddress->getRangeAddress());
2732 ScRange aScRange( aCellAddress2.StartColumn, aCellAddress2.StartRow, aCellAddress2.Sheet,
2733 aCellAddress2.EndColumn, aCellAddress2.EndRow, aCellAddress2.Sheet );
2734
2735 if ((aScRange.aEnd.Row() > nRow ||
2736 aScRange.aEnd.Col() > nCol) &&
2737 aScRange.aStart.Row() == nRow &&
2738 aScRange.aStart.Col() == nCol)
2739 {
2740 pMergedRangesContainer->AddRange(aScRange);
2741 pSharedData->SetLastColumn(aScRange.aEnd.Tab(), aScRange.aEnd.Col());
2742 pSharedData->SetLastRow(aScRange.aEnd.Tab(), aScRange.aEnd.Row());
2743 }
2744 else
2745 bReady = true;
2746 }
2747 }
2748 if (!bReady)
2749 {
2750 if (bRowInc)
2751 ++nRow;
2752 else
2753 ++nCol;
2754 }
2755 }
2756 OSL_ENSURE(!(!bReady && nEndRow > nRow && nEndCol > nCol), "should not be possible");
2757 return !bReady;
2758}
2759
2761 ScRange& aCellAddress, bool& bIsFirst) const
2762{
2763 bIsFirst = false;
2764
2765 ScRange aMatrixRange;
2766
2767 if (pDoc && pDoc->GetMatrixFormulaRange(aCell, aMatrixRange))
2768 {
2769 aCellAddress = aMatrixRange;
2770 if ((aCellAddress.aStart.Col() == aCell.Col() && aCellAddress.aStart.Row() == aCell.Row()) &&
2771 (aCellAddress.aEnd.Col() > aCell.Col() || aCellAddress.aEnd.Row() > aCell.Row()))
2772 {
2773 bIsFirst = true;
2774 return true;
2775 }
2776 else if (aCellAddress.aStart.Col() != aCell.Col() || aCellAddress.aStart.Row() != aCell.Row() ||
2777 aCellAddress.aEnd.Col() != aCell.Col() || aCellAddress.aEnd.Row()!= aCell.Row())
2778 return true;
2779 else
2780 {
2781 bIsFirst = true;
2782 return true;
2783 }
2784 }
2785
2786 return false;
2787}
2788
2789void ScXMLExport::WriteTable(sal_Int32 nTable, const uno::Reference<sheet::XSpreadsheet>& xTable)
2790{
2791 if (!xTable.is())
2792 return;
2793
2794 xCurrentTable.set(xTable);
2795 uno::Reference<container::XNamed> xName (xTable, uno::UNO_QUERY );
2796 if (!xName.is())
2797 return;
2798
2799 nCurrentTable = sal::static_int_cast<sal_uInt16>( nTable );
2800 OUString sOUTableName(xName->getName());
2801 AddAttribute(sAttrName, sOUTableName);
2803
2804 uno::Reference<util::XProtectable> xProtectable (xTable, uno::UNO_QUERY);
2805 const ScTableProtection* pProtect = nullptr;
2806 if (xProtectable.is() && xProtectable->isProtected())
2807 {
2809 if (pDoc)
2810 {
2811 pProtect = pDoc->GetTabProtection(nTable);
2812 if (pProtect)
2813 {
2814 OUStringBuffer aBuffer;
2816 if (pProtect->hasPasswordHash(PASSHASH_SHA1))
2817 {
2819 pProtect->getPasswordHash(PASSHASH_SHA1));
2820 eHashUsed = PASSHASH_SHA1;
2821 }
2822 else if (pProtect->hasPasswordHash(PASSHASH_SHA256))
2823 {
2825 pProtect->getPasswordHash(PASSHASH_SHA256));
2826 eHashUsed = PASSHASH_SHA256;
2827 }
2828 else if (pProtect->hasPasswordHash(PASSHASH_XL, PASSHASH_SHA1))
2829 {
2830 // Double-hash this by SHA1 on top of the legacy xls hash.
2831 uno::Sequence<sal_Int8> aHash = pProtect->getPasswordHash(PASSHASH_XL, PASSHASH_SHA1);
2833 eHashUsed = PASSHASH_XL;
2834 }
2835 if (!aBuffer.isEmpty())
2836 {
2839 {
2840 if (eHashUsed == PASSHASH_XL)
2841 {
2847 }
2848 else if (eHashUsed == PASSHASH_SHA1)
2849 {
2852 }
2853 else if (eHashUsed == PASSHASH_SHA256)
2854 {
2857 }
2858 }
2859 }
2860 }
2861 }
2862 }
2863 OUString sPrintRanges;
2864 ScRange aColumnHeaderRange;
2865 bool bHasColumnHeader;
2866 GetColumnRowHeader(bHasColumnHeader, aColumnHeaderRange, bHasRowHeader, aRowHeaderRange, sPrintRanges);
2867 if( !sPrintRanges.isEmpty() )
2869 else if (pDoc && !pDoc->IsPrintEntireSheet(static_cast<SCTAB>(nTable)))
2871 SvXMLElementExport aElemT(*this, sElemTab, true, true);
2872
2873 if (pProtect && pProtect->isProtected() && getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED)
2874 {
2879
2884
2889
2890 OUString aElemName = GetNamespaceMap().GetQNameByKey(
2892
2893 SvXMLElementExport aElemProtected(*this, aElemName, true, true);
2894 }
2895
2896 CheckAttrList();
2897
2898 if ( pDoc && pDoc->GetSheetEvents( static_cast<SCTAB>(nTable) ) &&
2900 {
2901 // store sheet events
2902 uno::Reference<document::XEventsSupplier> xSupplier(xTable, uno::UNO_QUERY);
2903 uno::Reference<container::XNameAccess> xEvents = xSupplier->getEvents();
2904 GetEventExport().ExportExt( xEvents );
2905 }
2906
2908 WriteScenario();
2909 uno::Reference<drawing::XDrawPage> xDrawPage;
2910 if (pSharedData->HasForm(nTable, xDrawPage) && xDrawPage.is())
2911 {
2912 ::xmloff::OOfficeFormsExport aForms(*this);
2913 GetFormExport()->exportForms( xDrawPage );
2914 bool bRet(GetFormExport()->seekPage( xDrawPage ));
2915 OSL_ENSURE( bRet, "OFormLayerXMLExport::seekPage failed!" );
2916 }
2917 if (pSharedData->HasDrawPage())
2918 {
2919 GetShapeExport()->seekShapes(pSharedData->GetDrawPage(nTable));
2921 }
2922 table::CellRangeAddress aRange(GetEndAddress(xTable));
2923 pSharedData->SetLastColumn(nTable, aRange.EndColumn);
2924 pSharedData->SetLastRow(nTable, aRange.EndRow);
2925 mpCellsItr->SetCurrentTable(static_cast<SCTAB>(nTable), xCurrentTable);
2926 pGroupColumns->NewTable();
2927 pGroupRows->NewTable();
2929 if (bHasColumnHeader)
2930 pSharedData->SetLastColumn(nTable, aColumnHeaderRange.aEnd.Col());
2931 bRowHeaderOpen = false;
2932 if (bHasRowHeader)
2933 pSharedData->SetLastRow(nTable, aRowHeaderRange.aEnd.Row());
2934 pDefaults->FillDefaultStyles(nTable, pSharedData->GetLastRow(nTable),
2935 pSharedData->GetLastColumn(nTable), pCellStyles.get(), pDoc);
2936 pRowFormatRanges->SetColDefaults(&pDefaults->GetColDefaults());
2937 pCellStyles->SetColDefaults(&pDefaults->GetColDefaults());
2938 ExportColumns(nTable, aColumnHeaderRange, bHasColumnHeader);
2939 bool bIsFirst(true);
2940 sal_Int32 nEqualCells(0);
2941 ScMyCell aCell;
2942 ScMyCell aPrevCell;
2943 while (mpCellsItr->GetNext(aCell, pCellStyles.get()))
2944 {
2945 if (bIsFirst)
2946 {
2947 ExportFormatRanges(0, 0, aCell.maCellAddress.Col()-1, aCell.maCellAddress.Row(), nTable);
2948 aPrevCell = aCell;
2949 bIsFirst = false;
2950 }
2951 else
2952 {
2953 if ((aPrevCell.maCellAddress.Row() == aCell.maCellAddress.Row()) &&
2954 (aPrevCell.maCellAddress.Col() + nEqualCells + 1 == aCell.maCellAddress.Col()))
2955 {
2956 if(IsCellEqual(aPrevCell, aCell))
2957 ++nEqualCells;
2958 else
2959 {
2960 WriteCell(aPrevCell, nEqualCells);
2961 nEqualCells = 0;
2962 aPrevCell = aCell;
2963 }
2964 }
2965 else
2966 {
2967 WriteCell(aPrevCell, nEqualCells);
2968 ExportFormatRanges(aPrevCell.maCellAddress.Col() + nEqualCells + 1, aPrevCell.maCellAddress.Row(),
2969 aCell.maCellAddress.Col()-1, aCell.maCellAddress.Row(), nTable);
2970 nEqualCells = 0;
2971 aPrevCell = aCell;
2972 }
2973 }
2974 }
2975 if (!bIsFirst)
2976 {
2977 WriteCell(aPrevCell, nEqualCells);
2978 ExportFormatRanges(aPrevCell.maCellAddress.Col() + nEqualCells + 1, aPrevCell.maCellAddress.Row(),
2979 pSharedData->GetLastColumn(nTable), pSharedData->GetLastRow(nTable), nTable);
2980 }
2981 else
2982 ExportFormatRanges(0, 0, pSharedData->GetLastColumn(nTable), pSharedData->GetLastRow(nTable), nTable);
2983
2984 CloseRow(pSharedData->GetLastRow(nTable));
2985
2986 if (!pDoc)
2987 return;
2988
2989 // Export sheet-local named ranges.
2990 ScRangeName* pRangeName = pDoc->GetRangeName(nTable);
2991 if (pRangeName && !pRangeName->empty())
2992 {
2993 WriteNamedRange(pRangeName);
2994 }
2995
2997 {
2998 //export new conditional format information
3000 exportSparklineGroups(nTable);
3001 }
3002}
3003
3004namespace {
3005
3006void writeContent(
3007 ScXMLExport& rExport, const OUString& rStyleName, const OUString& rContent, const SvxFieldData* pField )
3008{
3009 std::unique_ptr<SvXMLElementExport> pElem;
3010 if (!rStyleName.isEmpty())
3011 {
3012 // Formatted section with automatic style.
3013 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME, rStyleName);
3014 OUString aElemName = rExport.GetNamespaceMap().GetQNameByKey(
3015 XML_NAMESPACE_TEXT, GetXMLToken(XML_SPAN));
3016 pElem.reset(new SvXMLElementExport(rExport, aElemName, false, false));
3017 }
3018
3019 if (pField)
3020 {
3021 // Write a field item.
3022 OUString aFieldVal = ScEditUtil::GetCellFieldValue(*pField, rExport.GetDocument(), nullptr, nullptr);
3023 switch (pField->GetClassId())
3024 {
3025 case text::textfield::Type::URL:
3026 {
3027 // <text:a xlink:href="url" xlink:type="simple">value</text:a>
3028
3029 const SvxURLField* pURLField = static_cast<const SvxURLField*>(pField);
3030 const OUString& aURL = pURLField->GetURL();
3031 rExport.AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, rExport.GetRelativeReference(aURL));
3032 rExport.AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, "simple");
3033 const OUString& aTargetFrame = pURLField->GetTargetFrame();
3034 if (!aTargetFrame.isEmpty())
3035 rExport.AddAttribute(XML_NAMESPACE_OFFICE, XML_TARGET_FRAME_NAME, aTargetFrame);
3036
3037 OUString aElemName = rExport.GetNamespaceMap().GetQNameByKey(
3038 XML_NAMESPACE_TEXT, GetXMLToken(XML_A));
3039 SvXMLElementExport aElem(rExport, aElemName, false, false);
3040 rExport.Characters(aFieldVal);
3041 }
3042 break;
3044 {
3045 // <text:date style:data-style-name="N2" text:date-value="YYYY-MM-DD">value</text:date>
3046
3047 Date aDate(Date::SYSTEM);
3048 OUStringBuffer aBuf;
3049 sal_Int32 nVal = aDate.GetYear();
3050 aBuf.append(OUString::number(nVal) + "-");
3051 nVal = aDate.GetMonth();
3052 if (nVal < 10)
3053 aBuf.append('0');
3054 aBuf.append(OUString::number(nVal) + "-");
3055 nVal = aDate.GetDay();
3056 if (nVal < 10)
3057 aBuf.append('0');
3058 aBuf.append(nVal);
3059 rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_DATA_STYLE_NAME, "N2");
3060 rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_DATE_VALUE, aBuf.makeStringAndClear());
3061
3062 OUString aElemName = rExport.GetNamespaceMap().GetQNameByKey(
3063 XML_NAMESPACE_TEXT, GetXMLToken(XML_DATE));
3064 SvXMLElementExport aElem(rExport, aElemName, false, false);
3065 rExport.Characters(aFieldVal);
3066 }
3067 break;
3068 case text::textfield::Type::DOCINFO_TITLE:
3069 {
3070 // <text:title>value</text:title>
3071
3072 OUString aElemName = rExport.GetNamespaceMap().GetQNameByKey(
3073 XML_NAMESPACE_TEXT, GetXMLToken(XML_TITLE));
3074 SvXMLElementExport aElem(rExport, aElemName, false, false);
3075 rExport.Characters(aFieldVal);
3076 }
3077 break;
3079 {
3080 // <text:sheet-name>value</text:sheet-name>
3081
3082 OUString aElemName = rExport.GetNamespaceMap().GetQNameByKey(
3083 XML_NAMESPACE_TEXT, GetXMLToken(XML_SHEET_NAME));
3084 SvXMLElementExport aElem(rExport, aElemName, false, false);
3085 rExport.Characters(aFieldVal);
3086 }
3087 break;
3088 default:
3089 rExport.Characters(aFieldVal);
3090 }
3091 }
3092 else
3093 rExport.Characters(rContent);
3094}
3095
3096void flushParagraph(
3097 ScXMLExport& rExport, std::u16string_view rParaText,
3099 const ScXMLEditAttributeMap& rAttrMap,
3100 std::vector<editeng::Section>::const_iterator it, std::vector<editeng::Section>::const_iterator const & itEnd )
3101{
3102 OUString aElemName = rExport.GetNamespaceMap().GetQNameByKey(
3103 XML_NAMESPACE_TEXT, GetXMLToken(XML_P));
3104 SvXMLElementExport aElemP(rExport, aElemName, false, false);
3105
3106 for (; it != itEnd; ++it)
3107 {
3108 const editeng::Section& rSec = *it;
3109
3110 OUString aContent(rParaText.substr(rSec.mnStart, rSec.mnEnd - rSec.mnStart));
3111
3112 std::vector<XMLPropertyState> aPropStates;
3113 const SvxFieldData* pField = toXMLPropertyStates(rExport, aPropStates, rSec.maAttributes, xMapper, rAttrMap);
3114 OUString aStyleName = xStylePool->Find(XmlStyleFamily::TEXT_TEXT, OUString(), aPropStates);
3115 if (aContent == "\x001" && !pField)
3116 {
3117 for (const SfxPoolItem* p : rSec.maAttributes)
3118 {
3119 if (p->Which() == EE_FEATURE_TAB)
3120 {
3121 SvXMLElementExport Tab(rExport, XML_NAMESPACE_TEXT, XML_TAB, false, false);
3122 break;
3123 }
3124 }
3125 }
3126 else
3127 writeContent(rExport, aStyleName, aContent, pField);
3128 }
3129}
3130
3131}
3132
3133void ScXMLExport::WriteCell(ScMyCell& aCell, sal_Int32 nEqualCellCount)
3134{
3135 // nEqualCellCount is the number of additional cells
3136 SetRepeatAttribute(nEqualCellCount, (aCell.nType != table::CellContentType_EMPTY));
3137
3138 if (aCell.nStyleIndex != -1)
3139 AddAttribute(sAttrStyleName, pCellStyles->GetStyleNameByIndex(aCell.nStyleIndex, aCell.bIsAutoStyle));
3140 if (aCell.nValidationIndex > -1)
3142 const bool bIsFirstMatrixCell(aCell.bIsMatrixBase);
3143 if (bIsFirstMatrixCell)
3144 {
3145 SCCOL nColumns( aCell.aMatrixRange.aEnd.Col() - aCell.aMatrixRange.aStart.Col() + 1 );
3146 SCROW nRows( aCell.aMatrixRange.aEnd.Row() - aCell.aMatrixRange.aStart.Row() + 1 );
3149 }
3150 bool bIsEmpty(false);
3151 switch (aCell.nType)
3152 {
3153 case table::CellContentType_EMPTY :
3154 {
3155 bIsEmpty = true;
3156 }
3157 break;
3158 case table::CellContentType_VALUE :
3159 {
3161 aCell.nNumberFormat, aCell.maBaseCell.getDouble());
3164 aCell.nNumberFormat, aCell.maBaseCell.getDouble(), false, XML_NAMESPACE_CALC_EXT, false);
3165 }
3166 break;
3167 case table::CellContentType_TEXT :
3168 {
3169 OUString sFormattedString(lcl_GetFormattedString(pDoc, aCell.maBaseCell, aCell.maCellAddress));
3170 OUString sCellString = aCell.maBaseCell.getString(pDoc);
3171 bool bExportValue = sCellString.indexOf('\x001') == -1;
3173 sCellString, sFormattedString, bExportValue);
3176 sCellString, sFormattedString, false, XML_NAMESPACE_CALC_EXT);
3177 }
3178 break;
3179 case table::CellContentType_FORMULA :
3180 {
3181 if (aCell.maBaseCell.getType() == CELLTYPE_FORMULA)
3182 {
3183 const bool bIsMatrix(bIsFirstMatrixCell || aCell.bIsMatrixCovered);
3184 ScFormulaCell* pFormulaCell = aCell.maBaseCell.getFormula();
3185 if (!bIsMatrix || bIsFirstMatrixCell)
3186 {
3188 {
3190 mpCompileFormulaCxt.reset(new sc::CompileFormulaContext(*pDoc, eGrammar));
3191 }
3192
3193 OUString aFormula = pFormulaCell->GetFormula(*mpCompileFormulaCxt);
3194 sal_uInt16 nNamespacePrefix =
3196
3197 if (!bIsMatrix)
3198 {
3199 AddAttribute(sAttrFormula, GetNamespaceMap().GetQNameByKey(nNamespacePrefix, aFormula, false));
3200 }
3201 else
3202 {
3203 AddAttribute(sAttrFormula, GetNamespaceMap().GetQNameByKey(nNamespacePrefix, aFormula.copy(1, aFormula.getLength()-2), false));
3204 }
3205 }
3206 if (pFormulaCell->GetErrCode() != FormulaError::NONE)
3207 {
3211 {
3212 //export calcext:value-type="error"
3214 }
3215 }
3216 else if (pFormulaCell->IsValue())
3217 {
3218 bool bIsStandard;
3219 OUString sCurrency;
3220 GetNumberFormatAttributesExportHelper()->GetCellType(aCell.nNumberFormat, sCurrency, bIsStandard);
3221 if (pDoc)
3222 {
3224 aCell.nNumberFormat, pDoc->GetValue(aCell.maCellAddress));
3226 {
3228 aCell.nNumberFormat, pDoc->GetValue(aCell.maCellAddress), false, XML_NAMESPACE_CALC_EXT, false );
3229 }
3230 }
3231 }
3232 else
3233 {
3234 if (!aCell.maBaseCell.getString(pDoc).isEmpty())
3235 {
3239 {
3241 }
3242 }
3243 }
3244 }
3245 }
3246 break;
3247 default:
3248 break;
3249 }
3250 OUString* pCellString(&sElemCell);
3251 if (aCell.bIsCovered)
3252 {
3253 pCellString = &sElemCoveredCell;
3254 }
3255 else
3256 {
3257 if (aCell.bIsMergedBase)
3258 {
3259 SCCOL nColumns( aCell.aMergeRange.aEnd.Col() - aCell.aMergeRange.aStart.Col() + 1 );
3260 SCROW nRows( aCell.aMergeRange.aEnd.Row() - aCell.aMergeRange.aStart.Row() + 1 );
3261 AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_SPANNED, OUString::number(nColumns));
3262 AddAttribute(XML_NAMESPACE_TABLE, XML_NUMBER_ROWS_SPANNED, OUString::number(nRows));
3263 }
3264 }
3265 SvXMLElementExport aElemC(*this, *pCellString, true, true);
3266 CheckAttrList();
3267 WriteAreaLink(aCell);
3268 WriteAnnotation(aCell);
3269 WriteDetective(aCell);
3270
3271 if (!bIsEmpty)
3272 {
3273 if (aCell.maBaseCell.getType() == CELLTYPE_EDIT)
3274 {
3276 }
3278 {
3280 }
3281 else
3282 {
3283 SvXMLElementExport aElemP(*this, sElemP, true, false);
3284
3285 OUString aParaStr =
3287
3288 bool bPrevCharWasSpace = true;
3289 GetTextParagraphExport()->exportCharacterData(aParaStr, bPrevCharWasSpace);
3290 }
3291 }
3292 WriteShapes(aCell);
3293 if (!bIsEmpty)
3294 IncrementProgressBar(false);
3295}
3296
3298{
3299 rtl::Reference<XMLPropertySetMapper> xMapper = GetTextParagraphExport()->GetTextPropMapper()->getPropertySetMapper();
3301 const ScXMLEditAttributeMap& rAttrMap = GetEditAttributeMap();
3302
3303 // Get raw paragraph texts first.
3304 std::vector<OUString> aParaTexts;
3305 sal_Int32 nParaCount = pText->GetParagraphCount();
3306 aParaTexts.reserve(nParaCount);
3307 for (sal_Int32 i = 0; i < nParaCount; ++i)
3308 aParaTexts.push_back(pText->GetText(i));
3309
3310 // Get all section data and iterate through them.
3311 std::vector<editeng::Section> aAttrs;
3312 pText->GetAllSections(aAttrs);
3313 std::vector<editeng::Section>::const_iterator itSec = aAttrs.begin(), itSecEnd = aAttrs.end();
3314 std::vector<editeng::Section>::const_iterator itPara = itSec;
3315 sal_Int32 nCurPara = 0; // current paragraph
3316 for (; itSec != itSecEnd; ++itSec)
3317 {
3318 const editeng::Section& rSec = *itSec;
3319 if (nCurPara == rSec.mnParagraph)
3320 // Still in the same paragraph.
3321 continue;
3322
3323 // Start of a new paragraph. Flush the old paragraph.
3324 flushParagraph(*this, aParaTexts[nCurPara], xMapper, xStylePool, rAttrMap, itPara, itSec);
3325 nCurPara = rSec.mnParagraph;
3326 itPara = itSec;
3327 }
3328
3329 flushParagraph(*this, aParaTexts[nCurPara], xMapper, xStylePool, rAttrMap, itPara, itSecEnd);
3330}
3331
3333{
3335
3336 OUString aResStr = pCell->GetResultString().getString();
3337 const sal_Unicode* p = aResStr.getStr();
3338 const sal_Unicode* pEnd = p + static_cast<size_t>(aResStr.getLength());
3339 const sal_Unicode* pPara = p; // paragraph head.
3340 for (; p != pEnd; ++p)
3341 {
3342 if (*p != '\n')
3343 continue;
3344
3345 // flush the paragraph.
3346 OUString aContent;
3347 if (*pPara == '\n')
3348 ++pPara;
3349 if (p > pPara)
3350 aContent = OUString(pPara, p-pPara);
3351
3352 SvXMLElementExport aElem(*this, aElemName, false, false);
3353 Characters(aContent);
3354
3355 pPara = p;
3356 }
3357
3358 OUString aContent;
3359 if (*pPara == '\n')
3360 ++pPara;
3361 if (pEnd > pPara)
3362 aContent = OUString(pPara, pEnd-pPara);
3363
3364 SvXMLElementExport aElem(*this, aElemName, false, false);
3365 Characters(aContent);
3366}
3367
3368void ScXMLExport::ExportShape(const uno::Reference < drawing::XShape >& xShape, awt::Point* pPoint)
3369{
3370 uno::Reference < beans::XPropertySet > xShapeProps ( xShape, uno::UNO_QUERY );
3371 bool bIsChart( false );
3372 if (xShapeProps.is())
3373 {
3374 sal_Int32 nZOrder = 0;
3375 if (xShapeProps->getPropertyValue("ZOrder") >>= nZOrder)
3376 {
3377 AddAttribute(XML_NAMESPACE_DRAW, XML_ZINDEX, OUString::number(nZOrder));
3378 }
3379 uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xShapeProps->getPropertySetInfo();
3380 OUString sPropCLSID ("CLSID");
3381 if( xPropSetInfo->hasPropertyByName( sPropCLSID ) )
3382 {
3383 OUString sCLSID;
3384 if (xShapeProps->getPropertyValue( sPropCLSID ) >>= sCLSID)
3385 {
3386 if ( sCLSID.equalsIgnoreAsciiCase(GetChartExport()->getChartCLSID()) )
3387 {
3388 // we have a chart
3389 OUString sRanges;
3390 if ( pDoc )
3391 {
3392 OUString aChartName;
3393 xShapeProps->getPropertyValue( "PersistName" ) >>= aChartName;
3395 if (pCollection)
3396 {
3397 ScChartListener* pListener = pCollection->findByName(aChartName);
3398 if (pListener)
3399 {
3400 const ScRangeListRef& rRangeList = pListener->GetRangeList();
3401 if ( rRangeList.is() )
3402 {
3403 ScRangeStringConverter::GetStringFromRangeList( sRanges, rRangeList.get(), pDoc, FormulaGrammar::CONV_OOO );
3404 if ( !sRanges.isEmpty() )
3405 {
3406 bIsChart = true;
3408 pAttrList->AddAttribute(
3410 GetShapeExport()->exportShape( xShape, SEF_DEFAULT, pPoint, pAttrList.get() );
3411 }
3412 }
3413 }
3414 }
3415 }
3416
3417 if ( sRanges.isEmpty() )
3418 {
3419 uno::Reference< frame::XModel > xChartModel;
3420 if( ( xShapeProps->getPropertyValue( "Model" ) >>= xChartModel ) &&
3421 xChartModel.is())
3422 {
3423 uno::Reference< chart2::XChartDocument > xChartDoc( xChartModel, uno::UNO_QUERY );
3424 uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartModel, uno::UNO_QUERY );
3425 if( xChartDoc.is() && xReceiver.is() &&
3426 ! xChartDoc->hasInternalDataProvider())
3427 {
3428 // we have a chart that gets its data from Calc
3429 bIsChart = true;
3430 uno::Sequence< OUString > aRepresentations(
3431 xReceiver->getUsedRangeRepresentations());
3433 try
3434 {
3435 if (aRepresentations.hasElements())
3436 {
3437 // add the ranges used by the chart to the shape
3438 // element to be able to start listening after
3439 // load (when the chart is not yet loaded)
3440 uno::Reference< chart2::data::XRangeXMLConversion > xRangeConverter( xChartDoc->getDataProvider(), uno::UNO_QUERY );
3441 sRanges = lcl_RangeSequenceToString( aRepresentations, xRangeConverter );
3442 pAttrList = new comphelper::AttributeList();
3443 pAttrList->AddAttribute(
3445 }
3446 }
3447 catch (const lang::IllegalArgumentException&)
3448 {
3449 TOOLS_WARN_EXCEPTION("sc", "Exception in lcl_RangeSequenceToString - invalid range?");
3450 }
3451 GetShapeExport()->exportShape(xShape, SEF_DEFAULT, pPoint, pAttrList.get());
3452 }
3453 }
3454 }
3455 }
3456 }
3457 }
3458 }
3459 if (!bIsChart)
3460 GetShapeExport()->exportShape(xShape, SEF_DEFAULT, pPoint);
3461
3462 IncrementProgressBar(false);
3463}
3464
3466{
3467 if( !(rMyCell.bHasShape && !rMyCell.aShapeList.empty() && pDoc) )
3468 return;
3469
3470 // Reference point to turn absolute coordinates in reference point + offset. That happens in most
3471 // cases in XMLShapeExport::ImpExportNewTrans_DecomposeAndRefPoint, which gets the absolute
3472 // coordinates as translation from matrix in property "Transformation". For cell anchored shapes
3473 // the reference point is left-top (in LTR mode) of that cell, which contains the shape.
3474 tools::Rectangle aCellRectFull = pDoc->GetMMRect(
3475 rMyCell.maCellAddress.Col(), rMyCell.maCellAddress.Row(), rMyCell.maCellAddress.Col(),
3476 rMyCell.maCellAddress.Row(), rMyCell.maCellAddress.Tab(), false /*bHiddenAsZero*/);
3477 awt::Point aPoint;
3478 bool bNegativePage = pDoc->IsNegativePage(rMyCell.maCellAddress.Tab());
3479 if (bNegativePage)
3480 aPoint.X = aCellRectFull.Right();
3481 else
3482 aPoint.X = aCellRectFull.Left();
3483 aPoint.Y = aCellRectFull.Top();
3484
3485 for (const auto& rShape : rMyCell.aShapeList)
3486 {
3487 // Skip the shape if requirements are not met. The tests should not fail, but allow
3488 // shorter conditions in main part below.
3489 if (!rShape.xShape.is())
3490 continue;
3491 SdrObject* pObj = SdrObject::getSdrObjectFromXShape(rShape.xShape);
3492 if (!pObj)
3493 continue;
3494 ScDrawObjData* pObjData = ScDrawLayer::GetObjData(pObj);
3495 if (!pObjData)
3496 continue;
3497 ScAddress aSnapStartAddress = pObjData->maStart;
3498 if (!aSnapStartAddress.IsValid())
3499 continue;
3500
3501 // The current object geometry is based on bHiddenAsZero=true, but ODF file format
3502 // needs it as if there were no hidden rows or columns. We determine a fictive snap
3503 // rectangle from the anchor as if all column/rows are shown. Then we move and resize
3504 // (in case of "resize with cell") the object to meet this snap rectangle. We need to
3505 // manipulate the object itself, because the used methods in xmloff do not evaluate the
3506 // ObjData. This manipulation is only done temporarily for export. Thus we stash the geometry
3507 // and restore it when export is done and we use NbcFoo methods.
3508 bool bNeedsRestore = false;
3509 std::unique_ptr<SdrObjGeoData> pGeoData = pObj->GetGeoData();
3510
3511 // Determine top point of fictive snap rectangle ('Full' rectangle).
3512 SCTAB aTab(aSnapStartAddress.Tab());
3513 SCCOL aCol(aSnapStartAddress.Col());
3514 SCROW aRow(aSnapStartAddress.Row());
3515 tools::Rectangle aFullStartCellRect
3516 = pDoc->GetMMRect(aCol, aRow, aCol, aRow, aTab, false /*bHiddenAsZero*/);
3517 // The reference corner for the offset is top-left in case of LTR and top-right for RTL.
3518 Point aFullTopPoint;
3519 if (bNegativePage)
3520 aFullTopPoint.setX(aFullStartCellRect.Right() - pObjData->maStartOffset.X());
3521 else
3522 aFullTopPoint.setX(aFullStartCellRect.Left() + pObjData->maStartOffset.X());
3523 aFullTopPoint.setY(aFullStartCellRect.Top() + pObjData->maStartOffset.Y());
3524
3525 // Compare actual top point and full top point and move object accordingly.
3526 tools::Rectangle aOrigSnapRect(pObj->GetSnapRect());
3527 Point aActualTopPoint = bNegativePage ? aOrigSnapRect.TopRight() : aOrigSnapRect.TopLeft();
3528 if (aFullTopPoint != aActualTopPoint)
3529 {
3530 bNeedsRestore = true;
3531 Point aMoveBy = aFullTopPoint - aActualTopPoint;
3532 pObj->NbcMove(Size(aMoveBy.X(), aMoveBy.Y()));
3533 }
3534
3535 ScAddress aSnapEndAddress = pObjData->maEnd;
3536 // tdf#154005: We treat the combination of "To cell (resize with cell)" with 'size protected'
3537 // as being "To cell".
3538 if (pObjData->mbResizeWithCell && aSnapEndAddress.IsValid() && !pObj->IsResizeProtect())
3539 {
3540 // Object is anchored "To cell (resize with cell)". Compare size of actual snap rectangle
3541 // and fictive full one. Resize object accordingly.
3542 tools::Rectangle aActualSnapRect(pObj->GetSnapRect());
3543 Point aSnapEndOffset(pObjData->maEndOffset);
3544 aCol = aSnapEndAddress.Col();
3545 aRow = aSnapEndAddress.Row();
3546 tools::Rectangle aFullEndCellRect
3547 = pDoc->GetMMRect(aCol, aRow, aCol, aRow, aTab, false /*bHiddenAsZero*/);
3548 Point aFullBottomPoint;
3549 if (bNegativePage)
3550 aFullBottomPoint.setX(aFullEndCellRect.Right() - aSnapEndOffset.X());
3551 else
3552 aFullBottomPoint.setX(aFullEndCellRect.Left() + aSnapEndOffset.X());
3553 aFullBottomPoint.setY(aFullEndCellRect.Top() + aSnapEndOffset.Y());
3554 tools::Rectangle aFullSnapRect(aFullTopPoint, aFullBottomPoint);
3555 aFullSnapRect.Normalize();
3556
3557 if (aFullSnapRect != aActualSnapRect)
3558 {
3559 bNeedsRestore = true;
3560 Fraction aScaleWidth(aFullSnapRect.getOpenWidth(), aActualSnapRect.getOpenWidth());
3561 if (!aScaleWidth.IsValid())
3562 aScaleWidth = Fraction(1, 1);
3563 Fraction aScaleHeight(aFullSnapRect.getOpenHeight(),
3564 aActualSnapRect.getOpenHeight());
3565 if (!aScaleHeight.IsValid())
3566 aScaleHeight = Fraction(1, 1);
3567 pObj->NbcResize(aFullTopPoint, aScaleWidth, aScaleHeight);
3568 }
3569 }
3570
3571 // The existence of an end address is equivalent to anchor mode "To Cell (resize with cell)".
3572 // XML needs end address in regard of untransformed shape. Those are contained in rShape but
3573 // could be received from NonRotatedObjData as well.
3574 // tdf#154005: We treat the combination of "To Cell (resize with cell)" anchor with 'size
3575 // protected' property as being "To cell" anchor.
3576 if (pObjData->mbResizeWithCell && !pObj->IsResizeProtect())
3577 {
3578 OUString sEndAddress;
3579 ScRangeStringConverter::GetStringFromAddress(sEndAddress, rShape.aEndAddress, pDoc,
3580 FormulaGrammar::CONV_OOO);
3582 OUStringBuffer sBuffer;
3583 GetMM100UnitConverter().convertMeasureToXML(sBuffer, rShape.nEndX);
3584 AddAttribute(XML_NAMESPACE_TABLE, XML_END_X, sBuffer.makeStringAndClear());
3585 GetMM100UnitConverter().convertMeasureToXML(sBuffer, rShape.nEndY);
3586 AddAttribute(XML_NAMESPACE_TABLE, XML_END_Y, sBuffer.makeStringAndClear());
3587 }
3588
3589 // Correct above calculated reference point for these cases:
3590 // a) For a RTL-sheet translate from matrix is not suitable, because the shape
3591 // from xml (which is always LTR) is not mirrored to negative page but shifted.
3592 // b) In case of horizontal mirrored, 'resize with cell' anchored custom shape, translate from
3593 // matrix has wrong values. FixMe: Why is translate wrong?
3594 if (bNegativePage
3595 || (pObj->GetObjIdentifier() == SdrObjKind::CustomShape
3596 && static_cast<SdrObjCustomShape*>(pObj)->IsMirroredX()
3597 && pObjData->mbResizeWithCell))
3598 {
3599 // In these cases we set reference point so that the offset calculation in XML export
3600 // (= matrix translate - reference point) results in maStartOffset.
3602 if (pNRObjData)
3603 {
3604 awt::Point aMatrixTranslate = rShape.xShape->getPosition();
3605 aPoint.X = aMatrixTranslate.X - pNRObjData->maStartOffset.X();
3606 aPoint.Y = aMatrixTranslate.Y - pNRObjData->maStartOffset.Y();
3607 }
3608 }
3609
3610 ExportShape(rShape.xShape, &aPoint);
3611
3612 // Restore object geometry
3613 if (bNeedsRestore && pGeoData)
3614 pObj->SetGeoData(*pGeoData);
3615 }
3616}
3617
3619{
3620 ScMyTableShapes* pTableShapes(pSharedData->GetTableShapes());
3621 if (!pTableShapes || (*pTableShapes)[nCurrentTable].empty())
3622 return;
3623
3624 OSL_ENSURE(pTableShapes->size() > static_cast<size_t>(nCurrentTable), "wrong Table");
3625 SvXMLElementExport aShapesElem(*this, XML_NAMESPACE_TABLE, XML_SHAPES, true, false);
3626 for (const auto& rxShape : (*pTableShapes)[nCurrentTable])
3627 {
3628 if (rxShape.is())
3629 {
3630 if (pDoc->IsNegativePage(static_cast<SCTAB>(nCurrentTable)))
3631 {
3632 // RTL-mirroring refers to snap rectangle, not to logic rectangle, therefore cannot use
3633 // getPosition() and getSize(), but need property "FrameRect" from rxShape or
3634 // GetSnapRect() from associated SdrObject.
3635 uno::Reference<beans::XPropertySet> xShapeProp(rxShape, uno::UNO_QUERY);
3636 awt::Rectangle aFrameRect;
3637 if (xShapeProp.is() && (xShapeProp->getPropertyValue("FrameRect") >>= aFrameRect))
3638 {
3639 // file format uses shape in LTR mode. newLeft = - oldRight = - (oldLeft + width).
3640 // newTranslate = oldTranslate - refPoint, oldTranslate from transformation matrix,
3641 // calculated in XMLShapeExport::exportShape common for all modules.
3642 // oldTranslate.X = oldLeft ==> refPoint.X = 2 * oldLeft + width
3643 awt::Point aRefPoint;
3644 aRefPoint.X = 2 * aFrameRect.X + aFrameRect.Width - 1;
3645 aRefPoint.Y = 0;
3646 ExportShape(rxShape, &aRefPoint);
3647 }
3648 // else should not happen
3649 }
3650 else
3651 ExportShape(rxShape, nullptr);
3652 }
3653 }
3654 (*pTableShapes)[nCurrentTable].clear();
3655}
3656
3658{
3659 if( !rMyCell.bHasAreaLink )
3660 return;
3661
3662 const ScMyAreaLink& rAreaLink = rMyCell.aAreaLink;
3667 if( !rAreaLink.sFilterOptions.isEmpty() )
3669 AddAttribute( XML_NAMESPACE_TABLE, XML_LAST_COLUMN_SPANNED, OUString::number(rAreaLink.GetColCount()) );
3670 AddAttribute( XML_NAMESPACE_TABLE, XML_LAST_ROW_SPANNED, OUString::number(rAreaLink.GetRowCount()) );
3671 if( rAreaLink.nRefreshDelaySeconds )
3672 {
3673 OUStringBuffer sValue;
3675 static_cast<double>(rAreaLink.nRefreshDelaySeconds) / 86400 );
3676 AddAttribute( XML_NAMESPACE_TABLE, XML_REFRESH_DELAY, sValue.makeStringAndClear() );
3677 }
3679}
3680
3681void ScXMLExport::exportAnnotationMeta( const uno::Reference < drawing::XShape >& xShape)
3682{
3683 ScPostIt* pNote = pCurrentCell->pNote;
3684
3685 if (!pNote)
3686 return;
3687
3688 // TODO : notes
3689 //is it still useful, as this call back is only called from ScXMLExport::WriteAnnotation
3690 // and should be in sync with pCurrentCell
3692 uno::Reference<drawing::XShape> xCurrentShape( pNoteCaption->getUnoShape(), uno::UNO_QUERY );
3693 if (xCurrentShape.get()!=xShape.get())
3694 return;
3695
3696 const OUString& sAuthor(pNote->GetAuthor());
3697 if (!sAuthor.isEmpty())
3698 {
3699 SvXMLElementExport aCreatorElem( *this, XML_NAMESPACE_DC,
3700 XML_CREATOR, true,
3701 false );
3702 Characters(sAuthor);
3703 }
3704
3705 const OUString& aDate(pNote->GetDate());
3706 if (pDoc)
3707 {
3708 SvNumberFormatter* pNumForm = pDoc->GetFormatTable();
3709 double fDate;
3710 sal_uInt32 nfIndex = pNumForm->GetFormatIndex(NF_DATE_SYS_DDMMYYYY, LANGUAGE_SYSTEM);
3711 if (pNumForm->IsNumberFormat(aDate, nfIndex, fDate))
3712 {
3713 OUStringBuffer sBuf;
3714 GetMM100UnitConverter().convertDateTime(sBuf, fDate,true);
3715 SvXMLElementExport aDateElem( *this, XML_NAMESPACE_DC,
3716 XML_DATE, true,
3717 false );
3718 Characters(sBuf.makeStringAndClear());
3719 }
3720 else
3721 {
3722 SvXMLElementExport aDateElem( *this, XML_NAMESPACE_META,
3723 XML_DATE_STRING, true,
3724 false );
3725 Characters(aDate);
3726 }
3727 }
3728 else
3729 {
3730 SvXMLElementExport aDateElem( *this, XML_NAMESPACE_META,
3731 XML_DATE_STRING, true,
3732 false );
3733 Characters(aDate);
3734 }
3735}
3736
3738{
3739 ScPostIt* pNote = pDoc->GetNote(rMyCell.maCellAddress);
3740 if (!pNote)
3741 return;
3742
3743 if (pNote->IsCaptionShown())
3745
3746 pCurrentCell = &rMyCell;
3747
3748 SdrCaptionObj* pNoteCaption = pNote->GetOrCreateCaption(rMyCell.maCellAddress);
3749 if (pNoteCaption)
3750 {
3751 uno::Reference<drawing::XShape> xShape( pNoteCaption->getUnoShape(), uno::UNO_QUERY );
3752 if (xShape.is())
3753 GetShapeExport()->exportShape(xShape, SEF_DEFAULT|XMLShapeExportFlags::ANNOTATION);
3754 }
3755
3756 pCurrentCell = nullptr;
3757}
3758
3760{
3761 if( !(rMyCell.bHasDetectiveObj || rMyCell.bHasDetectiveOp) )
3762 return;
3763
3764 const ScMyDetectiveObjVec& rObjVec = rMyCell.aDetectiveObjVec;
3765 const ScMyDetectiveOpVec& rOpVec = rMyCell.aDetectiveOpVec;
3766 sal_Int32 nObjCount(rObjVec.size());
3767 sal_Int32 nOpCount(rOpVec.size());
3768 if( !(nObjCount || nOpCount) )
3769 return;
3770
3771 SvXMLElementExport aDetElem( *this, XML_NAMESPACE_TABLE, XML_DETECTIVE, true, true );
3772 OUString sString;
3773 for(const auto& rObj : rObjVec)
3774 {
3775 if (rObj.eObjType != SC_DETOBJ_CIRCLE)
3776 {
3777 if( (rObj.eObjType == SC_DETOBJ_ARROW) || (rObj.eObjType == SC_DETOBJ_TOOTHERTAB))
3778 {
3779 ScRangeStringConverter::GetStringFromRange( sString, rObj.aSourceRange, pDoc, FormulaGrammar::CONV_OOO );
3781 }
3782 sString = ScXMLConverter::GetStringFromDetObjType( rObj.eObjType );
3784 if( rObj.bHasError )
3786 }
3787 else
3789 SvXMLElementExport aRangeElem( *this, XML_NAMESPACE_TABLE, XML_HIGHLIGHTED_RANGE, true, true );
3790 }
3791 for(const auto& rOp : rOpVec)
3792 {
3793 OUString sOpString = ScXMLConverter::GetStringFromDetOpType( rOp.eOpType );
3795 AddAttribute( XML_NAMESPACE_TABLE, XML_INDEX, OUString::number(rOp.nIndex) );
3796 SvXMLElementExport aRangeElem( *this, XML_NAMESPACE_TABLE, XML_OPERATION, true, true );
3797 }
3798}
3799
3800void ScXMLExport::SetRepeatAttribute(sal_Int32 nEqualCellCount, bool bIncProgress)
3801{
3802 // nEqualCellCount is additional cells, so the attribute value is nEqualCellCount+1
3803 if (nEqualCellCount > 0)
3804 {
3805 sal_Int32 nTemp(nEqualCellCount + 1);
3806 OUString sOUEqualCellCount(OUString::number(nTemp));
3807 AddAttribute(sAttrColumnsRepeated, sOUEqualCellCount);
3808 if (bIncProgress)
3809 IncrementProgressBar(false, nEqualCellCount);
3810 }
3811}
3812
3814{
3815 return rCell.maBaseCell.getType() == CELLTYPE_EDIT;
3816}
3817
3818bool ScXMLExport::IsCellEqual (const ScMyCell& aCell1, const ScMyCell& aCell2)
3819{
3820 bool bIsEqual = false;
3821 if( !aCell1.bIsMergedBase && !aCell2.bIsMergedBase &&
3822 aCell1.bIsCovered == aCell2.bIsCovered &&
3823 !aCell1.bIsMatrixBase && !aCell2.bIsMatrixBase &&
3824 aCell1.bIsMatrixCovered == aCell2.bIsMatrixCovered &&
3825 aCell1.bHasAnnotation == aCell2.bHasAnnotation &&
3826 !aCell1.bHasShape && !aCell2.bHasShape &&
3827 aCell1.bHasAreaLink == aCell2.bHasAreaLink &&
3828 !aCell1.bHasDetectiveObj && !aCell2.bHasDetectiveObj)
3829 {
3830 if( (aCell1.bHasAreaLink &&
3831 (aCell1.aAreaLink.GetColCount() == 1) &&
3832 (aCell2.aAreaLink.GetColCount() == 1) &&
3833 aCell1.aAreaLink.Compare( aCell2.aAreaLink ) ) ||
3834 !aCell1.bHasAreaLink )
3835 {
3836 if (!aCell1.bHasAnnotation)
3837 {
3838 if ((((aCell1.nStyleIndex == aCell2.nStyleIndex) && (aCell1.bIsAutoStyle == aCell2.bIsAutoStyle)) ||
3839 ((aCell1.nStyleIndex == aCell2.nStyleIndex) && (aCell1.nStyleIndex == -1))) &&
3840 aCell1.nValidationIndex == aCell2.nValidationIndex &&
3841 aCell1.nType == aCell2.nType)
3842 {
3843 switch ( aCell1.nType )
3844 {
3845 case table::CellContentType_EMPTY :
3846 {
3847 bIsEqual = true;
3848 }
3849 break;
3850 case table::CellContentType_VALUE :
3851 {
3852 // #i29101# number format may be different from column default styles,
3853 // but can lead to different value types, so it must also be compared
3854 bIsEqual = (aCell1.nNumberFormat == aCell2.nNumberFormat) &&
3855 (aCell1.maBaseCell.getDouble() == aCell2.maBaseCell.getDouble());
3856 }
3857 break;
3858 case table::CellContentType_TEXT :
3859 {
3860 if (IsEditCell(aCell1) || IsEditCell(aCell2))
3861 bIsEqual = false;
3862 else
3863 {
3864 bIsEqual = (aCell1.maBaseCell.getString(pDoc) == aCell2.maBaseCell.getString(pDoc));
3865 }
3866 }
3867 break;
3868 case table::CellContentType_FORMULA :
3869 {
3870 bIsEqual = false;
3871 }
3872 break;
3873 default :
3874 {
3875 bIsEqual = false;
3876 }
3877 break;
3878 }
3879 }
3880 }
3881 }
3882 }
3883 return bIsEqual;
3884}
3885
3886void ScXMLExport::WriteCalculationSettings(const uno::Reference <sheet::XSpreadsheetDocument>& xSpreadDoc)
3887{
3888 uno::Reference<beans::XPropertySet> xPropertySet(xSpreadDoc, uno::UNO_QUERY);
3889 if (!xPropertySet.is())
3890 return;
3891
3892 bool bCalcAsShown (::cppu::any2bool( xPropertySet->getPropertyValue(SC_UNO_CALCASSHOWN) ));
3893 bool bIgnoreCase (::cppu::any2bool( xPropertySet->getPropertyValue(SC_UNO_IGNORECASE) ));
3894 bool bLookUpLabels (::cppu::any2bool( xPropertySet->getPropertyValue(SC_UNO_LOOKUPLABELS) ));
3895 bool bMatchWholeCell (::cppu::any2bool( xPropertySet->getPropertyValue(SC_UNO_MATCHWHOLE) ));
3896 bool bUseRegularExpressions (::cppu::any2bool( xPropertySet->getPropertyValue(SC_UNO_REGEXENABLED) ));
3897 bool bUseWildcards (::cppu::any2bool( xPropertySet->getPropertyValue(SC_UNO_WILDCARDSENABLED) ));
3898 if (bUseWildcards && bUseRegularExpressions)
3899 bUseRegularExpressions = false; // mutually exclusive, wildcards take precedence
3900 bool bIsIterationEnabled (::cppu::any2bool( xPropertySet->getPropertyValue(SC_UNO_ITERENABLED) ));
3901 sal_uInt16 nYear2000 (pDoc ? pDoc->GetDocOptions().GetYear2000() : 0);
3902 sal_Int32 nIterationCount(100);
3903 xPropertySet->getPropertyValue( SC_UNO_ITERCOUNT ) >>= nIterationCount;
3904 double fIterationEpsilon = 0;
3905 xPropertySet->getPropertyValue( SC_UNO_ITEREPSILON ) >>= fIterationEpsilon;
3906 util::Date aNullDate;
3907 xPropertySet->getPropertyValue( SC_UNO_NULLDATE ) >>= aNullDate;
3908 if (!(bCalcAsShown || bIgnoreCase || !bLookUpLabels || !bMatchWholeCell || !bUseRegularExpressions ||
3909 bUseWildcards ||
3910 bIsIterationEnabled || nIterationCount != 100 || !::rtl::math::approxEqual(fIterationEpsilon, 0.001) ||
3911 aNullDate.Day != 30 || aNullDate.Month != 12 || aNullDate.Year != 1899 || nYear2000 != 1930))
3912 return;
3913
3914 if (bIgnoreCase)
3916 if (bCalcAsShown)
3918 if (!bMatchWholeCell)
3920 if (!bLookUpLabels)
3922 if (!bUseRegularExpressions)
3924 if (bUseWildcards)
3926 if (nYear2000 != 1930)
3927 {
3928 AddAttribute(XML_NAMESPACE_TABLE, XML_NULL_YEAR, OUString::number(nYear2000));
3929 }
3930 SvXMLElementExport aCalcSettings(*this, XML_NAMESPACE_TABLE, XML_CALCULATION_SETTINGS, true, true);
3931 {
3932 if (aNullDate.Day != 30 || aNullDate.Month != 12 || aNullDate.Year != 1899)
3933 {
3934 OUStringBuffer sDate;
3935 SvXMLUnitConverter::convertDateTime(sDate, 0.0, aNullDate);
3936 AddAttribute(XML_NAMESPACE_TABLE, XML_DATE_VALUE, sDate.makeStringAndClear());
3937 SvXMLElementExport aElemNullDate(*this, XML_NAMESPACE_TABLE, XML_NULL_DATE, true, true);
3938 }
3939 if (bIsIterationEnabled || nIterationCount != 100 || !::rtl::math::approxEqual(fIterationEpsilon, 0.001))
3940 {
3941 if (bIsIterationEnabled)
3943 if (nIterationCount != 100)
3944 {
3945 AddAttribute(XML_NAMESPACE_TABLE, XML_STEPS, OUString::number(nIterationCount));
3946 }
3947 if (!::rtl::math::approxEqual(fIterationEpsilon, 0.001))
3948 {
3949 OUStringBuffer sBuffer;
3951 fIterationEpsilon);
3952 AddAttribute(XML_NAMESPACE_TABLE, XML_MAXIMUM_DIFFERENCE, sBuffer.makeStringAndClear());
3953 }
3954 SvXMLElementExport aElemIteration(*this, XML_NAMESPACE_TABLE, XML_ITERATION, true, true);
3955 }
3956 }
3957}
3958
3960{
3961 uno::Reference <sheet::XSheetLinkable> xLinkable (xCurrentTable, uno::UNO_QUERY);
3962 if (!(xLinkable.is() && GetModel().is()))
3963 return;
3964
3965 sheet::SheetLinkMode nMode (xLinkable->getLinkMode());
3966 if (nMode == sheet::SheetLinkMode_NONE)
3967 return;
3968
3969 OUString sLink (xLinkable->getLinkUrl());
3970 uno::Reference <beans::XPropertySet> xProps (GetModel(), uno::UNO_QUERY);
3971 if (!xProps.is())
3972 return;
3973
3974 uno::Reference <container::XIndexAccess> xIndex(xProps->getPropertyValue(SC_UNO_SHEETLINKS), uno::UNO_QUERY);
3975 if (!xIndex.is())
3976 return;
3977
3978 sal_Int32 nCount(xIndex->getCount());
3979 if (!nCount)
3980 return;
3981
3982 bool bFound(false);
3983 uno::Reference <beans::XPropertySet> xLinkProps;
3984 for (sal_Int32 i = 0; (i < nCount) && !bFound; ++i)
3985 {
3986 xLinkProps.set(xIndex->getByIndex(i), uno::UNO_QUERY);
3987 if (xLinkProps.is())
3988 {
3989 OUString sNewLink;
3990 if (xLinkProps->getPropertyValue(SC_UNONAME_LINKURL) >>= sNewLink)
3991 bFound = sLink == sNewLink;
3992 }
3993 }
3994 if (!(bFound && xLinkProps.is()))
3995 return;
3996
3997 OUString sFilter;
3998 OUString sFilterOptions;
3999 OUString sTableName (xLinkable->getLinkSheetName());
4000 sal_Int32 nRefresh(0);
4001 xLinkProps->getPropertyValue(SC_UNONAME_FILTER) >>= sFilter;
4002 xLinkProps->getPropertyValue(SC_UNONAME_FILTOPT) >>= sFilterOptions;
4003 xLinkProps->getPropertyValue(SC_UNONAME_REFDELAY) >>= nRefresh;
4004 if (sLink.isEmpty())
4005 return;
4006
4009 if (!sTableName.isEmpty())
4011 if (!sFilter.isEmpty())
4013 if (!sFilterOptions.isEmpty())
4015 if (nMode != sheet::SheetLinkMode_NORMAL)
4017 if( nRefresh )
4018 {
4019 OUStringBuffer sBuffer;
4021 static_cast<double>(nRefresh) / 86400 );
4022 AddAttribute( XML_NAMESPACE_TABLE, XML_REFRESH_DELAY, sBuffer.makeStringAndClear() );
4023 }
4024 SvXMLElementExport aSourceElem(*this, XML_NAMESPACE_TABLE, XML_TABLE_SOURCE, true, true);
4025}
4026
4027// core implementation
4029{
4030 if (!(pDoc && pDoc->IsScenario(static_cast<SCTAB>(nCurrentTable))))
4031 return;
4032
4033 OUString sComment;
4034 Color aColor;
4035 ScScenarioFlags nFlags;
4036 pDoc->GetScenarioData(static_cast<SCTAB>(nCurrentTable), sComment, aColor, nFlags);
4037 if (!(nFlags & ScScenarioFlags::ShowFrame))
4039 OUStringBuffer aBuffer;
4042 if (!(nFlags & ScScenarioFlags::TwoWay))
4044 if (!(nFlags & ScScenarioFlags::Attrib))
4046 if (nFlags & ScScenarioFlags::Value)
4048 if (nFlags & ScScenarioFlags::Protected)
4051 pDoc->IsActiveScenario(static_cast<SCTAB>(nCurrentTable)));
4052 AddAttribute(XML_NAMESPACE_TABLE, XML_IS_ACTIVE, aBuffer.makeStringAndClear());
4053 const ScRangeList* pRangeList = pDoc->GetScenarioRanges(static_cast<SCTAB>(nCurrentTable));
4054 OUString sRangeListStr;
4055 ScRangeStringConverter::GetStringFromRangeList( sRangeListStr, pRangeList, pDoc, FormulaGrammar::CONV_OOO );
4057 if (!sComment.isEmpty())
4059 SvXMLElementExport aElem(*this, XML_NAMESPACE_TABLE, XML_SCENARIO, true, true);
4060}
4061
4062void ScXMLExport::WriteTheLabelRanges( const uno::Reference< sheet::XSpreadsheetDocument >& xSpreadDoc )
4063{
4064 uno::Reference< beans::XPropertySet > xDocProp( xSpreadDoc, uno::UNO_QUERY );
4065 if( !xDocProp.is() ) return;
4066
4067 sal_Int32 nCount(0);
4068 uno::Reference< container::XIndexAccess > xColRangesIAccess(xDocProp->getPropertyValue( SC_UNO_COLLABELRNG ), uno::UNO_QUERY);
4069 if( xColRangesIAccess.is() )
4070 nCount += xColRangesIAccess->getCount();
4071
4072 uno::Reference< container::XIndexAccess > xRowRangesIAccess(xDocProp->getPropertyValue( SC_UNO_ROWLABELRNG ), uno::UNO_QUERY);
4073 if( xRowRangesIAccess.is() )
4074 nCount += xRowRangesIAccess->getCount();
4075
4076 if( nCount )
4077 {
4078 SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE, XML_LABEL_RANGES, true, true );
4079 WriteLabelRanges( xColRangesIAccess, true );
4080 WriteLabelRanges( xRowRangesIAccess, false );
4081 }
4082}
4083
4084void ScXMLExport::WriteLabelRanges( const uno::Reference< container::XIndexAccess >& xRangesIAccess, bool bColumn )
4085{
4086 if( !xRangesIAccess.is() ) return;
4087
4088 sal_Int32 nCount(xRangesIAccess->getCount());
4089 for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex )
4090 {
4091 uno::Reference< sheet::XLabelRange > xRange(xRangesIAccess->getByIndex( nIndex ), uno::UNO_QUERY);
4092 if( xRange.is() )
4093 {
4094 OUString sRangeStr;
4095 table::CellRangeAddress aCellRange( xRange->getLabelArea() );
4096 ScRangeStringConverter::GetStringFromRange( sRangeStr, aCellRange, pDoc, FormulaGrammar::CONV_OOO );
4098 aCellRange = xRange->getDataArea();
4099 ScRangeStringConverter::GetStringFromRange( sRangeStr, aCellRange, pDoc, FormulaGrammar::CONV_OOO );
4102 SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE, XML_LABEL_RANGE, true, true );
4103 }
4104 }
4105}
4106
4108{
4109 if (!pDoc)
4110 return;
4111 ScRangeName* pNamedRanges = pDoc->GetRangeName();
4112 WriteNamedRange(pNamedRanges);
4113}
4114
4116{
4117 if (!pDoc)
4118 return;
4119
4121 // Export this only for 1.2 extended and above.
4122 return;
4123
4125 auto& rDataSources = rDataMapper.getDataSources();
4126
4127 if (rDataSources.empty())
4128 return;
4129
4130 SvXMLElementExport aMappings(*this, XML_NAMESPACE_CALC_EXT, XML_DATA_MAPPINGS, true, true);
4131 for (const auto& itr : rDataSources)
4132 {
4138
4139 SvXMLElementExport aMapping(*this, XML_NAMESPACE_CALC_EXT, XML_DATA_MAPPING, true, true);
4140 // Add the data transformations
4141 WriteExternalDataTransformations(itr.getDataTransformation());
4142 }
4143}
4144
4145void ScXMLExport::WriteExternalDataTransformations(const std::vector<std::shared_ptr<sc::DataTransformation>>& aDataTransformations)
4146{
4147 SvXMLElementExport aTransformations(*this, XML_NAMESPACE_CALC_EXT, XML_DATA_TRANSFORMATIONS, true, true);
4148 for (auto& itr : aDataTransformations)
4149 {
4150 sc::TransformationType aTransformationType = itr->getTransformationType();
4151
4152 switch(aTransformationType)
4153 {
4155 {
4156 // Delete Columns Transformation
4157 std::shared_ptr<sc::ColumnRemoveTransformation> aDeleteTransformation = std::dynamic_pointer_cast<sc::ColumnRemoveTransformation>(itr);
4158 std::set<SCCOL> aColumns = aDeleteTransformation->getColumns();
4160 for(auto& col : aColumns)
4161 {
4162 // Add Columns
4164 SvXMLElementExport aCol(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN, true, true);
4165 }
4166 }
4167 break;
4169 {
4170 std::shared_ptr<sc::SplitColumnTransformation> aSplitTransformation = std::dynamic_pointer_cast<sc::SplitColumnTransformation>(itr);
4171
4172 AddAttribute(XML_NAMESPACE_CALC_EXT, XML_COLUMN, OUString::number(aSplitTransformation->getColumn()));
4173 AddAttribute(XML_NAMESPACE_CALC_EXT, XML_SEPARATOR, OUString::number(aSplitTransformation->getSeparator()));
4175 }
4176 break;
4178 {
4179 // Merge Transformation
4180 std::shared_ptr<sc::MergeColumnTransformation> aMergeTransformation = std::dynamic_pointer_cast<sc::MergeColumnTransformation>(itr);
4181 std::set<SCCOL> aColumns = aMergeTransformation->getColumns();
4182
4183 AddAttribute(XML_NAMESPACE_CALC_EXT, XML_MERGE_STRING, aMergeTransformation->getMergeString());
4185
4186 for(auto& col : aColumns)
4187 {
4188 // Columns
4190 SvXMLElementExport aCol(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN, true, true);
4191 }
4192 }
4193 break;
4195 {
4196 // Sort Transformation
4197 std::shared_ptr<sc::SortTransformation> aSortTransformation = std::dynamic_pointer_cast<sc::SortTransformation>(itr);
4198 ScSortParam aSortParam = aSortTransformation->getSortParam();
4200 const sc::DataStream* pStrm = rMgr.getDataStream();
4201 if (!pStrm)
4202 // No data stream.
4203 return;
4204
4205 // Streamed range
4206 ScRange aRange = pStrm->GetRange();
4207
4209
4210 writeSort(*this, aSortParam, aRange, pDoc);
4211 }
4212 break;
4214 {
4215 // Text Transformation
4216 std::shared_ptr<sc::TextTransformation> aTextTransformation = std::dynamic_pointer_cast<sc::TextTransformation>(itr);
4217
4218 sc::TEXT_TRANSFORM_TYPE aTextTransformType = aTextTransformation->getTextTransformationType();
4219
4220 switch ( aTextTransformType )
4221 {
4224 break;
4227 break;
4230 break;
4233 break;
4234 }
4235
4236 std::set<SCCOL> aColumns = aTextTransformation->getColumns();
4237
4239
4240 for(auto& col : aColumns)
4241 {
4242 // Columns
4244 SvXMLElementExport aCol(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN, true, true);
4245 }
4246 }
4247 break;
4249 {
4250 // Aggregate Transformation
4251 std::shared_ptr<sc::AggregateFunction> aAggregateFunction = std::dynamic_pointer_cast<sc::AggregateFunction>(itr);
4252 std::set<SCCOL> aColumns = aAggregateFunction->getColumns();
4253
4254 sc::AGGREGATE_FUNCTION aAggregateType = aAggregateFunction->getAggregateType();
4255
4256 switch (aAggregateType)
4257 {
4260 break;
4263 break;
4266 break;
4269 break;
4270 }
4271
4273
4274 for(auto& col : aColumns)
4275 {
4276 // Columns
4278 SvXMLElementExport aCol(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN, true, true);
4279 }
4280 }
4281 break;
4283 {
4284 // Number Transformation
4285 std::shared_ptr<sc::NumberTransformation> aNumberTransformation = std::dynamic_pointer_cast<sc::NumberTransformation>(itr);
4286
4287 sc::NUMBER_TRANSFORM_TYPE aNumberTransformType = aNumberTransformation->getNumberTransformationType();
4288
4289 switch ( aNumberTransformType )
4290 {
4293 break;
4296 break;
4299 break;
4302 break;
4305 break;
4308 break;
4311 break;
4314 break;
4317 break;
4320 break;
4323 break;
4326 break;
4329 break;
4330 }
4331
4332 AddAttribute(XML_NAMESPACE_CALC_EXT, XML_PRECISION, OUString::number(aNumberTransformation->getPrecision()));
4334
4335 std::set<SCCOL> aColumns = aNumberTransformation->getColumn();
4336 for(auto& col : aColumns)
4337 {
4338 // Columns
4340 SvXMLElementExport aCol(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN, true, true);
4341 }
4342 }
4343 break;
4345 {
4346 // Replace Null Transformation
4347 std::shared_ptr<sc::ReplaceNullTransformation> aReplaceNullTransformation = std::dynamic_pointer_cast<sc::ReplaceNullTransformation>(itr);
4348 std::set<SCCOL> aColumns = aReplaceNullTransformation->getColumn();
4349
4350 AddAttribute(XML_NAMESPACE_CALC_EXT, XML_REPLACE_STRING, aReplaceNullTransformation->getReplaceString());
4352
4353 for(auto& col : aColumns)
4354 {
4355 // Columns
4357 SvXMLElementExport aCol(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN, true, true);
4358 }
4359 }
4360 break;
4362 {
4363 // Number Transformation
4364 std::shared_ptr<sc::DateTimeTransformation> aDateTimeTransformation = std::dynamic_pointer_cast<sc::DateTimeTransformation>(itr);
4365
4366 sc::DATETIME_TRANSFORMATION_TYPE aDateTimeTransformationType = aDateTimeTransformation->getDateTimeTransformationType();
4367
4368 switch ( aDateTimeTransformationType )
4369 {
4372 break;
4375 break;
4378 break;
4381 break;
4384 break;
4387 break;
4390 break;
4393 break;
4396 break;
4399 break;
4402 break;
4405 break;
4408 break;
4411 break;
4414 break;
4417 break;
4420 break;
4423 break;
4424 }
4425
4427
4428 std::set<SCCOL> aColumns = aDateTimeTransformation->getColumn();
4429 for(auto& col : aColumns)
4430 {
4431 // Columns
4433 SvXMLElementExport aCol(*this, XML_NAMESPACE_CALC_EXT, XML_COLUMN, true, true);
4434 }
4435 }
4436 break;
4437 default:
4438 break;
4439 }
4440 }
4441}
4442
4444{
4445 if (!pDoc)
4446 return;
4447
4448 if (!officecfg::Office::Common::Misc::ExperimentalMode::get())
4449 // Export this only in experimental mode.
4450 return;
4451
4453 // Export this only for 1.2 extended and above.
4454 return;
4455
4457 const sc::DataStream* pStrm = rMgr.getDataStream();
4458 if (!pStrm)
4459 // No data stream.
4460 return;
4461
4462 // Source URL
4464
4465 // Streamed range
4466 ScRange aRange = pStrm->GetRange();
4467 OUString aRangeStr;
4469 aRangeStr, aRange, pDoc, formula::FormulaGrammar::CONV_OOO);
4471
4472 // Empty line refresh option.
4474
4475 // New data insertion position. Either top of bottom. Default to bottom.
4476 xmloff::token::XMLTokenEnum eInsertPosition = XML_BOTTOM;
4477 if (pStrm->GetMove() == sc::DataStream::MOVE_DOWN)
4478 eInsertPosition = XML_TOP;
4479
4481
4483}
4484
4486{
4487 //write a global or local ScRangeName
4488 SvXMLElementExport aElemNEs(*this, XML_NAMESPACE_TABLE, XML_NAMED_EXPRESSIONS, true, true);
4489 for (const auto& rxEntry : *pRangeName)
4490 {
4491 AddAttribute(sAttrName, rxEntry.second->GetName());
4492
4493 OUString sBaseCellAddress;
4494 rxEntry.second->ValidateTabRefs();
4495 ScRangeStringConverter::GetStringFromAddress( sBaseCellAddress, rxEntry.second->GetPos(), pDoc,
4496 FormulaGrammar::CONV_OOO, ' ', false, ScRefFlags::ADDR_ABS_3D);
4497 assert(!sBaseCellAddress.isEmpty());
4499
4500 OUString sSymbol = rxEntry.second->GetSymbol(pDoc->GetStorageGrammar());
4501 OUString sTempSymbol(sSymbol);
4502 ScRange aRange;
4503 if (rxEntry.second->IsReference(aRange))
4504 {
4505
4506 OUString sContent(sTempSymbol.copy(1, sTempSymbol.getLength() -2 ));
4508
4509 sal_Int32 nRangeType = rxEntry.second->GetUnoType();
4510 OUStringBuffer sBufferRangeType;
4512 sBufferRangeType.append(GetXMLToken(XML_REPEAT_COLUMN));
4514 {
4515 if (!sBufferRangeType.isEmpty())
4516 sBufferRangeType.append(" ");
4517 sBufferRangeType.append(GetXMLToken(XML_REPEAT_ROW));
4518 }
4519 if ((nRangeType & sheet::NamedRangeFlag::FILTER_CRITERIA) == sheet::NamedRangeFlag::FILTER_CRITERIA)
4520 {
4521 if (!sBufferRangeType.isEmpty())
4522 sBufferRangeType.append(" ");
4523 sBufferRangeType.append(GetXMLToken(XML_FILTER));
4524 }
4525 if ((nRangeType & sheet::NamedRangeFlag::PRINT_AREA) == sheet::NamedRangeFlag::PRINT_AREA)
4526 {
4527 if (!sBufferRangeType.isEmpty())
4528 sBufferRangeType.append(" ");
4529 sBufferRangeType.append(GetXMLToken(XML_PRINT_RANGE));
4530 }
4531 OUString sRangeType = sBufferRangeType.makeStringAndClear();
4532 if (!sRangeType.isEmpty())
4534 SvXMLElementExport aElemNR(*this, XML_NAMESPACE_TABLE, XML_NAMED_RANGE, true, true);
4535
4536 }
4537 else
4538 {
4540 SvXMLElementExport aElemNE(*this, XML_NAMESPACE_TABLE, XML_NAMED_EXPRESSION, true, true);
4541 }
4542 }
4543}
4544
4546{
4547 sc::SparklineGroupsExport aSparklineGroupExport(*this, nTable);
4548 aSparklineGroupExport.write();
4549}
4550
4551namespace {
4552
4553OUString getCondFormatEntryType(const ScColorScaleEntry& rEntry, bool bFirst = true)
4554{
4555 switch(rEntry.GetType())
4556 {
4557 case COLORSCALE_MIN:
4558 return "minimum";
4559 case COLORSCALE_MAX:
4560 return "maximum";
4561 case COLORSCALE_PERCENT:
4562 return "percent";
4564 return "percentile";
4565 case COLORSCALE_FORMULA:
4566 return "formula";
4567 case COLORSCALE_VALUE:
4568 return "number";
4569 case COLORSCALE_AUTO:
4570 // only important for data bars
4571 if(bFirst)
4572 return "auto-minimum";
4573 else
4574 return "auto-maximum";
4575 }
4576 return OUString();
4577}
4578
4579OUString getDateStringForType(condformat::ScCondFormatDateType eType)
4580{
4581 switch(eType)
4582 {
4583 case condformat::TODAY:
4584 return "today";
4586 return "yesterday";
4588 return "tomorrow";
4590 return "last-7-days";
4592 return "this-week";
4594 return "last-week";
4596 return "next-week";
4598 return "this-month";
4600 return "last-month";
4602 return "next-month";
4604 return "this-year";
4606 return "last-year";
4608 return "next-year";
4609 }
4610
4611 return OUString();
4612}
4613
4614}
4615
4617{
4618 ScConditionalFormatList* pCondFormatList = pDoc->GetCondFormList(nTab);
4619 if(!pCondFormatList)
4620 return;
4621
4622 if (pCondFormatList->empty())
4623 return;
4624
4625 SvXMLElementExport aElementCondFormats(*this, XML_NAMESPACE_CALC_EXT, XML_CONDITIONAL_FORMATS, true, true);
4626
4627 for(const auto& rxCondFormat : *pCondFormatList)
4628 {
4629 OUString sRanges;
4630 const ScRangeList& rRangeList = rxCondFormat->GetRange();