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