LibreOffice Module sc (master)  1
xmlimprt.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 #include <osl/diagnose.h>
23 
24 #include <svl/numformat.hxx>
25 
26 #include <xmloff/namespacemap.hxx>
27 #include <xmloff/xmlnamespace.hxx>
28 #include <xmloff/xmlictxt.hxx>
29 #include <xmloff/xmlmetai.hxx>
30 #include <sfx2/objsh.hxx>
31 #include <unotools/streamwrap.hxx>
32 #include <xmloff/xmlscripti.hxx>
35 #include <xmloff/xmluconv.hxx>
36 #include <xmloff/numehelp.hxx>
37 #include <xmloff/xmltoken.hxx>
38 #include <xmloff/xmlerror.hxx>
40 #include <svx/svdpage.hxx>
41 
42 #include <svl/languageoptions.hxx>
43 #include <editeng/editstat.hxx>
44 #include <formula/errorcodes.hxx>
45 #include <vcl/svapp.hxx>
46 
47 #include <appluno.hxx>
48 #include "xmlimprt.hxx"
49 #include "importcontext.hxx"
50 #include <document.hxx>
51 #include <docsh.hxx>
52 #include <docuno.hxx>
53 #include "xmlbodyi.hxx"
54 #include "xmlstyli.hxx"
56 #include <userdat.hxx>
57 
58 #include <compiler.hxx>
59 
60 #include "XMLConverter.hxx"
61 #include "XMLDetectiveContext.hxx"
64 #include <chgviset.hxx>
66 #include <sheetdata.hxx>
67 #include <rangeutl.hxx>
68 #include <formulaparserpool.hxx>
69 #include <externalrefmgr.hxx>
70 #include <editutil.hxx>
71 #include "editattributemap.hxx"
72 #include <documentimport.hxx>
73 #include "pivotsource.hxx"
74 #include <unonames.hxx>
75 #include <numformat.hxx>
76 #include <sizedev.hxx>
77 #include <scdll.hxx>
78 #include "xmlstyle.hxx"
79 
80 #include <comphelper/base64.hxx>
81 #include <comphelper/extract.hxx>
84 
85 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
86 #include <com/sun/star/frame/XModel.hpp>
87 #include <com/sun/star/io/IOException.hpp>
88 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
89 #include <com/sun/star/document/XActionLockable.hpp>
90 #include <com/sun/star/util/MalformedNumberFormatException.hpp>
91 #include <com/sun/star/util/NumberFormat.hpp>
92 #include <com/sun/star/util/XNumberFormatTypes.hpp>
93 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
94 #include <com/sun/star/sheet/NamedRangeFlag.hpp>
95 #include <com/sun/star/sheet/XLabelRanges.hpp>
96 #include <com/sun/star/io/XSeekable.hpp>
97 #include <com/sun/star/beans/XPropertySet.hpp>
98 #include <com/sun/star/sheet/XSheetCellRangeContainer.hpp>
99 #include <cellsuno.hxx>
100 
101 #include <memory>
102 #include <utility>
103 
104 constexpr OUStringLiteral SC_LOCALE = u"Locale";
105 constexpr OUStringLiteral SC_CURRENCYSYMBOL = u"CurrencySymbol";
106 constexpr OUStringLiteral SC_REPEAT_ROW = u"repeat-row";
107 constexpr OUStringLiteral SC_FILTER = u"filter";
108 constexpr OUStringLiteral SC_PRINT_RANGE = u"print-range";
109 
110 using namespace com::sun::star;
111 using namespace ::xmloff::token;
112 using namespace ::formula;
113 
114 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
116  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
117 {
118  return cppu::acquire(
119  new ScXMLImport(
120  context,
121  "com.sun.star.comp.Calc.XMLOasisImporter",
122  SvXMLImportFlags::ALL,
123  { "com.sun.star.comp.Calc.XMLOasisImporter" } ));
124 }
125 
126 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
128  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
129 {
130  return cppu::acquire(
131  new ScXMLImport(
132  context,
133  "com.sun.star.comp.Calc.XMLOasisMetaImporter",
134  SvXMLImportFlags::META,
135  { "com.sun.star.comp.Calc.XMLOasisMetaImporter" } ));
136 }
137 
138 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
140  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
141 {
142  return cppu::acquire(
143  new ScXMLImport(
144  context,
145  "com.sun.star.comp.Calc.XMLOasisStylesImporter",
146  SvXMLImportFlags::STYLES|SvXMLImportFlags::AUTOSTYLES|SvXMLImportFlags::MASTERSTYLES|SvXMLImportFlags::FONTDECLS,
147  { "com.sun.star.comp.Calc.XMLOasisStylesImporter" } ));
148 }
149 
150 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
152  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
153 {
154  return cppu::acquire(new ScXMLImport(
155  context,
156  "com.sun.star.comp.Calc.XMLOasisContentImporter",
157  SvXMLImportFlags::AUTOSTYLES|SvXMLImportFlags::CONTENT|SvXMLImportFlags::SCRIPTS|SvXMLImportFlags::FONTDECLS,
158  uno::Sequence< OUString > { "com.sun.star.comp.Calc.XMLOasisContentImporter" }));
159 }
160 
161 
162 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
164  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
165 {
166  return cppu::acquire(
167  new ScXMLImport(
168  context,
169  "com.sun.star.comp.Calc.XMLOasisSettingsImporter",
170  SvXMLImportFlags::SETTINGS,
171  { "com.sun.star.comp.Calc.XMLOasisSettingsImporter" } ));
172 }
173 
174 namespace {
175 
176 // NB: virtually inherit so we can multiply inherit properly
177 // in ScXMLFlatDocContext_Impl
178 class ScXMLDocContext_Impl : public virtual SvXMLImportContext
179 {
180 protected:
181  ScXMLImport& GetScImport() { return static_cast<ScXMLImport&>(GetImport()); }
182 
183 public:
184  ScXMLDocContext_Impl( ScXMLImport& rImport );
185 
186  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL
187  createFastChildContext( sal_Int32 nElement,
188  const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList ) override;
189 };
190 
191 }
192 
193 ScXMLDocContext_Impl::ScXMLDocContext_Impl( ScXMLImport& rImport ) :
194 SvXMLImportContext( rImport )
195 {
196 }
197 
198 namespace {
199 
200 // context for flat file xml format
201 class ScXMLFlatDocContext_Impl
202  : public ScXMLDocContext_Impl, public SvXMLMetaDocumentContext
203 {
204 public:
205 
206  ScXMLFlatDocContext_Impl( ScXMLImport& i_rImport,
207  const uno::Reference<document::XDocumentProperties>& i_xDocProps);
208 
209  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL
210  createFastChildContext( sal_Int32 nElement,
211  const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList ) override;
212 };
213 
214 }
215 
216 ScXMLFlatDocContext_Impl::ScXMLFlatDocContext_Impl( ScXMLImport& i_rImport,
217  const uno::Reference<document::XDocumentProperties>& i_xDocProps) :
218 SvXMLImportContext(i_rImport),
219 ScXMLDocContext_Impl(i_rImport),
220 SvXMLMetaDocumentContext(i_rImport, i_xDocProps)
221 {
222 }
223 
224 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
225  ScXMLFlatDocContext_Impl::createFastChildContext( sal_Int32 nElement,
226  const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
227 {
228  if ( nElement == XML_ELEMENT( OFFICE, XML_META ) )
229  return SvXMLMetaDocumentContext::createFastChildContext( nElement, xAttrList );
230  else
231  return ScXMLDocContext_Impl::createFastChildContext( nElement, xAttrList );
232 }
233 
234 namespace {
235 
236 class ScXMLBodyContext_Impl : public ScXMLImportContext
237 {
238 public:
239  ScXMLBodyContext_Impl( ScXMLImport& rImport );
240 
241  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL
242  createFastChildContext( sal_Int32 nElement,
243  const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList ) override;
244 };
245 
246 }
247 
248 ScXMLBodyContext_Impl::ScXMLBodyContext_Impl( ScXMLImport& rImport ) :
249 ScXMLImportContext( rImport )
250 {
251 }
252 
253 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
254  ScXMLBodyContext_Impl::createFastChildContext( sal_Int32 /*nElement*/,
255  const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
256 {
257  sax_fastparser::FastAttributeList *pAttribList =
259  return GetScImport().CreateBodyContext( pAttribList );
260 }
261 
262 uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
263  ScXMLDocContext_Impl::createFastChildContext( sal_Int32 nElement,
264  const uno::Reference< xml::sax::XFastAttributeList > & /*xAttrList*/ )
265 {
266  SvXMLImportContext *pContext(nullptr);
267 
268  switch( nElement )
269  {
270  case XML_ELEMENT( OFFICE, XML_BODY ):
271  if (GetScImport().getImportFlags() & SvXMLImportFlags::CONTENT)
272  pContext = new ScXMLBodyContext_Impl( GetScImport() );
273  break;
274  case XML_ELEMENT( OFFICE, XML_SCRIPTS ):
275  if (GetScImport().getImportFlags() & SvXMLImportFlags::SCRIPTS)
276  pContext = GetScImport().CreateScriptContext();
277  break;
278  case XML_ELEMENT( OFFICE, XML_SETTINGS ):
279  if (GetScImport().getImportFlags() & SvXMLImportFlags::SETTINGS)
280  pContext = new XMLDocumentSettingsContext(GetScImport());
281  break;
282  case XML_ELEMENT(OFFICE, XML_STYLES):
283  if (GetScImport().getImportFlags() & SvXMLImportFlags::STYLES)
284  pContext = GetScImport().CreateStylesContext( false);
285  break;
286  case XML_ELEMENT(OFFICE, XML_AUTOMATIC_STYLES):
287  if (GetScImport().getImportFlags() & SvXMLImportFlags::AUTOSTYLES)
288  pContext = GetScImport().CreateStylesContext( true);
289  break;
290  case XML_ELEMENT(OFFICE, XML_FONT_FACE_DECLS):
291  if (GetScImport().getImportFlags() & SvXMLImportFlags::FONTDECLS)
292  pContext = GetScImport().CreateFontDeclsContext();
293  break;
294  case XML_ELEMENT(OFFICE, XML_MASTER_STYLES):
295  if (GetScImport().getImportFlags() & SvXMLImportFlags::MASTERSTYLES)
296  pContext = new ScXMLMasterStylesContext( GetImport() );
297  break;
298  case XML_ELEMENT(OFFICE, XML_META):
299  SAL_INFO("sc", "XML_ELEMENT(OFFICE, XML_META): should not have come here, maybe document is invalid?");
300  break;
301  }
302 
303  return pContext;
304 }
305 
306 
308 {
309  mpPostProcessData = p;
310 }
311 
313 {
314  if (!mpPivotSources)
316 
317  return *mpPivotSources;
318 }
319 
321  const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
322 {
323  SvXMLImportContext *pContext = nullptr;
324 
325  switch( nElement )
326  {
330  pContext = new ScXMLDocContext_Impl( *this );
331  break;
332 
334  pContext = CreateMetaContext(nElement);
335  break;
336 
338  {
339  uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
340  GetModel(), uno::UNO_QUERY_THROW);
341  // flat OpenDocument file format
342  pContext = new ScXMLFlatDocContext_Impl( *this,
343  xDPS->getDocumentProperties());
344  break;
345  }
346 
347  }
348 
349  return pContext;
350 }
351 
353  const css::uno::Reference< css::uno::XComponentContext >& rContext,
354  OUString const & implementationName, SvXMLImportFlags nImportFlag,
355  const css::uno::Sequence< OUString > & sSupportedServiceNames)
356 : SvXMLImport( rContext, implementationName, nImportFlag, sSupportedServiceNames ),
357  pDoc( nullptr ),
358  mpPostProcessData(nullptr),
359  aTables(*this),
360  nSolarMutexLocked(0),
361  nProgressCount(0),
362  nPrevCellType(0),
363  bLoadDoc( true ),
364  bNullDateSetted(false),
365  bSelfImportingXMLSet(false),
366  mbLockSolarMutex(true),
367  mbImportStyles(true),
368  mbHasNewCondFormatData(false)
369 {
371 
377 
378  // #i66550# needed for 'presentation:event-listener' element for URLs in shapes
383 }
384 
386 {
389  pStyleNumberFormats.reset();
390  pStylesImportHelper.reset();
391 
392  m_aMyNamedExpressions.clear();
393  maMyLabelRanges.clear();
394  maValidations.clear();
395  pDetectiveOpArray.reset();
396 
397  //call SvXMLImport dtor contents before deleting pSolarMutexGuard
398  cleanup();
399 
400  pSolarMutexGuard.reset();
401 }
402 
403 void ScXMLImport::initialize( const css::uno::Sequence<css::uno::Any>& aArguments )
404 {
405  SvXMLImport::initialize(aArguments);
406 
407  uno::Reference<beans::XPropertySet> xInfoSet = getImportInfo();
408  if (!xInfoSet.is())
409  return;
410 
411  uno::Reference<beans::XPropertySetInfo> xInfoSetInfo = xInfoSet->getPropertySetInfo();
412  if (!xInfoSetInfo.is())
413  return;
414 
415  if (xInfoSetInfo->hasPropertyByName(SC_UNO_ODS_LOCK_SOLAR_MUTEX))
416  xInfoSet->getPropertyValue(SC_UNO_ODS_LOCK_SOLAR_MUTEX) >>= mbLockSolarMutex;
417 
418  if (xInfoSetInfo->hasPropertyByName(SC_UNO_ODS_IMPORT_STYLES))
419  xInfoSet->getPropertyValue(SC_UNO_ODS_IMPORT_STYLES) >>= mbImportStyles;
420 }
421 
423 {
424  XMLFontStylesContext *pFSContext = new XMLFontStylesContext(
425  *this, osl_getThreadTextEncoding());
426  SetFontDecls(pFSContext);
427  SvXMLImportContext* pContext = pFSContext;
428  return pContext;
429 }
430 
432 {
434  *this, bIsAutoStyle);
435 
436  if (bIsAutoStyle)
437  SetAutoStyles(static_cast<SvXMLStylesContext*>(pContext));
438  else
439  SetStyles(static_cast<SvXMLStylesContext*>(pContext));
440 
441  return pContext;
442 }
443 
445 {
446  return new ScXMLBodyContext(*this, rAttrList);
447 }
448 
450  const sal_Int32 /*nElement*/ )
451 {
452  SvXMLImportContext* pContext = nullptr;
453 
454  if (getImportFlags() & SvXMLImportFlags::META)
455  {
456  uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
457  GetModel(), uno::UNO_QUERY_THROW);
458  uno::Reference<document::XDocumentProperties> const xDocProps(
459  (IsStylesOnlyMode()) ? nullptr : xDPS->getDocumentProperties());
460  pContext = new SvXMLMetaDocumentContext(*this, xDocProps);
461  }
462 
463  return pContext;
464 }
465 
467 {
468  SvXMLImportContext* pContext = nullptr;
469 
470  if( !(IsStylesOnlyMode()) )
471  {
472  pContext = new XMLScriptContext( *this, GetModel() );
473  }
474 
475  return pContext;
476 }
477 
478 void ScXMLImport::SetStatistics(const uno::Sequence<beans::NamedValue> & i_rStats)
479 {
480  static const char* s_stats[] =
481  { "TableCount", "CellCount", "ObjectCount", nullptr };
482 
483  SvXMLImport::SetStatistics(i_rStats);
484 
485  sal_uInt64 nCount(0);
486  for (const auto& rStat : i_rStats) {
487  for (const char** pStat = s_stats; *pStat != nullptr; ++pStat) {
488  if (rStat.Name.equalsAscii(*pStat)) {
489  sal_Int32 val = 0;
490  if (rStat.Value >>= val) {
491  nCount += val;
492  } else {
493  OSL_FAIL("ScXMLImport::SetStatistics: invalid entry");
494  }
495  }
496  }
497  }
498 
499  if (nCount)
500  {
503  }
504 }
505 
507 {
508  return *mpDocImport;
509 }
510 
511 sal_Int16 ScXMLImport::GetCellType(const char* rStrValue, const sal_Int32 nStrLength)
512 {
513  sal_Int16 nCellType = util::NumberFormat::UNDEFINED;
514  if (rStrValue != nullptr)
515  {
516  switch (rStrValue[0])
517  {
518  case 'b':
519  if (nStrLength == 7 && !strcmp(rStrValue, "boolean"))
520  nCellType = util::NumberFormat::LOGICAL;
521  break;
522  case 'c':
523  if (nStrLength == 8 && !strcmp(rStrValue, "currency"))
524  nCellType = util::NumberFormat::CURRENCY;
525  break;
526  case 'd':
527  if (nStrLength == 4 && !strcmp(rStrValue, "date"))
528  nCellType = util::NumberFormat::DATETIME;
529  break;
530  case 'f':
531  if (nStrLength == 5 && !strcmp(rStrValue, "float"))
532  nCellType = util::NumberFormat::NUMBER;
533  break;
534  case 'p':
535  if (nStrLength == 10 && !strcmp(rStrValue, "percentage"))
536  nCellType = util::NumberFormat::PERCENT;
537  break;
538  case 's':
539  if (nStrLength == 6 && !strcmp(rStrValue, "string"))
540  nCellType = util::NumberFormat::TEXT;
541  break;
542  case 't':
543  if (nStrLength == 4 && !strcmp(rStrValue, "time"))
544  nCellType = util::NumberFormat::TIME;
545  break;
546  }
547  }
548 
549  return nCellType;
550 }
551 
553 {
554  return new XMLTableShapeImportHelper(*this);
555 }
556 
557 bool ScXMLImport::GetValidation(const OUString& sName, ScMyImportValidation& aValidation)
558 {
559  auto aItr = std::find_if(maValidations.begin(), maValidations.end(),
560  [&sName](const ScMyImportValidation& rValidation) { return rValidation.sName == sName; });
561  if (aItr != maValidations.end())
562  {
563  // source position must be set as string,
564  // so sBaseCellAddress no longer has to be converted here
565  aValidation = *aItr;
566  return true;
567  }
568  return false;
569 }
570 
572 {
573  SheetNamedExpMap::iterator itr = m_SheetNamedExpressions.find(nTab);
574  if (itr == m_SheetNamedExpressions.end())
575  {
576  // No chain exists for this sheet. Create one.
577  ::std::pair<SheetNamedExpMap::iterator, bool> r =
578  m_SheetNamedExpressions.insert(std::make_pair(nTab, ScMyNamedExpressions()));
579  if (!r.second)
580  // insertion failed.
581  return;
582 
583  itr = r.first;
584  }
585  ScMyNamedExpressions& r = itr->second;
586  r.push_back(std::move(aNamedExp));
587 }
588 
590 {
593  return pChangeTrackingImportHelper.get();
594 }
595 
597 {
598  GetStyles()->CopyStylesToDoc(true);
599 
600  // if content is going to be loaded with the same import, set bLatinDefaultStyle flag now
601  if ( getImportFlags() & SvXMLImportFlags::CONTENT )
603 }
604 
606 {
607  if (pDoc)
608  {
609  // #i62435# after inserting the styles, check if the default style has a latin-script-only
610  // number format (then, value cells can be pre-initialized with western script type)
611 
612  const ScPatternAttr* pDefPattern = pDoc->GetDefPattern();
613  if (pDefPattern && sc::NumFmtUtil::isLatinScript(*pDefPattern, *pDoc))
614  mpDocImport->setDefaultNumericScript(SvtScriptType::LATIN);
615  }
616 }
617 
618 void ScXMLImport::SetChangeTrackingViewSettings(const css::uno::Sequence<css::beans::PropertyValue>& rChangeProps)
619 {
620  if (!pDoc)
621  return;
622 
623  if (!rChangeProps.hasElements())
624  return;
625 
626  ScXMLImport::MutexGuard aGuard(*this);
627  sal_Int16 nTemp16(0);
628  ScChangeViewSettings aViewSettings;
629  for (const auto& rChangeProp : rChangeProps)
630  {
631  OUString sName(rChangeProp.Name);
632  if (sName == "ShowChanges")
633  aViewSettings.SetShowChanges(::cppu::any2bool(rChangeProp.Value));
634  else if (sName == "ShowAcceptedChanges")
635  aViewSettings.SetShowAccepted(::cppu::any2bool(rChangeProp.Value));
636  else if (sName == "ShowRejectedChanges")
637  aViewSettings.SetShowRejected(::cppu::any2bool(rChangeProp.Value));
638  else if (sName == "ShowChangesByDatetime")
639  aViewSettings.SetHasDate(::cppu::any2bool(rChangeProp.Value));
640  else if (sName == "ShowChangesByDatetimeMode")
641  {
642  if (rChangeProp.Value >>= nTemp16)
643  aViewSettings.SetTheDateMode(static_cast<SvxRedlinDateMode>(nTemp16));
644  }
645  else if (sName == "ShowChangesByDatetimeFirstDatetime")
646  {
647  util::DateTime aDateTime;
648  if (rChangeProp.Value >>= aDateTime)
649  {
650  aViewSettings.SetTheFirstDateTime(::DateTime(aDateTime));
651  }
652  }
653  else if (sName == "ShowChangesByDatetimeSecondDatetime")
654  {
655  util::DateTime aDateTime;
656  if (rChangeProp.Value >>= aDateTime)
657  {
658  aViewSettings.SetTheLastDateTime(::DateTime(aDateTime));
659  }
660  }
661  else if (sName == "ShowChangesByAuthor")
662  aViewSettings.SetHasAuthor(::cppu::any2bool(rChangeProp.Value));
663  else if (sName == "ShowChangesByAuthorName")
664  {
665  OUString sOUName;
666  if (rChangeProp.Value >>= sOUName)
667  {
668  aViewSettings.SetTheAuthorToShow(sOUName);
669  }
670  }
671  else if (sName == "ShowChangesByComment")
672  aViewSettings.SetHasComment(::cppu::any2bool(rChangeProp.Value));
673  else if (sName == "ShowChangesByCommentText")
674  {
675  OUString sOUComment;
676  if (rChangeProp.Value >>= sOUComment)
677  {
678  aViewSettings.SetTheComment(sOUComment);
679  }
680  }
681  else if (sName == "ShowChangesByRanges")
682  aViewSettings.SetHasRange(::cppu::any2bool(rChangeProp.Value));
683  else if (sName == "ShowChangesByRangesList")
684  {
685  OUString sRanges;
686  if ((rChangeProp.Value >>= sRanges) && !sRanges.isEmpty())
687  {
688  ScRangeList aRangeList;
690  aRangeList, sRanges, *pDoc, FormulaGrammar::CONV_OOO);
691  aViewSettings.SetTheRangeList(aRangeList);
692  }
693  }
694  }
695  pDoc->SetChangeViewSettings(aViewSettings);
696 }
697 
698 void ScXMLImport::SetViewSettings(const uno::Sequence<beans::PropertyValue>& aViewProps)
699 {
700  sal_Int32 nHeight(0);
701  sal_Int32 nLeft(0);
702  sal_Int32 nTop(0);
703  sal_Int32 nWidth(0);
704  for (const auto& rViewProp : aViewProps)
705  {
706  OUString sName(rViewProp.Name);
707  if (sName == "VisibleAreaHeight")
708  rViewProp.Value >>= nHeight;
709  else if (sName == "VisibleAreaLeft")
710  rViewProp.Value >>= nLeft;
711  else if (sName == "VisibleAreaTop")
712  rViewProp.Value >>= nTop;
713  else if (sName == "VisibleAreaWidth")
714  rViewProp.Value >>= nWidth;
715  else if (sName == "TrackedChangesViewSettings")
716  {
717  uno::Sequence<beans::PropertyValue> aChangeProps;
718  if(rViewProp.Value >>= aChangeProps)
719  SetChangeTrackingViewSettings(aChangeProps);
720  }
721  }
722  if (!(nHeight && nWidth && GetModel().is()))
723  return;
724 
725  ScModelObj* pDocObj(comphelper::getFromUnoTunnel<ScModelObj>( GetModel() ));
726  if (!pDocObj)
727  return;
728 
729  SfxObjectShell* pEmbeddedObj = pDocObj->GetEmbeddedObject();
730  if (pEmbeddedObj)
731  {
732  tools::Rectangle aRect{ nLeft, nTop };
733  aRect.setWidth( nWidth );
734  aRect.setHeight( nHeight );
735  pEmbeddedObj->SetVisArea(aRect);
736  }
737 }
738 
739 void ScXMLImport::SetConfigurationSettings(const uno::Sequence<beans::PropertyValue>& aConfigProps)
740 {
741  if (!GetModel().is())
742  return;
743 
744  uno::Reference <lang::XMultiServiceFactory> xMultiServiceFactory(GetModel(), uno::UNO_QUERY);
745  if (!xMultiServiceFactory.is())
746  return;
747 
748  sal_Int32 nCount(aConfigProps.getLength());
749  css::uno::Sequence<css::beans::PropertyValue> aFilteredProps(nCount);
750  auto pFilteredProps = aFilteredProps.getArray();
751  sal_Int32 nFilteredPropsLen = 0;
752  for (sal_Int32 i = nCount - 1; i >= 0; --i)
753  {
754  if (aConfigProps[i].Name == "TrackedChangesProtectionKey")
755  {
756  OUString sKey;
757  if (aConfigProps[i].Value >>= sKey)
758  {
759  uno::Sequence<sal_Int8> aPass;
760  ::comphelper::Base64::decode(aPass, sKey);
761  if (aPass.hasElements())
762  {
763  if (pDoc->GetChangeTrack())
764  pDoc->GetChangeTrack()->SetProtection(aPass);
765  else
766  {
767  std::set<OUString> aUsers;
768  std::unique_ptr<ScChangeTrack> pTrack( new ScChangeTrack(*pDoc, std::move(aUsers)) );
769  pTrack->SetProtection(aPass);
770  pDoc->SetChangeTrack(std::move(pTrack));
771  }
772  }
773  }
774  }
775  // store the following items for later use (after document is loaded)
776  else if ((aConfigProps[i].Name == "VBACompatibilityMode") || (aConfigProps[i].Name == "ScriptConfiguration"))
777  {
778  uno::Reference< beans::XPropertySet > xImportInfo = getImportInfo();
779  if (xImportInfo.is())
780  {
781  uno::Reference< beans::XPropertySetInfo > xPropertySetInfo = xImportInfo->getPropertySetInfo();
782  if (xPropertySetInfo.is() && xPropertySetInfo->hasPropertyByName(aConfigProps[i].Name))
783  xImportInfo->setPropertyValue( aConfigProps[i].Name, aConfigProps[i].Value );
784  }
785  }
786  if (aConfigProps[i].Name != "LinkUpdateMode")
787  {
788  pFilteredProps[nFilteredPropsLen++] = aConfigProps[i];
789  }
790  }
791  aFilteredProps.realloc(nFilteredPropsLen);
792  uno::Reference <uno::XInterface> xInterface = xMultiServiceFactory->createInstance("com.sun.star.comp.SpreadsheetSettings");
793  uno::Reference <beans::XPropertySet> xProperties(xInterface, uno::UNO_QUERY);
794  if (xProperties.is())
795  SvXMLUnitConverter::convertPropertySet(xProperties, aFilteredProps);
796 }
797 
798 sal_Int32 ScXMLImport::SetCurrencySymbol(const sal_Int32 nKey, std::u16string_view rCurrency)
799 {
800  uno::Reference <util::XNumberFormatsSupplier> xNumberFormatsSupplier(GetNumberFormatsSupplier());
801  if (xNumberFormatsSupplier.is())
802  {
803  uno::Reference <util::XNumberFormats> xLocalNumberFormats(xNumberFormatsSupplier->getNumberFormats());
804  if (xLocalNumberFormats.is())
805  {
806  OUString sFormatString;
807  try
808  {
809  uno::Reference <beans::XPropertySet> xProperties(xLocalNumberFormats->getByKey(nKey));
810  if (xProperties.is())
811  {
812  lang::Locale aLocale;
813  if (GetDocument() && (xProperties->getPropertyValue(SC_LOCALE) >>= aLocale))
814  {
815  {
816  ScXMLImport::MutexGuard aGuard(*this);
818  sFormatString = "#" +
819  aLocaleData.getNumThousandSep() +
820  "##0" +
821  aLocaleData.getNumDecimalSep() +
822  "00 [$" +
823  rCurrency +
824  "]";
825  }
826  sal_Int32 nNewKey = xLocalNumberFormats->queryKey(sFormatString, aLocale, true);
827  if (nNewKey == -1)
828  nNewKey = xLocalNumberFormats->addNew(sFormatString, aLocale);
829  return nNewKey;
830  }
831  }
832  }
833  catch ( const util::MalformedNumberFormatException& rException )
834  {
835  OUString sErrorMessage ="Error in Formatstring " +
836  sFormatString + " at position " +
837  OUString::number(rException.CheckPos);
838  uno::Sequence<OUString> aSeq { sErrorMessage };
839  uno::Reference<xml::sax::XLocator> xLocator;
840  SetError(XMLERROR_API | XMLERROR_FLAG_ERROR, aSeq, rException.Message, xLocator);
841  }
842  }
843  }
844  return nKey;
845 }
846 
847 bool ScXMLImport::IsCurrencySymbol(const sal_Int32 nNumberFormat, const OUString& sCurrentCurrency, std::u16string_view sBankSymbol)
848 {
849  uno::Reference <util::XNumberFormatsSupplier> xNumberFormatsSupplier(GetNumberFormatsSupplier());
850  if (xNumberFormatsSupplier.is())
851  {
852  uno::Reference <util::XNumberFormats> xLocalNumberFormats(xNumberFormatsSupplier->getNumberFormats());
853  if (xLocalNumberFormats.is())
854  {
855  try
856  {
857  uno::Reference <beans::XPropertySet> xNumberPropertySet(xLocalNumberFormats->getByKey(nNumberFormat));
858  if (xNumberPropertySet.is())
859  {
860  OUString sTemp;
861  if ( xNumberPropertySet->getPropertyValue(SC_CURRENCYSYMBOL) >>= sTemp)
862  {
863  if (sCurrentCurrency == sTemp)
864  return true;
865  // A release that saved an unknown currency may have
866  // saved the currency symbol of the number format
867  // instead of an ISO code bank symbol. In another
868  // release we may have a match for that. In this case
869  // sCurrentCurrency is the ISO code obtained through
870  // XMLNumberFormatAttributesExportHelper::GetCellType()
871  // and sBankSymbol is the currency symbol.
872  if (sCurrentCurrency.getLength() == 3 && sBankSymbol == sTemp)
873  return true;
874  // #i61657# This may be a legacy currency symbol that changed in the meantime.
875  if (SvNumberFormatter::GetLegacyOnlyCurrencyEntry( sCurrentCurrency, sBankSymbol) != nullptr)
876  return true;
877  // In the rare case that sCurrentCurrency is not the
878  // currency symbol, but a matching ISO code
879  // abbreviation instead that was obtained through
880  // XMLNumberFormatAttributesExportHelper::GetCellType(),
881  // check with the number format's symbol. This happens,
882  // for example, in the es_BO locale, where a legacy
883  // B$,BOB matched B$->BOP, which leads to
884  // sCurrentCurrency being BOP, and the previous call
885  // with BOP,BOB didn't find an entry, but B$,BOB will.
886  return SvNumberFormatter::GetLegacyOnlyCurrencyEntry( sTemp, sBankSymbol) != nullptr;
887  }
888  }
889  }
890  catch ( uno::Exception& )
891  {
892  OSL_FAIL("Numberformat not found");
893  }
894  }
895  }
896  return false;
897 }
898 
899 void ScXMLImport::SetType(const uno::Reference <beans::XPropertySet>& rProperties,
900  sal_Int32& rNumberFormat,
901  const sal_Int16 nCellType,
902  std::u16string_view rCurrency)
903 {
904  if (!mbImportStyles)
905  return;
906 
907  if ((nCellType == util::NumberFormat::TEXT) || (nCellType == util::NumberFormat::UNDEFINED))
908  return;
909 
910  if (rNumberFormat == -1)
911  rProperties->getPropertyValue( SC_UNONAME_NUMFMT ) >>= rNumberFormat;
912  OSL_ENSURE(rNumberFormat != -1, "no NumberFormat");
913  bool bIsStandard;
914  // sCurrentCurrency may be the ISO code abbreviation if the currency
915  // symbol matches such, or if no match found the symbol itself!
916  OUString sCurrentCurrency;
917  sal_Int32 nCurrentCellType(
919  rNumberFormat, sCurrentCurrency, bIsStandard) & ~util::NumberFormat::DEFINED);
920  // If the (numeric) cell type (number, currency, date, time, boolean)
921  // is different from the format type then for some combinations we may
922  // have to apply a format, e.g. in case the generator deduced format
923  // from type and did not apply a format but we don't keep a dedicated
924  // type internally. Specifically this is necessary if the cell type is
925  // not number but the format type is (i.e. General). Currency cells
926  // need extra attention, see calls of ScXMLImport::IsCurrencySymbol()
927  // and description within there and ScXMLImport::SetCurrencySymbol().
928  if ((nCellType != nCurrentCellType) &&
929  (nCellType != util::NumberFormat::NUMBER) &&
930  (bIsStandard || (nCellType == util::NumberFormat::CURRENCY)))
931  {
932  if (!xNumberFormats.is())
933  {
934  uno::Reference <util::XNumberFormatsSupplier> xNumberFormatsSupplier(GetNumberFormatsSupplier());
935  if (xNumberFormatsSupplier.is())
936  xNumberFormats.set(xNumberFormatsSupplier->getNumberFormats());
937  }
938  if (xNumberFormats.is())
939  {
940  try
941  {
942  uno::Reference < beans::XPropertySet> xNumberFormatProperties(xNumberFormats->getByKey(rNumberFormat));
943  if (xNumberFormatProperties.is())
944  {
945  if (nCellType != util::NumberFormat::CURRENCY)
946  {
947  lang::Locale aLocale;
948  if ( xNumberFormatProperties->getPropertyValue(SC_LOCALE) >>= aLocale )
949  {
950  if (!xNumberFormatTypes.is())
951  xNumberFormatTypes.set(uno::Reference <util::XNumberFormatTypes>(xNumberFormats, uno::UNO_QUERY));
952  rProperties->setPropertyValue( SC_UNONAME_NUMFMT, uno::Any(xNumberFormatTypes->getStandardFormat(nCellType, aLocale)) );
953  }
954  }
955  else if (!rCurrency.empty() && !sCurrentCurrency.isEmpty())
956  {
957  if (sCurrentCurrency != rCurrency)
958  if (!IsCurrencySymbol(rNumberFormat, sCurrentCurrency, rCurrency))
959  rProperties->setPropertyValue( SC_UNONAME_NUMFMT, uno::Any(SetCurrencySymbol(rNumberFormat, rCurrency)));
960  }
961  }
962  }
963  catch ( uno::Exception& )
964  {
965  OSL_FAIL("Numberformat not found");
966  }
967  }
968  }
969  else
970  {
971  if ((nCellType == util::NumberFormat::CURRENCY) && !rCurrency.empty() && !sCurrentCurrency.isEmpty() &&
972  sCurrentCurrency != rCurrency && !IsCurrencySymbol(rNumberFormat, sCurrentCurrency, rCurrency))
973  rProperties->setPropertyValue( SC_UNONAME_NUMFMT, uno::Any(SetCurrencySymbol(rNumberFormat, rCurrency)));
974  }
975 }
976 
978 {
979  if (!mbImportStyles)
980  return;
981 
982  if (!sPrevStyleName.isEmpty())
983  {
984  uno::Reference <beans::XPropertySet> xProperties (xSheetCellRanges, uno::UNO_QUERY);
985  if (xProperties.is())
986  {
987  XMLTableStylesContext *pStyles(static_cast<XMLTableStylesContext *>(GetAutoStyles()));
988  XMLTableStyleContext* pStyle = nullptr;
989  if ( pStyles )
990  pStyle = const_cast<XMLTableStyleContext*>(static_cast<const XMLTableStyleContext *>(pStyles->FindStyleChildContext(
991  XmlStyleFamily::TABLE_CELL, sPrevStyleName, true)));
992  if (pStyle)
993  {
994  pStyle->FillPropertySet(xProperties);
995  // here needs to be the cond format import method
996  sal_Int32 nNumberFormat(pStyle->GetNumberFormat());
997  SetType(xProperties, nNumberFormat, nPrevCellType, sPrevCurrency);
998 
999  css::uno::Any aAny = xProperties->getPropertyValue("FormatID");
1000  sal_uInt64 nKey = 0;
1001  if ((aAny >>= nKey) && nKey)
1002  {
1003  ScFormatSaveData* pFormatSaveData = comphelper::getFromUnoTunnel<ScModelObj>(GetModel())->GetFormatSaveData();
1004  pFormatSaveData->maIDToName.insert(std::pair<sal_uInt64, OUString>(nKey, sPrevStyleName));
1005  }
1006 
1007  // store first cell of first range for each style, once per sheet
1008  uno::Sequence<table::CellRangeAddress> aAddresses(xSheetCellRanges->getRangeAddresses());
1009  pStyle->ApplyCondFormat(aAddresses);
1010  if ( aAddresses.hasElements() )
1011  {
1012  const table::CellRangeAddress& rRange = aAddresses[0];
1013  if ( rRange.Sheet != pStyle->GetLastSheet() )
1014  {
1015  ScSheetSaveData* pSheetData = comphelper::getFromUnoTunnel<ScModelObj>(GetModel())->GetSheetSaveData();
1016  pSheetData->AddCellStyle( sPrevStyleName,
1017  ScAddress( static_cast<SCCOL>(rRange.StartColumn), static_cast<SCROW>(rRange.StartRow), static_cast<SCTAB>(rRange.Sheet) ) );
1018  pStyle->SetLastSheet(rRange.Sheet);
1019  }
1020  }
1021  }
1022  else
1023  {
1024  xProperties->setPropertyValue(SC_UNONAME_CELLSTYL, uno::Any(GetStyleDisplayName( XmlStyleFamily::TABLE_CELL, sPrevStyleName )));
1025  sal_Int32 nNumberFormat(GetStyleNumberFormats()->GetStyleNumberFormat(sPrevStyleName));
1026  bool bInsert(nNumberFormat == -1);
1027  SetType(xProperties, nNumberFormat, nPrevCellType, sPrevCurrency);
1028  if (bInsert)
1030  }
1031  }
1032  }
1033  if (GetModel().is())
1034  {
1035  uno::Reference <lang::XMultiServiceFactory> xMultiServiceFactory(GetModel(), uno::UNO_QUERY);
1036  if (xMultiServiceFactory.is())
1037  xSheetCellRanges.set(uno::Reference <sheet::XSheetCellRangeContainer>(
1038  xMultiServiceFactory->createInstance("com.sun.star.sheet.SheetCellRanges"),
1039  uno::UNO_QUERY));
1040  }
1041  OSL_ENSURE(xSheetCellRanges.is(), "didn't get SheetCellRanges");
1042 }
1043 
1044 void ScXMLImport::SetStyleToRanges(const ScRangeList& rRanges, const OUString* pStyleName,
1045  const sal_Int16 nCellType, const OUString* pCurrency)
1046 {
1047  if (!mbImportStyles)
1048  return;
1049 
1050  if (sPrevStyleName.isEmpty())
1051  {
1052  nPrevCellType = nCellType;
1053  if (pStyleName)
1054  sPrevStyleName = *pStyleName;
1055  if (pCurrency)
1056  sPrevCurrency = *pCurrency;
1057  else if (!sPrevCurrency.isEmpty())
1058  sPrevCurrency.clear();
1059  }
1060  else if ((nCellType != nPrevCellType) ||
1061  ((pStyleName && *pStyleName != sPrevStyleName) ||
1062  (!pStyleName && !sPrevStyleName.isEmpty())) ||
1063  ((pCurrency && *pCurrency != sPrevCurrency) ||
1064  (!pCurrency && !sPrevCurrency.isEmpty())))
1065  {
1066  SetStyleToRanges();
1067  nPrevCellType = nCellType;
1068  if (pStyleName)
1069  sPrevStyleName = *pStyleName;
1070  else if(!sPrevStyleName.isEmpty())
1071  sPrevStyleName.clear();
1072  if (pCurrency)
1073  sPrevCurrency = *pCurrency;
1074  else if(!sPrevCurrency.isEmpty())
1075  sPrevCurrency.clear();
1076  }
1077 
1078  if (!xSheetCellRanges.is() && GetModel().is())
1079  {
1080  uno::Reference <lang::XMultiServiceFactory> xMultiServiceFactory(GetModel(), uno::UNO_QUERY);
1081  if (xMultiServiceFactory.is())
1082  xSheetCellRanges.set(uno::Reference <sheet::XSheetCellRangeContainer>(xMultiServiceFactory->createInstance("com.sun.star.sheet.SheetCellRanges"), uno::UNO_QUERY));
1083  OSL_ENSURE(xSheetCellRanges.is(), "didn't get SheetCellRanges");
1084 
1085  }
1086  static_cast<ScCellRangesObj*>(xSheetCellRanges.get())->SetNewRanges(rRanges);
1087 }
1088 
1090 {
1091  if (!bNullDateSetted)
1093  OSL_ENSURE(bNullDateSetted, "could not set the null date");
1094  return bNullDateSetted;
1095 }
1096 
1098 {
1102 }
1103 
1105 {
1106  if (!pStyleNumberFormats)
1108  return pStyleNumberFormats.get();
1109 }
1110 
1112 {
1113  SetStyleToRanges();
1114  sPrevStyleName.clear();
1115 }
1116 
1117 // XImporter
1118 void SAL_CALL ScXMLImport::setTargetDocument( const css::uno::Reference< css::lang::XComponent >& xDoc )
1119 {
1120  ScXMLImport::MutexGuard aGuard(*this);
1122 
1123  uno::Reference<frame::XModel> xModel(xDoc, uno::UNO_QUERY);
1124  pDoc = ScXMLConverter::GetScDocument( xModel );
1125  OSL_ENSURE( pDoc, "ScXMLImport::setTargetDocument - no ScDocument!" );
1126  if (!pDoc)
1127  throw lang::IllegalArgumentException();
1128 
1129  if (ScDocShell* pDocSh = static_cast<ScDocShell*>(pDoc->GetDocumentShell()))
1130  pDocSh->SetInitialLinkUpdate( pDocSh->GetMedium());
1131 
1132  mpDocImport.reset(new ScDocumentImport(*pDoc));
1134 
1135  uno::Reference<document::XActionLockable> xActionLockable(xDoc, uno::UNO_QUERY);
1136  if (xActionLockable.is())
1137  xActionLockable->addActionLock();
1138 }
1139 
1140 // css::xml::sax::XDocumentHandler
1142 {
1143  ScXMLImport::MutexGuard aGuard(*this);
1145  if (pDoc && !pDoc->IsImportingXML())
1146  {
1147  comphelper::getFromUnoTunnel<ScModelObj>(GetModel())->BeforeXMLLoading();
1148  bSelfImportingXMLSet = true;
1149  }
1150 
1151  // if content and styles are loaded with separate imports,
1152  // set bLatinDefaultStyle flag at the start of the content import
1153  SvXMLImportFlags nFlags = getImportFlags();
1154  if ( ( nFlags & SvXMLImportFlags::CONTENT ) && !( nFlags & SvXMLImportFlags::STYLES ) )
1156 
1157  if (getImportFlags() & SvXMLImportFlags::CONTENT)
1158  {
1159  if (GetModel().is())
1160  {
1161  // store initial namespaces, to find the ones that were added from the file later
1162  ScSheetSaveData* pSheetData = comphelper::getFromUnoTunnel<ScModelObj>(GetModel())->GetSheetSaveData();
1163  const SvXMLNamespaceMap& rNamespaces = GetNamespaceMap();
1164  pSheetData->StoreInitialNamespaces(rNamespaces);
1165  }
1166  }
1167 
1168  uno::Reference< beans::XPropertySet > const xImportInfo( getImportInfo() );
1169  uno::Reference< beans::XPropertySetInfo > const xPropertySetInfo(
1170  xImportInfo.is() ? xImportInfo->getPropertySetInfo() : nullptr);
1171  if (xPropertySetInfo.is())
1172  {
1173  OUString const sOrganizerMode(
1174  "OrganizerMode");
1175  if (xPropertySetInfo->hasPropertyByName(sOrganizerMode))
1176  {
1177  bool bStyleOnly(false);
1178  if (xImportInfo->getPropertyValue(sOrganizerMode) >>= bStyleOnly)
1179  {
1180  bLoadDoc = !bStyleOnly;
1181  }
1182  }
1183  }
1184 
1185  UnlockSolarMutex();
1186 }
1187 
1188 sal_Int32 ScXMLImport::GetRangeType(const OUString& sRangeType)
1189 {
1190  sal_Int32 nRangeType(0);
1191  OUStringBuffer sBuffer;
1192  sal_Int32 i = 0;
1193  while (i <= sRangeType.getLength())
1194  {
1195  if ((i == sRangeType.getLength()) || (sRangeType[i] == ' '))
1196  {
1197  OUString sTemp = sBuffer.makeStringAndClear();
1198  if (sTemp == "repeat-column")
1200  else if (sTemp == SC_REPEAT_ROW)
1201  nRangeType |= sheet::NamedRangeFlag::ROW_HEADER;
1202  else if (sTemp == SC_FILTER)
1203  nRangeType |= sheet::NamedRangeFlag::FILTER_CRITERIA;
1204  else if (sTemp == SC_PRINT_RANGE)
1205  nRangeType |= sheet::NamedRangeFlag::PRINT_AREA;
1206  }
1207  else if (i < sRangeType.getLength())
1208  sBuffer.append(sRangeType[i]);
1209  ++i;
1210  }
1211  return nRangeType;
1212 }
1213 
1215 {
1216  if (maMyLabelRanges.empty())
1217  return;
1218 
1219  uno::Reference <beans::XPropertySet> xPropertySet (GetModel(), uno::UNO_QUERY);
1220  if (!xPropertySet.is())
1221  return;
1222 
1223  uno::Any aColAny = xPropertySet->getPropertyValue(SC_UNO_COLLABELRNG);
1224  uno::Any aRowAny = xPropertySet->getPropertyValue(SC_UNO_ROWLABELRNG);
1225 
1226  uno::Reference< sheet::XLabelRanges > xColRanges;
1227  uno::Reference< sheet::XLabelRanges > xRowRanges;
1228 
1229  if ( !(( aColAny >>= xColRanges ) && ( aRowAny >>= xRowRanges )) )
1230  return;
1231 
1232  table::CellRangeAddress aLabelRange;
1233  table::CellRangeAddress aDataRange;
1234 
1235  for (const auto& rLabelRange : maMyLabelRanges)
1236  {
1237  sal_Int32 nOffset1(0);
1238  sal_Int32 nOffset2(0);
1239  FormulaGrammar::AddressConvention eConv = FormulaGrammar::CONV_OOO;
1240 
1241  assert(pDoc);
1242  if (ScRangeStringConverter::GetRangeFromString( aLabelRange, rLabelRange.sLabelRangeStr, *pDoc, eConv, nOffset1 ) &&
1243  ScRangeStringConverter::GetRangeFromString( aDataRange, rLabelRange.sDataRangeStr, *pDoc, eConv, nOffset2 ))
1244  {
1245  if ( rLabelRange.bColumnOrientation )
1246  xColRanges->addNew( aLabelRange, aDataRange );
1247  else
1248  xRowRanges->addNew( aLabelRange, aDataRange );
1249  }
1250  }
1251 
1252  maMyLabelRanges.clear();
1253 }
1254 
1255 namespace {
1256 
1257 class RangeNameInserter
1258 {
1259  ScDocument& mrDoc;
1260  ScRangeName& mrRangeName;
1261 
1262 public:
1263  RangeNameInserter(ScDocument& rDoc, ScRangeName& rRangeName) :
1264  mrDoc(rDoc), mrRangeName(rRangeName) {}
1265 
1266  void operator() (const ScMyNamedExpression& p) const
1267  {
1268  using namespace formula;
1269 
1270  const OUString& aType = p.sRangeType;
1271  sal_uInt32 nUnoType = ScXMLImport::GetRangeType(aType);
1272 
1274  if ( nUnoType & sheet::NamedRangeFlag::FILTER_CRITERIA ) nNewType |= ScRangeData::Type::Criteria;
1275  if ( nUnoType & sheet::NamedRangeFlag::PRINT_AREA ) nNewType |= ScRangeData::Type::PrintArea;
1278 
1279  // Insert a new name.
1280  ScAddress aPos;
1281  sal_Int32 nOffset = 0;
1283  aPos, p.sBaseCellAddress, mrDoc, FormulaGrammar::CONV_OOO, nOffset);
1284 
1285  if (bSuccess)
1286  {
1287  OUString aContent = p.sContent;
1288  if (!p.bIsExpression)
1290 
1291  ScRangeData* pData = new ScRangeData(
1292  mrDoc, p.sName, aContent, aPos, nNewType, p.eGrammar);
1293  mrRangeName.insert(pData);
1294  }
1295  }
1296 };
1297 
1298 }
1299 
1301 {
1302  if (m_aMyNamedExpressions.empty())
1303  return;
1304 
1305  if (!pDoc)
1306  return;
1307 
1308  // Insert the namedRanges
1309  ScRangeName* pRangeNames = pDoc->GetRangeName();
1310  ::std::for_each(m_aMyNamedExpressions.begin(), m_aMyNamedExpressions.end(), RangeNameInserter(*pDoc, *pRangeNames));
1311 }
1312 
1314 {
1315  if (!pDoc)
1316  return;
1317 
1318  for (auto const& itr : m_SheetNamedExpressions)
1319  {
1320  const SCTAB nTab = itr.first;
1321  ScRangeName* pRangeNames = pDoc->GetRangeName(nTab);
1322  if (!pRangeNames)
1323  continue;
1324 
1325  const ScMyNamedExpressions& rNames = itr.second;
1326  ::std::for_each(rNames.begin(), rNames.end(), RangeNameInserter(*pDoc, *pRangeNames));
1327  }
1328 }
1329 
1331 {
1332  if (!pDoc)
1333  return;
1334 
1335  ScCalcConfig aCalcConfig = pDoc->GetCalcConfig();
1336 
1337  // Has any string ref syntax been imported?
1338  // If not, we need to take action
1339  if ( !aCalcConfig.mbHasStringRefSyntax )
1340  {
1342  pDoc->SetCalcConfig(aCalcConfig);
1343  }
1344 }
1345 
1347 {
1348  ScXMLImport::MutexGuard aGuard(*this);
1349  if (getImportFlags() & SvXMLImportFlags::CONTENT)
1350  {
1351  if (GetModel().is())
1352  {
1353  mpDocImport->finalize();
1354 
1355  uno::Reference<document::XViewDataSupplier> xViewDataSupplier(GetModel(), uno::UNO_QUERY);
1356  if (xViewDataSupplier.is())
1357  {
1358  uno::Reference<container::XIndexAccess> xIndexAccess(xViewDataSupplier->getViewData());
1359  if (xIndexAccess.is() && xIndexAccess->getCount() > 0)
1360  {
1361  uno::Sequence< beans::PropertyValue > aSeq;
1362  if (xIndexAccess->getByIndex(0) >>= aSeq)
1363  {
1364  for (const auto& rProp : std::as_const(aSeq))
1365  {
1366  OUString sName(rProp.Name);
1367  if (sName == SC_ACTIVETABLE)
1368  {
1369  OUString sTabName;
1370  if(rProp.Value >>= sTabName)
1371  {
1372  SCTAB nTab(0);
1373  if (pDoc->GetTable(sTabName, nTab))
1374  {
1375  pDoc->SetVisibleTab(nTab);
1376  break;
1377  }
1378  }
1379  }
1380  }
1381  }
1382  }
1383  }
1384  SetLabelRanges();
1385  SetNamedRanges();
1388  if (mpPivotSources)
1389  // Process pivot table sources after the named ranges have been set.
1390  mpPivotSources->process();
1391  }
1392  GetProgressBarHelper()->End(); // make room for subsequent SfxProgressBars
1393  if (pDoc)
1394  {
1395  pDoc->CompileXML();
1396 
1397  // After CompileXML, links must be completely changed to the new URLs.
1398  // Otherwise, hasExternalFile for API wouldn't work (#i116940#),
1399  // and typing a new formula would create a second link with the same "real" file name.
1400  if (pDoc->HasExternalRefManager())
1402  }
1403 
1404  // If the stream contains cells outside of the current limits, the styles can't be re-created,
1405  // so stream copying is disabled then.
1406  if (pDoc && GetModel().is() && !pDoc->HasRangeOverflow())
1407  {
1408  // set "valid stream" flags after loading (before UpdateRowHeights, so changed formula results
1409  // in UpdateRowHeights can already clear the flags again)
1410  ScSheetSaveData* pSheetData = comphelper::getFromUnoTunnel<ScModelObj>(GetModel())->GetSheetSaveData();
1411 
1412  SCTAB nTabCount = pDoc->GetTableCount();
1413  for (SCTAB nTab=0; nTab<nTabCount; ++nTab)
1414  {
1415  pDoc->SetDrawPageSize(nTab);
1416  if (!pSheetData->IsSheetBlocked( nTab ))
1417  pDoc->SetStreamValid( nTab, true );
1418  }
1419  }
1420 
1421  // There are rows with optimal height which need to be updated
1422  if (pDoc && !maRecalcRowRanges.empty())
1423  {
1424  bool bLockHeight = pDoc->IsAdjustHeightLocked();
1425  if (bLockHeight)
1426  {
1428  }
1429 
1430  ScSizeDeviceProvider aProv(static_cast<ScDocShell*>(pDoc->GetDocumentShell()));
1431  ScDocRowHeightUpdater aUpdater(*pDoc, aProv.GetDevice(), aProv.GetPPTX(), aProv.GetPPTY(), &maRecalcRowRanges);
1432  aUpdater.update();
1433 
1434  if (bLockHeight)
1435  {
1437  }
1438  }
1439 
1440  // Initialize and set position and size of objects
1441  if (pDoc && pDoc->GetDrawLayer())
1442  {
1443  ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1444  SCTAB nTabCount = pDoc->GetTableCount();
1445  for (SCTAB nTab = 0; nTab < nTabCount; ++nTab)
1446  {
1447  const SdrPage* pPage = pDrawLayer->GetPage(nTab);
1448  if (!pPage)
1449  continue;
1450  bool bNegativePage = pDoc->IsNegativePage(nTab);
1451  const size_t nCount = pPage->GetObjCount();
1452  for (size_t i = 0; i < nCount; ++i)
1453  {
1454  SdrObject* pObj = pPage->GetObj(i);
1456  = ScDrawLayer::GetObjDataTab(pObj, nTab);
1457  // Existence of pData means, that it is a cell anchored object
1458  if (pData)
1459  {
1460  // Finish and correct import based on full size (no hidden row/col) and LTR
1461  pDrawLayer->InitializeCellAnchoredObj(pObj, *pData);
1462  // Adapt object to hidden row/col and RTL
1463  pDrawLayer->RecalcPos(pObj, *pData, bNegativePage,
1464  true /*bUpdateNoteCaptionPos*/);
1465  }
1466  }
1467  }
1468  }
1469 
1470  aTables.FixupOLEs();
1471  }
1472  if (GetModel().is())
1473  {
1474  uno::Reference<document::XActionLockable> xActionLockable(GetModel(), uno::UNO_QUERY);
1475  if (xActionLockable.is())
1476  xActionLockable->removeActionLock();
1477  }
1479 
1480  if (pDoc)
1481  {
1482  pDoc->BroadcastUno(SfxHint(SfxHintId::ScClearCache));
1483  }
1484 
1485  if(pDoc && bSelfImportingXMLSet)
1486  comphelper::getFromUnoTunnel<ScModelObj>(GetModel())->AfterXMLLoading();
1487 }
1488 
1489 // XEventListener
1491 {
1493  pDoc = nullptr;
1494 }
1495 
1497  mrImport(rImport)
1498 {
1500 }
1501 
1503 {
1504  mrImport.UnlockSolarMutex();
1505 }
1506 
1508 {
1509  // #i62677# When called from DocShell/Wrapper, the SolarMutex is already locked,
1510  // so there's no need to allocate (and later delete) the SolarMutexGuard.
1511  if (!mbLockSolarMutex)
1512  {
1514  return;
1515  }
1516 
1517  if (nSolarMutexLocked == 0)
1518  {
1519  OSL_ENSURE(!pSolarMutexGuard, "Solar Mutex is locked");
1520  pSolarMutexGuard.reset(new SolarMutexGuard());
1521  }
1523 }
1524 
1526 {
1527  if (nSolarMutexLocked > 0)
1528  {
1530  if (nSolarMutexLocked == 0)
1531  {
1532  OSL_ENSURE(pSolarMutexGuard, "Solar Mutex is always unlocked");
1533  pSolarMutexGuard.reset();
1534  }
1535  }
1536 }
1537 
1539 {
1540  sal_Int32 nOffset = -1;
1541  uno::Reference<xml::sax::XLocator> xLocator = GetLocator();
1542  uno::Reference<io::XSeekable> xSeek( xLocator, uno::UNO_QUERY );
1543  if ( xSeek.is() )
1544  nOffset = static_cast<sal_Int32>(xSeek->getPosition());
1545  return nOffset;
1546 }
1547 
1549 {
1550  // #i31130# Overflow is stored in the document, because the ScXMLImport object
1551  // isn't available in ScXMLImportWrapper::ImportFromComponent when using the
1552  // OOo->Oasis transformation.
1553 
1554  if ( pDoc )
1555  pDoc->SetRangeOverflowType( nType );
1556 }
1557 
1559 {
1560  nProgressCount++;
1561  if (nProgressCount > 100)
1562  {
1564  nProgressCount = 0;
1565  }
1566 }
1567 
1569  OUString& rFormula, OUString& rFormulaNmsp, FormulaGrammar::Grammar& reGrammar,
1570  const OUString& rAttrValue, bool bRestrictToExternalNmsp ) const
1571 {
1572  // parse the attribute value, extract namespace ID, literal namespace, and formula string
1573  rFormulaNmsp.clear();
1574  sal_uInt16 nNsId = GetNamespaceMap().GetKeyByQName(rAttrValue, nullptr, &rFormula, &rFormulaNmsp, SvXMLNamespaceMap::QNameMode::AttrValue);
1575 
1576  // check if we have an ODF formula namespace
1577  if( !bRestrictToExternalNmsp ) switch( nNsId )
1578  {
1579  case XML_NAMESPACE_OOOC:
1580  rFormulaNmsp.clear(); // remove namespace string for built-in grammar
1581  reGrammar = FormulaGrammar::GRAM_PODF;
1582  return;
1583  case XML_NAMESPACE_OF:
1584  rFormulaNmsp.clear(); // remove namespace string for built-in grammar
1585  reGrammar = FormulaGrammar::GRAM_ODFF;
1586  return;
1587  }
1588 
1589  /* Find default grammar for formulas without namespace. There may be
1590  documents in the wild that stored no namespace in ODF 1.0/1.1. Use
1591  GRAM_PODF then (old style ODF 1.0/1.1 formulas). The default for ODF
1592  1.2 and later without namespace is GRAM_ODFF (OpenFormula). */
1593  FormulaGrammar::Grammar eDefaultGrammar =
1594  (GetDocument()->GetStorageGrammar() == FormulaGrammar::GRAM_PODF) ?
1595  FormulaGrammar::GRAM_PODF : FormulaGrammar::GRAM_ODFF;
1596 
1597  /* Check if we have no namespace at all. The value XML_NAMESPACE_NONE
1598  indicates that there is no colon. If the first character of the
1599  attribute value is the equality sign, the value XML_NAMESPACE_UNKNOWN
1600  indicates that there is a colon somewhere in the formula string. */
1601  if( (nNsId == XML_NAMESPACE_NONE) || ((nNsId == XML_NAMESPACE_UNKNOWN) && (rAttrValue.toChar() == '=')) )
1602  {
1603  rFormula = rAttrValue; // return entire string as formula
1604  reGrammar = eDefaultGrammar;
1605  return;
1606  }
1607 
1608  /* Check if a namespace URL could be resolved from the attribute value.
1609  Use that namespace only, if the Calc document knows an associated
1610  external formula parser. This prevents that the range operator in
1611  conjunction with defined names is confused as namespaces prefix, e.g.
1612  in the expression 'table:A1' where 'table' is a named reference. */
1613  if( ((nNsId & XML_NAMESPACE_UNKNOWN_FLAG) != 0) && !rFormulaNmsp.isEmpty() &&
1614  GetDocument()->GetFormulaParserPool().hasFormulaParser( rFormulaNmsp ) )
1615  {
1616  reGrammar = FormulaGrammar::GRAM_EXTERNAL;
1617  return;
1618  }
1619 
1620  /* All attempts failed (e.g. no namespace and no leading equality sign, or
1621  an invalid namespace prefix), continue with the entire attribute value. */
1622  rFormula = rAttrValue;
1623  rFormulaNmsp.clear(); // remove any namespace string
1624  reGrammar = eDefaultGrammar;
1625 }
1626 
1628 {
1629  if (!mpComp)
1630  return FormulaError::NONE;
1631 
1632  return mpComp->GetErrorConstant(rStr);
1633 }
1634 
1636 {
1637  if (!mpEditEngine)
1638  {
1640  mpEditEngine->SetRefMapMode(MapMode(MapUnit::Map100thMM));
1641  mpEditEngine->SetEditTextObjectPool(pDoc->GetEditPool());
1642  mpEditEngine->SetUpdateLayout(false);
1643  mpEditEngine->EnableUndo(false);
1644  mpEditEngine->SetControlWord(mpEditEngine->GetControlWord() & ~EEControlBits::ALLOWBIGOBJS);
1645  }
1646  return mpEditEngine.get();
1647 }
1648 
1650 {
1651  if (!mpEditAttrMap)
1653  return *mpEditAttrMap;
1654 }
1655 
1657 {
1658  if (pDoc)
1659  pDoc->SetEmbedFonts(true);
1660 }
1661 
1663 {
1664  if (!pDetectiveOpArray)
1666  return pDetectiveOpArray.get();
1667 }
1668 
1669 extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportFODS(SvStream &rStream)
1670 {
1671  ScDLL::Init();
1672 
1673  SfxObjectShellLock xDocSh(new ScDocShell);
1674  xDocSh->DoInitNew();
1675  uno::Reference<frame::XModel> xModel(xDocSh->GetModel());
1676 
1677  uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(comphelper::getProcessServiceFactory());
1678  uno::Reference<io::XInputStream> xStream(new ::utl::OSeekableInputStreamWrapper(rStream));
1679  uno::Reference<uno::XInterface> xInterface(xMultiServiceFactory->createInstance("com.sun.star.comp.Writer.XmlFilterAdaptor"), uno::UNO_SET_THROW);
1680 
1681  css::uno::Sequence<OUString> aUserData
1682  {
1683  "com.sun.star.comp.filter.OdfFlatXml",
1684  "",
1685  "com.sun.star.comp.Calc.XMLOasisImporter",
1686  "com.sun.star.comp.Calc.XMLOasisExporter",
1687  "",
1688  "",
1689  "true"
1690  };
1691  uno::Sequence<beans::PropertyValue> aAdaptorArgs(comphelper::InitPropertySequence(
1692  {
1693  { "UserData", uno::Any(aUserData) },
1694  }));
1695  css::uno::Sequence<uno::Any> aOuterArgs{ uno::Any(aAdaptorArgs) };
1696 
1697  uno::Reference<lang::XInitialization> xInit(xInterface, uno::UNO_QUERY_THROW);
1698  xInit->initialize(aOuterArgs);
1699 
1700  uno::Reference<document::XImporter> xImporter(xInterface, uno::UNO_QUERY_THROW);
1701  uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
1702  {
1703  { "InputStream", uno::Any(xStream) },
1704  { "URL", uno::Any(OUString("private:stream")) },
1705  }));
1706  xImporter->setTargetDocument(xModel);
1707 
1708  uno::Reference<document::XFilter> xFilter(xInterface, uno::UNO_QUERY_THROW);
1709  //SetLoading hack because the document properties will be re-initted
1710  //by the xml filter and during the init, while it's considered uninitialized,
1711  //setting a property will inform the document it's modified, which attempts
1712  //to update the properties, which throws cause the properties are uninitialized
1713  xDocSh->SetLoading(SfxLoadedFlags::NONE);
1714  bool ret = xFilter->filter(aArgs);
1715  xDocSh->SetLoading(SfxLoadedFlags::ALL);
1716 
1717  xDocSh->DoClose();
1718 
1719  return ret;
1720 }
1721 
1722 extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportXLSX(SvStream &rStream)
1723 {
1724  ScDLL::Init();
1725 
1726  SfxObjectShellLock xDocSh(new ScDocShell);
1727  xDocSh->DoInitNew();
1728  uno::Reference<frame::XModel> xModel(xDocSh->GetModel());
1729 
1730  uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(comphelper::getProcessServiceFactory());
1731  uno::Reference<io::XInputStream> xStream(new utl::OSeekableInputStreamWrapper(rStream));
1732 
1733  uno::Reference<document::XFilter> xFilter(xMultiServiceFactory->createInstance("com.sun.star.comp.oox.xls.ExcelFilter"), uno::UNO_QUERY_THROW);
1734 
1735  uno::Reference<document::XImporter> xImporter(xFilter, uno::UNO_QUERY_THROW);
1736  uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
1737  {
1738  { "InputStream", uno::Any(xStream) },
1739  { "InputMode", uno::Any(true) },
1740  }));
1741  xImporter->setTargetDocument(xModel);
1742 
1743  //SetLoading hack because the document properties will be re-initted
1744  //by the xml filter and during the init, while it's considered uninitialized,
1745  //setting a property will inform the document it's modified, which attempts
1746  //to update the properties, which throws cause the properties are uninitialized
1747  xDocSh->SetLoading(SfxLoadedFlags::NONE);
1748  bool ret = false;
1749  try
1750  {
1751  ret = xFilter->filter(aArgs);
1752  }
1753  catch (const css::io::IOException&)
1754  {
1755  }
1756  catch (const css::lang::WrappedTargetRuntimeException&)
1757  {
1758  }
1759  xDocSh->SetLoading(SfxLoadedFlags::ALL);
1760 
1761  xDocSh->DoClose();
1762 
1763  return ret;
1764 }
1765 
1766 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SetVisArea(const tools::Rectangle &rVisArea)
void SetStringRefSyntaxIfMissing()
Definition: xmlimprt.cxx:1330
css::uno::Reference< css::sheet::XSheetCellRangeContainer > xSheetCellRanges
Definition: xmlimprt.hxx:156
virtual SvXMLImportContext * CreateFastContext(sal_Int32 nElement, const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmlimprt.cxx:320
bool HasExternalRefManager() const
Definition: document.hxx:1025
XML_DOCUMENT_CONTENT
ScMyImportValidations maValidations
Definition: xmlimprt.hxx:147
virtual ~ScXMLImport() noexcept override
Definition: xmlimprt.cxx:385
double GetPPTY() const
Definition: sizedev.hxx:42
void SetStyles(SvXMLStylesContext *pStyles)
XML_DOCUMENT
SvXMLImportContext * CreateScriptContext()
Definition: xmlimprt.cxx:466
css::uno::Reference< css::util::XNumberFormatTypes > xNumberFormatTypes
Definition: xmlimprt.hxx:154
SC_DLLPUBLIC bool IsNegativePage(SCTAB nTab) const
Definition: document.cxx:997
ScMyTables aTables
Lift cycle managed elsewhere, no need to delete.
Definition: xmlimprt.hxx:139
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Calc_XMLOasisStylesImporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: xmlimprt.cxx:139
Provide mapping from ODF text formatting styles to EditEngine's, for rich-text cell content import...
static bool GetAddressFromString(ScAddress &rAddress, const OUString &rAddressStr, const ScDocument &rDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Int32 &nOffset, sal_Unicode cSeparator= ' ', sal_Unicode cQuote= '\'')
String to Range core.
Definition: rangeutl.cxx:461
void SetTheFirstDateTime(const DateTime &aDateTime)
Definition: chgviset.hxx:86
void cleanup() noexcept
sal_Int32 nProgressCount
Definition: xmlimprt.hxx:161
SC_DLLPUBLIC void SetChangeViewSettings(const ScChangeViewSettings &rNew)
Definition: documen2.cxx:1134
OUString sRangeType
Definition: xmlimprt.hxx:71
SAL_DLLPUBLIC_EXPORT bool TestImportFODS(SvStream &rStream)
Definition: xmlimprt.cxx:1669
ScDocument * pDoc
Definition: xmlimprt.hxx:121
void SetProtection(const css::uno::Sequence< sal_Int8 > &rPass)
Definition: chgtrack.hxx:1123
Store pivot table data that need to be post-processed at the end of the import.
Definition: pivotsource.hxx:25
constexpr sal_uInt16 XML_NAMESPACE_OOOC
ScDocument * GetDocument()
Definition: xmlimprt.hxx:205
SC_DLLPUBLIC void SetDrawPageSize(SCTAB nTab)
Definition: documen9.cxx:195
void SetShowRejected(bool bVal)
Definition: chgviset.hxx:116
std::unique_ptr< sal_Int32[]> pData
::std::list< ScMyNamedExpression > ScMyNamedExpressions
Definition: xmlimprt.hxx:76
SC_DLLPUBLIC ScRangeName * GetRangeName(SCTAB nTab) const
Definition: documen3.cxx:168
void updateAbsAfterLoad()
Replace the original URL with the real URL that was generated from the relative URL.
constexpr OUStringLiteral PERCENT(u"Percent")
css::uno::Reference< css::frame::XModel3 > GetModel() const
XML_DOCUMENT_STYLES
void StoreInitialNamespaces(const SvXMLNamespaceMap &rNamespaces)
Definition: sheetdata.cxx:172
SdrObject * GetObj(size_t nNum) const
static void decode(css::uno::Sequence< sal_Int8 > &aPass, std::u16string_view sBuffer)
size_t GetObjCount() const
void SetTheAuthorToShow(const OUString &aString)
Definition: chgviset.hxx:96
Stores data imported from the file that need to be processed at the end of the import process...
static ScDocument * GetScDocument(const css::uno::Reference< css::frame::XModel > &xModel)
SvXMLNamespaceMap & GetNamespaceMap()
std::vector< ScDocRowHeightUpdater::TabRanges > maRecalcRowRanges
Definition: xmlimprt.hxx:141
SvXMLImportContext * CreateFontDeclsContext()
Definition: xmlimprt.cxx:422
SCTAB GetLastSheet() const
Definition: xmlstyli.hxx:103
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
void SetLastSheet(SCTAB nNew)
Definition: xmlstyli.hxx:104
const ScXMLEditAttributeMap & GetEditAttributeMap() const
Definition: xmlimprt.cxx:1649
void RecalcPos(SdrObject *pObj, ScDrawObjData &rData, bool bNegativePage, bool bUpdateNoteCaptionPos)
Definition: drwlayer.cxx:1021
OUString Name
OUString sPrevCurrency
Definition: xmlimprt.hxx:159
bool mbLockSolarMutex
Definition: xmlimprt.hxx:166
XML_NP_PRESENTATION
Accessor class to ScDocument.
OUString sBaseCellAddress
Definition: xmlimprt.hxx:70
EEControlBits
OUString sPrevStyleName
Definition: xmlimprt.hxx:158
bool IsAdjustHeightLocked() const
Definition: document.hxx:1594
#define XMLERROR_API
void SetFontDecls(XMLFontStylesContext *pFontDecls)
const sal_uInt16 XML_NAMESPACE_UNKNOWN
ScMyLabelRanges maMyLabelRanges
Definition: xmlimprt.hxx:146
Value
SvXMLImportContext * CreateMetaContext(sal_Int32 nElement)
Definition: xmlimprt.cxx:449
rtl::Reference< XMLPropertySetMapper > xRowStylesPropertySetMapper
Definition: xmlimprt.hxx:134
bool SetNullDateOnUnitConverter()
Definition: xmlimprt.cxx:1089
Reference< XInputStream > xStream
SvXMLImportFlags
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:315
void LockSolarMutex()
Definition: xmlimprt.cxx:1507
void SetTheDateMode(SvxRedlinDateMode eDatMod)
Definition: chgviset.hxx:83
std::unique_ptr< ScDocumentImport > mpDocImport
Definition: xmlimprt.hxx:122
sc::ImportPostProcessData * mpPostProcessData
Definition: xmlimprt.hxx:137
virtual void FillPropertySet(const css::uno::Reference< css::beans::XPropertySet > &rPropSet) override
Definition: xmlstyli.cxx:510
int nCount
void SetHasDate(bool bFlag)
Definition: chgviset.hxx:81
std::unique_ptr< sc::PivotTableSources > mpPivotSources
Definition: xmlimprt.hxx:125
SC_DLLPUBLIC bool GetTable(const OUString &rName, SCTAB &rTab) const
Definition: document.cxx:262
SC_DLLPUBLIC ScExternalRefManager * GetExternalRefManager() const
Definition: documen3.cxx:627
bool bSelfImportingXMLSet
Definition: xmlimprt.hxx:165
void FixupOLEs()
Definition: xmlsubti.hxx:76
FormulaError GetFormulaErrorConstant(const OUString &rStr) const
Definition: xmlimprt.cxx:1627
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
ScXMLImport(const ScXMLImport &)=delete
const char * sName
ScChangeTrack * GetChangeTrack() const
Definition: document.hxx:2485
sal_Int32 SetCurrencySymbol(const sal_Int32 nKey, std::u16string_view rCurrency)
Definition: xmlimprt.cxx:798
void SetTheRangeList(const ScRangeList &aRl)
Definition: chgviset.hxx:110
virtual void SAL_CALL endDocument() override
Definition: xmlimprt.cxx:1346
SvXMLImportContext * CreateStylesContext(bool bAutoStyles)
Definition: xmlimprt.cxx:431
static bool GetRangeFromString(ScRange &rRange, const OUString &rRangeStr, const ScDocument &rDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Int32 &nOffset, sal_Unicode cSeparator= ' ', sal_Unicode cQuote= '\'')
SvXMLStylesContext * GetStyles()
bool bNullDateSetted
Definition: xmlimprt.hxx:164
OutputDevice * GetDevice() const
Definition: sizedev.hxx:40
void InsertStyles()
Definition: xmlimprt.cxx:596
SheetNamedExpMap m_SheetNamedExpressions
Definition: xmlimprt.hxx:144
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
bool GetValidation(const OUString &sName, ScMyImportValidation &aValidation)
Definition: xmlimprt.cxx:557
void ApplyCondFormat(const css::uno::Sequence< css::table::CellRangeAddress > &xCellRanges)
Definition: xmlstyli.cxx:466
SC_DLLPUBLIC void SetVisibleTab(SCTAB nTab)
Definition: document.hxx:878
void ExamineDefaultStyle()
Definition: xmlimprt.cxx:605
This class exists only to provide GetScImport() to its derived classes.
void Increment(sal_Int32 nInc=1)
const OUString & getNumDecimalSep() const
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1081
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Calc_XMLOasisSettingsImporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: xmlimprt.cxx:163
constexpr OUStringLiteral SC_LOCALE
Definition: xmlimprt.cxx:104
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Calc_XMLOasisContentImporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: xmlimprt.cxx:151
const XMLPropertyMapEntry aXMLScTableStylesImportProperties[]
Definition: xmlstyle.cxx:154
bool IsImportingXML() const
Definition: document.hxx:2220
virtual void SetStatistics(const css::uno::Sequence< css::beans::NamedValue > &i_rStats) override
Definition: xmlimprt.cxx:478
sal_Int32 GetNumberFormat()
Definition: xmlstyli.cxx:581
void SetPostProcessData(sc::ImportPostProcessData *p)
Definition: xmlimprt.cxx:307
int i
virtual void SetConfigurationSettings(const css::uno::Sequence< css::beans::PropertyValue > &aConfigProps) override
Definition: xmlimprt.cxx:739
void CopyStylesToDoc(bool bOverwrite, bool bFinish=true)
constexpr OUStringLiteral SC_CURRENCYSYMBOL
Definition: xmlimprt.cxx:105
ScMyNamedExpressions m_aMyNamedExpressions
Definition: xmlimprt.hxx:143
std::unique_ptr< ScXMLEditAttributeMap > mpEditAttrMap
Definition: xmlimprt.hxx:127
void CompileXML()
Definition: document.cxx:4020
virtual void SAL_CALL startDocument() override
Definition: xmlimprt.cxx:1141
static SC_DLLPUBLIC void Init()
DLL-init/exit-code must be linked to the DLL only.
Definition: scdll.cxx:100
constexpr OUStringLiteral SC_REPEAT_ROW
Definition: xmlimprt.cxx:106
void SetLoading(SfxLoadedFlags nFlags)
std::unique_ptr< ScMyStyleNumberFormats > pStyleNumberFormats
Definition: xmlimprt.hxx:152
SfxObjectShell * GetEmbeddedObject() const
Definition: docuno.cxx:448
void SetStyleToRanges()
Definition: xmlimprt.cxx:977
const sal_uInt16 XML_NAMESPACE_UNKNOWN_FLAG
bool HasRangeOverflow() const
Definition: document.hxx:2212
std::unique_ptr< ScCompiler > mpComp
Definition: xmlimprt.hxx:123
void SetHasComment(bool bFlag)
Definition: chgviset.hxx:99
ScFormulaParserPool & GetFormulaParserPool() const
Returns the pool containing external formula parsers.
Definition: documen3.cxx:656
static void ConvertCellRangeAddress(OUString &sFormula)
const SdrPage * GetPage(sal_uInt16 nPgNum) const
bool IsCurrencySymbol(const sal_Int32 nNumberFormat, const OUString &sCurrencySymbol, std::u16string_view sBankSymbol)
Definition: xmlimprt.cxx:847
SC_DLLPUBLIC SfxItemPool * GetEnginePool() const
Definition: documen2.cxx:470
SC_DLLPUBLIC void UnlockAdjustHeight()
Definition: document.cxx:1802
bool hasFormulaParser(const OUString &rNamespace)
Returns true, if a formula parser is registered for the passed namespace.
constexpr OUStringLiteral SC_PRINT_RANGE
Definition: xmlimprt.cxx:108
const XMLPropertyMapEntry aXMLScColumnStylesProperties[]
Definition: xmlstyle.cxx:115
float u
void SetTheComment(const OUString &aString)
Definition: chgviset.cxx:91
sal_uInt32 nSolarMutexLocked
Definition: xmlimprt.hxx:160
bool setNullDate(const css::uno::Reference< css::frame::XModel > &xModel)
ProgressBarHelper * GetProgressBarHelper()
Use this class to manage solar mutex locking instead of calling LockSolarMutex() and UnlockSolarMutex...
Definition: xmlimprt.hxx:288
void BroadcastUno(const SfxHint &rHint)
Definition: documen3.cxx:952
XML_N_PRESENTATION
formula::FormulaGrammar::Grammar GetStorageGrammar() const
Definition: document.hxx:2532
static sal_Int16 GetCellType(const char *rStrValue, const sal_Int32 nStrLength)
Definition: xmlimprt.cxx:511
const sal_uInt16 XML_NAMESPACE_NONE
ScXMLImport & mrImport
Definition: xmlimprt.hxx:294
void ExtractFormulaNamespaceGrammar(OUString &rFormula, OUString &rFormulaNmsp,::formula::FormulaGrammar::Grammar &reGrammar, const OUString &rAttrValue, bool bRestrictToExternalNmsp=false) const
Extracts the formula string, the formula grammar namespace URL, and a grammar enum value from the pas...
Definition: xmlimprt.cxx:1568
formula::FormulaGrammar::AddressConvention meStringRefAddressSyntax
Definition: calcconfig.hxx:53
std::map< sal_uInt64, OUString > maIDToName
Definition: sheetdata.hxx:176
FormulaError
XMLNumberFormatAttributesExportHelper * GetNumberFormatAttributesExportHelper()
Definition: xmlimprt.cxx:1097
std::unique_ptr< ScEditEngineDefaulter > mpEditEngine
Definition: xmlimprt.hxx:124
constexpr OUStringLiteral SC_UNO_ODS_LOCK_SOLAR_MUTEX
Definition: unonames.hxx:709
static sal_Int32 GetRangeType(const OUString &sRangeType)
Definition: xmlimprt.cxx:1188
std::unique_ptr< XMLNumberFormatAttributesExportHelper > pNumberFormatAttributesExportHelper
Definition: xmlimprt.hxx:151
#define SC_UNONAME_CELLSTYL
Definition: unonames.hxx:98
ScEditEngineDefaulter * GetEditEngine()
Definition: xmlimprt.cxx:1635
void SetRangeOverflowType(ErrCode nType)
Definition: document.hxx:2211
Configuration options for formula interpreter.
Definition: calcconfig.hxx:43
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Calc_XMLOasisImporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: xmlimprt.cxx:115
css::uno::Reference< css::util::XNumberFormats > xNumberFormats
Definition: xmlimprt.hxx:153
SvXMLImportContext * CreateBodyContext(const rtl::Reference< sax_fastparser::FastAttributeList > &rAttrList)
Definition: xmlimprt.cxx:444
SAL_DLLPUBLIC_EXPORT bool TestImportXLSX(SvStream &rStream)
Definition: xmlimprt.cxx:1722
static const NfCurrencyEntry * GetLegacyOnlyCurrencyEntry(std::u16string_view rSymbol, std::u16string_view rAbbrev)
virtual void SAL_CALL startDocument() override
sal_Int16 nPrevCellType
Definition: xmlimprt.hxx:162
virtual void SetViewSettings(const css::uno::Sequence< css::beans::PropertyValue > &aViewProps) override
Definition: xmlimprt.cxx:698
constexpr OUStringLiteral SC_UNO_ODS_IMPORT_STYLES
Definition: unonames.hxx:710
void SetNamedRanges()
Definition: xmlimprt.cxx:1300
void SetShowAccepted(bool bVal)
Definition: chgviset.hxx:113
XML_DOCUMENT_META
constexpr sal_uInt16 XML_NAMESPACE_PRESENTATION
void SetLabelRanges()
Definition: xmlimprt.cxx:1214
Reference< XMultiServiceFactory > getProcessServiceFactory()
bool IsStylesOnlyMode() const
Definition: xmlimprt.hxx:212
void SetStreamValid(SCTAB nTab, bool bSet, bool bIgnoreLock=false)
Definition: document.cxx:928
std::unique_ptr< SolarMutexGuard > pSolarMutexGuard
Definition: xmlimprt.hxx:149
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
Definition: xmlimprt.cxx:403
void LockAdjustHeight()
Definition: document.hxx:1595
SvXMLImportFlags getImportFlags() const
OUString GetStyleDisplayName(XmlStyleFamily nFamily, const OUString &rName) const
bool mbHasStringRefSyntax
Definition: calcconfig.hxx:56
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
ScMyStyleNumberFormats * GetStyleNumberFormats()
Definition: xmlimprt.cxx:1104
void AddCellStyle(const OUString &rName, const ScAddress &rCellPos)
Definition: sheetdata.cxx:41
void setWidth(tools::Long n)
rtl::Reference< XMLPropertySetMapper > xColumnStylesPropertySetMapper
Definition: xmlimprt.hxx:133
static ScDrawObjData * GetObjDataTab(SdrObject *pObj, SCTAB nTab)
Definition: drwlayer.cxx:2616
const ScCalcConfig & GetCalcConfig() const
Definition: document.hxx:2612
std::unique_ptr< ScMyStylesImportHelper > pStylesImportHelper
Definition: xmlimprt.hxx:129
void SetEmbedFonts(bool bUse)
Definition: document.hxx:587
rtl::Reference< XMLPropertySetMapper > xTableStylesPropertySetMapper
Definition: xmlimprt.hxx:135
#define SC_UNONAME_NUMFMT
Definition: unonames.hxx:107
void SetHasRange(bool bFlag)
Definition: chgviset.hxx:107
SC_DLLPUBLIC void SetChangeTrack(std::unique_ptr< ScChangeTrack > pTrack)
only for import filter, deletes any existing ChangeTrack via EndChangeTracking() and takes ownership ...
Definition: documen2.cxx:286
#define SAL_INFO(area, stream)
const css::uno::Reference< css::xml::sax::XLocator > & GetLocator() const
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
void UnlockSolarMutex()
Definition: xmlimprt.cxx:1525
if(aStr!=aBuf) UpdateName_Impl(m_xFollowLb.get()
#define XMLERROR_FLAG_ERROR
ScXMLChangeTrackingImportHelper * GetChangeTrackingImportHelper()
Definition: xmlimprt.cxx:589
virtual void SetStatistics(const css::uno::Sequence< css::beans::NamedValue > &i_rStats)
const XMLPropertyMapEntry aXMLScRowStylesImportProperties[]
Definition: xmlstyle.cxx:123
std::unique_ptr< ScMyImpDetectiveOpArray > pDetectiveOpArray
Definition: xmlimprt.hxx:148
#define XML_ELEMENT(prefix, name)
constexpr OUStringLiteral SC_ACTIVETABLE
sal_uInt16 Add(const OUString &rPrefix, const OUString &rName, sal_uInt16 nKey=XML_NAMESPACE_UNKNOWN)
virtual void DisposingModel() override
Definition: xmlimprt.cxx:1490
const SvXMLUnitConverter & GetMM100UnitConverter() const
const css::uno::Reference< css::frame::XModel > & GetModel() const
Reference< XComponentContext > getProcessComponentContext()
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
void InitializeCellAnchoredObj(SdrObject *pObj, ScDrawObjData &rData)
Definition: drwlayer.cxx:904
void SetValue(sal_Int32 nValue)
static void convertPropertySet(css::uno::Sequence< css::beans::PropertyValue > &rProps, const css::uno::Reference< css::beans::XPropertySet > &aProperties)
void SetError(sal_Int32 nId, const css::uno::Sequence< OUString > &rMsgParams, const OUString &rExceptionMessage, const css::uno::Reference< css::xml::sax::XLocator > &rLocator)
Sequence< sal_Int8 > aSeq
SC_DLLPUBLIC ScPatternAttr * GetDefPattern() const
Definition: document.cxx:6151
constexpr sal_uInt16 XML_NAMESPACE_OF
#define SC_UNO_COLLABELRNG
Definition: unonames.hxx:42
bool bLoadDoc
Definition: xmlimprt.hxx:163
void SetType(const css::uno::Reference< css::beans::XPropertySet > &rProperties, sal_Int32 &rNumberFormat, const sal_Int16 nCellType, std::u16string_view rCurrency)
Definition: xmlimprt.cxx:899
formula::FormulaGrammar::Grammar eGrammar
Definition: xmlimprt.hxx:72
void AddStyleNumberFormat(const OUString &rStyleName, const sal_Int32 nNumberFormat)
const struct statistic s_stats[]
void SetAutoStyles(SvXMLStylesContext *pAutoStyles)
SC_DLLPUBLIC SfxItemPool * GetEditPool() const
Definition: documen2.cxx:465
const XMLPropertyMapEntry aXMLScCellStylesProperties[]
Definition: xmlstyle.cxx:60
ScMyImpDetectiveOpArray * GetDetectiveOpArray()
Definition: xmlimprt.cxx:1662
static bool GetRangeListFromString(ScRangeList &rRangeList, const OUString &rRangeListStr, const ScDocument &rDocument, formula::FormulaGrammar::AddressConvention eConv, sal_Unicode cSeparator= ' ', sal_Unicode cQuote= '\'')
Definition: rangeutl.cxx:552
const OUString & getNumThousandSep() const
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
constexpr OUStringLiteral SC_FILTER
Definition: xmlimprt.cxx:107
const css::uno::Reference< css::beans::XPropertySet > & getImportInfo() const
void SetReference(sal_Int32 nVal)
void SetChangeTrackingViewSettings(const css::uno::Sequence< css::beans::PropertyValue > &rChangeProps)
Definition: xmlimprt.cxx:618
static bool isLatinScript(const ScPatternAttr &rPat, ScDocument &rDoc)
Check if the attribute pattern has a number format that only produces latin script output...
Definition: numformat.cxx:31
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1080
void AddNamedExpression(ScMyNamedExpression aMyNamedExpression)
Definition: xmlimprt.hxx:226
Reference< XModel > xModel
bool mbImportStyles
Definition: xmlimprt.hxx:167
#define DBG_TESTSOLARMUTEX()
virtual void DisposingModel()
rtl::Reference< XMLPropertyHandlerFactory > xScPropHdlFactory
Definition: xmlimprt.hxx:131
bool IsSheetBlocked(SCTAB nTab) const
Definition: sheetdata.cxx:100
virtual void SAL_CALL setTargetDocument(const css::uno::Reference< css::lang::XComponent > &xDoc) override
rtl::Reference< XMLPropertySetMapper > xCellStylesPropertySetMapper
Definition: xmlimprt.hxx:132
sal_Int32 GetByteOffset() const
Definition: xmlimprt.cxx:1538
#define SC_UNO_ROWLABELRNG
Definition: unonames.hxx:46
void ProgressBarIncrement()
Definition: xmlimprt.cxx:1558
sc::PivotTableSources & GetPivotTableSources()
Definition: xmlimprt.cxx:312
void SetHasAuthor(bool bFlag)
Definition: chgviset.hxx:93
SvXMLStylesContext * GetAutoStyles()
void SetTheLastDateTime(const DateTime &aDateTime)
Definition: chgviset.hxx:89
SC_DLLPUBLIC void SetCalcConfig(const ScCalcConfig &rConfig)
Definition: document10.cxx:203
virtual void SAL_CALL setTargetDocument(const css::uno::Reference< css::lang::XComponent > &xDoc) override
Definition: xmlimprt.cxx:1118
css::uno::Reference< css::util::XNumberFormatsSupplier > & GetNumberFormatsSupplier()
XML_DOCUMENT_SETTINGS
MutexGuard(ScXMLImport &rImport)
Definition: xmlimprt.cxx:1496
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * Calc_XMLOasisMetaImporter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Definition: xmlimprt.cxx:127
double GetPPTX() const
Definition: sizedev.hxx:41
SC_DLLPUBLIC bool insert(ScRangeData *p, bool bReuseFreeIndex=true)
Insert object into set.
Definition: rangenam.cxx:802
virtual XMLShapeImportHelper * CreateShapeImport() override
Definition: xmlimprt.cxx:552
virtual void NotifyContainsEmbeddedFont() override
Definition: xmlimprt.cxx:1656
ScDocumentImport & GetDoc()
Definition: xmlimprt.cxx:506
sal_Int16 SCTAB
Definition: types.hxx:22
sal_uInt16 GetKeyByQName(const OUString &rQName, OUString *pPrefix, OUString *pLocalName, OUString *pNamespace, QNameMode eMode) const
virtual void SAL_CALL endDocument() override
bool any2bool(const css::uno::Any &rAny)
void SetStylesToRangesFinished()
Definition: xmlimprt.cxx:1111
void SetRangeOverflowType(ErrCode nType)
Definition: xmlimprt.cxx:1548
void SetSheetNamedRanges()
Definition: xmlimprt.cxx:1313
bool m_bDetectedRangeSegmentation false
void SetShowChanges(bool bFlag)
Definition: chgviset.hxx:78
std::unique_ptr< ScXMLChangeTrackingImportHelper > pChangeTrackingImportHelper
Definition: xmlimprt.hxx:128