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