1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
21 #include <sal/log.hxx>
22 #include <osl/diagnose.h>
24 #include <svl/zforlist.hxx>
26 #include <xmloff/namespacemap.hxx>
27 #include <xmloff/xmlnamespace.hxx>
28 #include <xmloff/xmltkmap.hxx>
29 #include <xmloff/xmlictxt.hxx>
30 #include <xmloff/xmlmetai.hxx>
31 #include <sfx2/objsh.hxx>
32 #include <unotools/streamwrap.hxx>
33 #include <xmloff/xmlscripti.hxx>
34 #include <xmloff/XMLFontStylesContext.hxx>
35 #include <xmloff/DocumentSettingsContext.hxx>
36 #include <xmloff/xmluconv.hxx>
37 #include <xmloff/numehelp.hxx>
38 #include <xmloff/xmltoken.hxx>
39 #include <xmloff/xmlerror.hxx>
40 #include <xmloff/ProgressBarHelper.hxx>
41 #include <svx/svdpage.hxx>
43 #include <svl/languageoptions.hxx>
44 #include <editeng/editstat.hxx>
45 #include <formula/errorcodes.hxx>
46 #include <vcl/svapp.hxx>
48 #include <appluno.hxx>
49 #include "xmlimprt.hxx"
50 #include "importcontext.hxx"
51 #include <document.hxx>
54 #include "xmlbodyi.hxx"
55 #include "xmlstyli.hxx"
56 #include <ViewSettingsSequenceDefines.hxx>
57 #include <userdat.hxx>
59 #include <compiler.hxx>
61 #include "XMLConverter.hxx"
62 #include "XMLDetectiveContext.hxx"
63 #include "XMLTableShapeImportHelper.hxx"
64 #include "XMLChangeTrackingImportHelper.hxx"
65 #include <chgviset.hxx>
66 #include "XMLStylesImportHelper.hxx"
67 #include <sheetdata.hxx>
68 #include <rangeutl.hxx>
69 #include <formulaparserpool.hxx>
70 #include <externalrefmgr.hxx>
71 #include <editutil.hxx>
72 #include "editattributemap.hxx"
73 #include <documentimport.hxx>
74 #include "pivotsource.hxx"
75 #include <unonames.hxx>
76 #include <numformat.hxx>
77 #include <sizedev.hxx>
79 #include "xmlstyle.hxx"
81 #include <comphelper/base64.hxx>
82 #include <comphelper/extract.hxx>
83 #include <comphelper/propertysequence.hxx>
84 #include <comphelper/processfactory.hxx>
86 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
87 #include <com/sun/star/frame/XModel.hpp>
88 #include <com/sun/star/io/IOException.hpp>
89 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
90 #include <com/sun/star/document/XActionLockable.hpp>
91 #include <com/sun/star/util/MalformedNumberFormatException.hpp>
92 #include <com/sun/star/util/NumberFormat.hpp>
93 #include <com/sun/star/util/XNumberFormatTypes.hpp>
94 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
95 #include <com/sun/star/sheet/NamedRangeFlag.hpp>
96 #include <com/sun/star/sheet/XLabelRanges.hpp>
97 #include <com/sun/star/io/XSeekable.hpp>
98 #include <com/sun/star/beans/XPropertySet.hpp>
99 #include <com/sun/star/sheet/XSheetCellRangeContainer.hpp>
100 #include <cellsuno.hxx>
105 #define SC_LOCALE "Locale"
106 #define SC_CURRENCYSYMBOL "CurrencySymbol"
107 #define SC_REPEAT_ROW "repeat-row"
108 #define SC_FILTER "filter"
109 #define SC_PRINT_RANGE "print-range"
111 using namespace com::sun::star
;
112 using namespace ::xmloff::token
;
113 using namespace ::formula
;
115 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
116 Calc_XMLOasisImporter_get_implementation(
117 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const& )
119 return cppu::acquire(static_cast<cppu::OWeakObject
*>(
122 "com.sun.star.comp.Calc.XMLOasisImporter",
123 SvXMLImportFlags::ALL
,
124 { "com.sun.star.comp.Calc.XMLOasisImporter" } )));
127 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
128 Calc_XMLOasisMetaImporter_get_implementation(
129 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const& )
131 return cppu::acquire(static_cast<cppu::OWeakObject
*>(
134 "com.sun.star.comp.Calc.XMLOasisMetaImporter",
135 SvXMLImportFlags::META
,
136 { "com.sun.star.comp.Calc.XMLOasisMetaImporter" } )));
139 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
140 Calc_XMLOasisStylesImporter_get_implementation(
141 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const& )
143 return cppu::acquire(static_cast<cppu::OWeakObject
*>(
146 "com.sun.star.comp.Calc.XMLOasisStylesImporter",
147 SvXMLImportFlags::STYLES
|SvXMLImportFlags::AUTOSTYLES
|SvXMLImportFlags::MASTERSTYLES
|SvXMLImportFlags::FONTDECLS
,
148 { "com.sun.star.comp.Calc.XMLOasisStylesImporter" } )));
151 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
152 Calc_XMLOasisContentImporter_get_implementation(
153 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const& )
155 return cppu::acquire(static_cast<cppu::OWeakObject
*>(new ScXMLImport(
157 "com.sun.star.comp.Calc.XMLOasisContentImporter",
158 SvXMLImportFlags::AUTOSTYLES
|SvXMLImportFlags::CONTENT
|SvXMLImportFlags::SCRIPTS
|SvXMLImportFlags::FONTDECLS
,
159 uno::Sequence
< OUString
> { "com.sun.star.comp.Calc.XMLOasisContentImporter" })));
163 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
164 Calc_XMLOasisSettingsImporter_get_implementation(
165 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const& )
167 return cppu::acquire(static_cast<cppu::OWeakObject
*>(
170 "com.sun.star.comp.Calc.XMLOasisSettingsImporter",
171 SvXMLImportFlags::SETTINGS
,
172 { "com.sun.star.comp.Calc.XMLOasisSettingsImporter" } )));
175 const SvXMLTokenMap
& ScXMLImport::GetTableRowCellAttrTokenMap()
177 static const SvXMLTokenMapEntry aTableRowCellAttrTokenMap
[] =
179 { XML_NAMESPACE_TABLE
, XML_STYLE_NAME
, XML_TOK_TABLE_ROW_CELL_ATTR_STYLE_NAME
},
180 { XML_NAMESPACE_TABLE
, XML_CONTENT_VALIDATION_NAME
, XML_TOK_TABLE_ROW_CELL_ATTR_CONTENT_VALIDATION_NAME
},
181 { XML_NAMESPACE_TABLE
, XML_NUMBER_ROWS_SPANNED
, XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_ROWS
},
182 { XML_NAMESPACE_TABLE
, XML_NUMBER_COLUMNS_SPANNED
, XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_COLS
},
183 { XML_NAMESPACE_TABLE
, XML_NUMBER_MATRIX_COLUMNS_SPANNED
, XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_MATRIX_COLS
},
184 { XML_NAMESPACE_TABLE
, XML_NUMBER_MATRIX_ROWS_SPANNED
, XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_MATRIX_ROWS
},
185 { XML_NAMESPACE_TABLE
, XML_NUMBER_COLUMNS_REPEATED
, XML_TOK_TABLE_ROW_CELL_ATTR_REPEATED
},
186 { XML_NAMESPACE_OFFICE
, XML_VALUE_TYPE
, XML_TOK_TABLE_ROW_CELL_ATTR_VALUE_TYPE
},
187 { XML_NAMESPACE_CALC_EXT
, XML_VALUE_TYPE
, XML_TOK_TABLE_ROW_CELL_ATTR_NEW_VALUE_TYPE
},
188 { XML_NAMESPACE_OFFICE
, XML_VALUE
, XML_TOK_TABLE_ROW_CELL_ATTR_VALUE
},
189 { XML_NAMESPACE_OFFICE
, XML_DATE_VALUE
, XML_TOK_TABLE_ROW_CELL_ATTR_DATE_VALUE
},
190 { XML_NAMESPACE_OFFICE
, XML_TIME_VALUE
, XML_TOK_TABLE_ROW_CELL_ATTR_TIME_VALUE
},
191 { XML_NAMESPACE_OFFICE
, XML_STRING_VALUE
, XML_TOK_TABLE_ROW_CELL_ATTR_STRING_VALUE
},
192 { XML_NAMESPACE_OFFICE
, XML_BOOLEAN_VALUE
, XML_TOK_TABLE_ROW_CELL_ATTR_BOOLEAN_VALUE
},
193 { XML_NAMESPACE_TABLE
, XML_FORMULA
, XML_TOK_TABLE_ROW_CELL_ATTR_FORMULA
},
194 { XML_NAMESPACE_OFFICE
, XML_CURRENCY
, XML_TOK_TABLE_ROW_CELL_ATTR_CURRENCY
},
198 if ( !pTableRowCellAttrTokenMap
)
199 pTableRowCellAttrTokenMap
.reset(new SvXMLTokenMap( aTableRowCellAttrTokenMap
));
200 return *pTableRowCellAttrTokenMap
;
205 // NB: virtually inherit so we can multiply inherit properly
206 // in ScXMLFlatDocContext_Impl
207 class ScXMLDocContext_Impl
: public virtual SvXMLImportContext
210 ScXMLImport
& GetScImport() { return static_cast<ScXMLImport
&>(GetImport()); }
213 ScXMLDocContext_Impl( ScXMLImport
& rImport
);
215 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
216 createFastChildContext( sal_Int32 nElement
,
217 const css::uno::Reference
<css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
222 ScXMLDocContext_Impl::ScXMLDocContext_Impl( ScXMLImport
& rImport
) :
223 SvXMLImportContext( rImport
)
229 // context for flat file xml format
230 class ScXMLFlatDocContext_Impl
231 : public ScXMLDocContext_Impl
, public SvXMLMetaDocumentContext
235 ScXMLFlatDocContext_Impl( ScXMLImport
& i_rImport
,
236 const uno::Reference
<document::XDocumentProperties
>& i_xDocProps
);
238 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
239 createFastChildContext( sal_Int32 nElement
,
240 const css::uno::Reference
<css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
245 ScXMLFlatDocContext_Impl::ScXMLFlatDocContext_Impl( ScXMLImport
& i_rImport
,
246 const uno::Reference
<document::XDocumentProperties
>& i_xDocProps
) :
247 SvXMLImportContext(i_rImport
),
248 ScXMLDocContext_Impl(i_rImport
),
249 SvXMLMetaDocumentContext(i_rImport
, i_xDocProps
)
253 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
254 ScXMLFlatDocContext_Impl::createFastChildContext( sal_Int32 nElement
,
255 const uno::Reference
< xml::sax::XFastAttributeList
> & xAttrList
)
257 if ( nElement
== XML_ELEMENT( OFFICE
, XML_META
) )
258 return SvXMLMetaDocumentContext::createFastChildContext( nElement
, xAttrList
);
260 return ScXMLDocContext_Impl::createFastChildContext( nElement
, xAttrList
);
265 class ScXMLBodyContext_Impl
: public ScXMLImportContext
268 ScXMLBodyContext_Impl( ScXMLImport
& rImport
);
270 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
271 createFastChildContext( sal_Int32 nElement
,
272 const css::uno::Reference
<css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
277 ScXMLBodyContext_Impl::ScXMLBodyContext_Impl( ScXMLImport
& rImport
) :
278 ScXMLImportContext( rImport
)
282 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
283 ScXMLBodyContext_Impl::createFastChildContext( sal_Int32
/*nElement*/,
284 const uno::Reference
< xml::sax::XFastAttributeList
> & xAttrList
)
286 sax_fastparser::FastAttributeList
*pAttribList
=
287 &sax_fastparser::castToFastAttributeList( xAttrList
);
288 return GetScImport().CreateBodyContext( pAttribList
);
291 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
292 ScXMLDocContext_Impl::createFastChildContext( sal_Int32 nElement
,
293 const uno::Reference
< xml::sax::XFastAttributeList
> & /*xAttrList*/ )
295 SvXMLImportContext
*pContext(nullptr);
299 case XML_ELEMENT( OFFICE
, XML_BODY
):
300 if (GetScImport().getImportFlags() & SvXMLImportFlags::CONTENT
)
301 pContext
= new ScXMLBodyContext_Impl( GetScImport() );
303 case XML_ELEMENT( OFFICE
, XML_SCRIPTS
):
304 if (GetScImport().getImportFlags() & SvXMLImportFlags::SCRIPTS
)
305 pContext
= GetScImport().CreateScriptContext();
307 case XML_ELEMENT( OFFICE
, XML_SETTINGS
):
308 if (GetScImport().getImportFlags() & SvXMLImportFlags::SETTINGS
)
309 pContext
= new XMLDocumentSettingsContext(GetScImport());
311 case XML_ELEMENT(OFFICE
, XML_STYLES
):
312 if (GetScImport().getImportFlags() & SvXMLImportFlags::STYLES
)
313 pContext
= GetScImport().CreateStylesContext( false);
315 case XML_ELEMENT(OFFICE
, XML_AUTOMATIC_STYLES
):
316 if (GetScImport().getImportFlags() & SvXMLImportFlags::AUTOSTYLES
)
317 pContext
= GetScImport().CreateStylesContext( true);
319 case XML_ELEMENT(OFFICE
, XML_FONT_FACE_DECLS
):
320 if (GetScImport().getImportFlags() & SvXMLImportFlags::FONTDECLS
)
321 pContext
= GetScImport().CreateFontDeclsContext();
323 case XML_ELEMENT(OFFICE
, XML_MASTER_STYLES
):
324 if (GetScImport().getImportFlags() & SvXMLImportFlags::MASTERSTYLES
)
325 pContext
= new ScXMLMasterStylesContext( GetImport() );
327 case XML_ELEMENT(OFFICE
, XML_META
):
328 SAL_INFO("sc", "XML_ELEMENT(OFFICE, XML_META): should not have come here, maybe document is invalid?");
335 const SvXMLTokenMap
& ScXMLImport::GetTableElemTokenMap()
337 if( !pTableElemTokenMap
)
339 static const SvXMLTokenMapEntry aTableTokenMap
[] =
341 { XML_NAMESPACE_TABLE
, XML_NAMED_EXPRESSIONS
, XML_TOK_TABLE_NAMED_EXPRESSIONS
},
342 { XML_NAMESPACE_TABLE
, XML_TABLE_COLUMN_GROUP
, XML_TOK_TABLE_COL_GROUP
},
343 { XML_NAMESPACE_TABLE
, XML_TABLE_HEADER_COLUMNS
, XML_TOK_TABLE_HEADER_COLS
},
344 { XML_NAMESPACE_TABLE
, XML_TABLE_COLUMNS
, XML_TOK_TABLE_COLS
},
345 { XML_NAMESPACE_TABLE
, XML_TABLE_COLUMN
, XML_TOK_TABLE_COL
},
346 { XML_NAMESPACE_TABLE
, XML_TABLE_PROTECTION
, XML_TOK_TABLE_PROTECTION
},
347 { XML_NAMESPACE_LO_EXT
, XML_TABLE_PROTECTION
, XML_TOK_TABLE_PROTECTION_EXT
},
348 { XML_NAMESPACE_OFFICE_EXT
, XML_TABLE_PROTECTION
, XML_TOK_TABLE_PROTECTION_EXT
},
349 { XML_NAMESPACE_TABLE
, XML_TABLE_ROW_GROUP
, XML_TOK_TABLE_ROW_GROUP
},
350 { XML_NAMESPACE_TABLE
, XML_TABLE_HEADER_ROWS
, XML_TOK_TABLE_HEADER_ROWS
},
351 { XML_NAMESPACE_TABLE
, XML_TABLE_ROWS
, XML_TOK_TABLE_ROWS
},
352 { XML_NAMESPACE_TABLE
, XML_TABLE_ROW
, XML_TOK_TABLE_ROW
},
353 { XML_NAMESPACE_TABLE
, XML_TABLE_SOURCE
, XML_TOK_TABLE_SOURCE
},
354 { XML_NAMESPACE_TABLE
, XML_SCENARIO
, XML_TOK_TABLE_SCENARIO
},
355 { XML_NAMESPACE_TABLE
, XML_SHAPES
, XML_TOK_TABLE_SHAPES
},
356 { XML_NAMESPACE_OFFICE
, XML_FORMS
, XML_TOK_TABLE_FORMS
},
357 { XML_NAMESPACE_OFFICE
, XML_EVENT_LISTENERS
, XML_TOK_TABLE_EVENT_LISTENERS
},
358 { XML_NAMESPACE_OFFICE_EXT
, XML_EVENT_LISTENERS
, XML_TOK_TABLE_EVENT_LISTENERS_EXT
},
359 { XML_NAMESPACE_CALC_EXT
, XML_CONDITIONAL_FORMATS
, XML_TOK_TABLE_CONDFORMATS
},
363 pTableElemTokenMap
.reset(new SvXMLTokenMap( aTableTokenMap
));
364 } // if( !pTableElemTokenMap )
366 return *pTableElemTokenMap
;
369 const SvXMLTokenMap
& ScXMLImport::GetTableRowsElemTokenMap()
371 if( !pTableRowsElemTokenMap
)
373 static const SvXMLTokenMapEntry aTableRowsElemTokenMap
[] =
375 { XML_NAMESPACE_TABLE
, XML_TABLE_ROW_GROUP
, XML_TOK_TABLE_ROWS_ROW_GROUP
},
376 { XML_NAMESPACE_TABLE
, XML_TABLE_HEADER_ROWS
, XML_TOK_TABLE_ROWS_HEADER_ROWS
},
377 { XML_NAMESPACE_TABLE
, XML_TABLE_ROWS
, XML_TOK_TABLE_ROWS_ROWS
},
378 { XML_NAMESPACE_TABLE
, XML_TABLE_ROW
, XML_TOK_TABLE_ROWS_ROW
},
382 pTableRowsElemTokenMap
.reset(new SvXMLTokenMap( aTableRowsElemTokenMap
));
383 } // if( !pTableRowsElemTokenMap )
385 return *pTableRowsElemTokenMap
;
388 const SvXMLTokenMap
& ScXMLImport::GetTableRowElemTokenMap()
390 if( !pTableRowElemTokenMap
)
392 static const SvXMLTokenMapEntry aTableRowTokenMap
[] =
394 { XML_NAMESPACE_TABLE
, XML_TABLE_CELL
, XML_TOK_TABLE_ROW_CELL
},
395 { XML_NAMESPACE_TABLE
, XML_COVERED_TABLE_CELL
, XML_TOK_TABLE_ROW_COVERED_CELL
},
399 pTableRowElemTokenMap
.reset(new SvXMLTokenMap( aTableRowTokenMap
));
400 } // if( !pTableRowElemTokenMap )
402 return *pTableRowElemTokenMap
;
405 const SvXMLTokenMap
& ScXMLImport::GetTableRowAttrTokenMap()
407 if( !pTableRowAttrTokenMap
)
409 static const SvXMLTokenMapEntry aTableRowAttrTokenMap
[] =
411 { XML_NAMESPACE_TABLE
, XML_STYLE_NAME
, XML_TOK_TABLE_ROW_ATTR_STYLE_NAME
},
412 { XML_NAMESPACE_TABLE
, XML_VISIBILITY
, XML_TOK_TABLE_ROW_ATTR_VISIBILITY
},
413 { XML_NAMESPACE_TABLE
, XML_NUMBER_ROWS_REPEATED
, XML_TOK_TABLE_ROW_ATTR_REPEATED
},
414 { XML_NAMESPACE_TABLE
, XML_DEFAULT_CELL_STYLE_NAME
, XML_TOK_TABLE_ROW_ATTR_DEFAULT_CELL_STYLE_NAME
},
415 // { XML_NAMESPACE_TABLE, XML_USE_OPTIMAL_HEIGHT, XML_TOK_TABLE_ROW_ATTR_USE_OPTIMAL_HEIGHT },
419 pTableRowAttrTokenMap
.reset(new SvXMLTokenMap( aTableRowAttrTokenMap
));
420 } // if( !pTableRowAttrTokenMap )
422 return *pTableRowAttrTokenMap
;
425 const SvXMLTokenMap
& ScXMLImport::GetTableRowCellElemTokenMap()
427 if( !pTableRowCellElemTokenMap
)
429 static const SvXMLTokenMapEntry aTableRowCellTokenMap
[] =
431 { XML_NAMESPACE_TEXT
, XML_P
, XML_TOK_TABLE_ROW_CELL_P
},
432 { XML_NAMESPACE_TABLE
, XML_SUB_TABLE
, XML_TOK_TABLE_ROW_CELL_TABLE
},
433 { XML_NAMESPACE_OFFICE
, XML_ANNOTATION
, XML_TOK_TABLE_ROW_CELL_ANNOTATION
},
434 { XML_NAMESPACE_TABLE
, XML_DETECTIVE
, XML_TOK_TABLE_ROW_CELL_DETECTIVE
},
435 { XML_NAMESPACE_TABLE
, XML_CELL_RANGE_SOURCE
, XML_TOK_TABLE_ROW_CELL_CELL_RANGE_SOURCE
},
439 pTableRowCellElemTokenMap
.reset(new SvXMLTokenMap( aTableRowCellTokenMap
));
440 } // if( !pTableRowCellElemTokenMap )
442 return *pTableRowCellElemTokenMap
;
445 const SvXMLTokenMap
& ScXMLImport::GetTableAnnotationAttrTokenMap()
447 if( !pTableAnnotationAttrTokenMap
)
449 static const SvXMLTokenMapEntry aTableAnnotationAttrTokenMap
[] =
451 { XML_NAMESPACE_OFFICE
, XML_AUTHOR
, XML_TOK_TABLE_ANNOTATION_ATTR_AUTHOR
},
452 { XML_NAMESPACE_OFFICE
, XML_CREATE_DATE
, XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE
},
453 { XML_NAMESPACE_OFFICE
, XML_CREATE_DATE_STRING
, XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE_STRING
},
454 { XML_NAMESPACE_OFFICE
, XML_DISPLAY
, XML_TOK_TABLE_ANNOTATION_ATTR_DISPLAY
},
455 { XML_NAMESPACE_SVG
, XML_X
, XML_TOK_TABLE_ANNOTATION_ATTR_X
},
456 { XML_NAMESPACE_SVG
, XML_Y
, XML_TOK_TABLE_ANNOTATION_ATTR_Y
},
460 pTableAnnotationAttrTokenMap
.reset(new SvXMLTokenMap( aTableAnnotationAttrTokenMap
));
461 } // if( !pTableAnnotationAttrTokenMap )
463 return *pTableAnnotationAttrTokenMap
;
467 void ScXMLImport::SetPostProcessData( sc::ImportPostProcessData
* p
)
469 mpPostProcessData
= p
;
472 sc::PivotTableSources
& ScXMLImport::GetPivotTableSources()
475 mpPivotSources
.reset(new sc::PivotTableSources
);
477 return *mpPivotSources
;
480 SvXMLImportContext
*ScXMLImport::CreateFastContext( sal_Int32 nElement
,
481 const uno::Reference
< xml::sax::XFastAttributeList
>& /*xAttrList*/ )
483 SvXMLImportContext
*pContext
= nullptr;
487 case XML_ELEMENT( OFFICE
, XML_DOCUMENT_STYLES
):
488 case XML_ELEMENT( OFFICE
, XML_DOCUMENT_CONTENT
):
489 case XML_ELEMENT( OFFICE
, XML_DOCUMENT_SETTINGS
):
490 pContext
= new ScXMLDocContext_Impl( *this );
493 case XML_ELEMENT( OFFICE
, XML_DOCUMENT_META
):
494 pContext
= CreateMetaContext(nElement
);
497 case XML_ELEMENT( OFFICE
, XML_DOCUMENT
):
499 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
500 GetModel(), uno::UNO_QUERY_THROW
);
501 // flat OpenDocument file format
502 pContext
= new ScXMLFlatDocContext_Impl( *this,
503 xDPS
->getDocumentProperties());
512 constexpr OUStringLiteral
gsNumberFormat(u
"" SC_UNONAME_NUMFMT
);
513 constexpr OUStringLiteral
gsLocale(u
"" SC_LOCALE
);
514 constexpr OUStringLiteral
gsCellStyle(u
"" SC_UNONAME_CELLSTYL
);
516 ScXMLImport::ScXMLImport(
517 const css::uno::Reference
< css::uno::XComponentContext
>& rContext
,
518 OUString
const & implementationName
, SvXMLImportFlags nImportFlag
,
519 const css::uno::Sequence
< OUString
> & sSupportedServiceNames
)
520 : SvXMLImport( rContext
, implementationName
, nImportFlag
, sSupportedServiceNames
),
522 mpPostProcessData(nullptr),
526 nSolarMutexLocked(0),
530 bNullDateSetted(false),
531 bSelfImportingXMLSet(false),
532 mbLockSolarMutex(true),
533 mbImportStyles(true),
534 mbHasNewCondFormatData(false)
536 pStylesImportHelper
.reset(new ScMyStylesImportHelper(*this));
538 xScPropHdlFactory
= new XMLScPropHdlFactory
;
539 xCellStylesPropertySetMapper
= new XMLPropertySetMapper(aXMLScCellStylesProperties
, xScPropHdlFactory
, false);
540 xColumnStylesPropertySetMapper
= new XMLPropertySetMapper(aXMLScColumnStylesProperties
, xScPropHdlFactory
, false);
541 xRowStylesPropertySetMapper
= new XMLPropertySetMapper(aXMLScRowStylesImportProperties
, xScPropHdlFactory
, false);
542 xTableStylesPropertySetMapper
= new XMLPropertySetMapper(aXMLScTableStylesImportProperties
, xScPropHdlFactory
, false);
544 // #i66550# needed for 'presentation:event-listener' element for URLs in shapes
545 GetNamespaceMap().Add(
546 GetXMLToken( XML_NP_PRESENTATION
),
547 GetXMLToken( XML_N_PRESENTATION
),
548 XML_NAMESPACE_PRESENTATION
);
551 ScXMLImport::~ScXMLImport() throw()
554 pTableElemTokenMap
.reset();
555 pTableRowsElemTokenMap
.reset();
556 pTableRowElemTokenMap
.reset();
557 pTableRowAttrTokenMap
.reset();
558 pTableRowCellElemTokenMap
.reset();
559 pTableRowCellAttrTokenMap
.reset();
560 pTableAnnotationAttrTokenMap
.reset();
562 pChangeTrackingImportHelper
.reset();
563 pNumberFormatAttributesExportHelper
.reset();
564 pStyleNumberFormats
.reset();
565 pStylesImportHelper
.reset();
567 m_pMyNamedExpressions
.reset();
568 pMyLabelRanges
.reset();
569 pValidations
.reset();
570 pDetectiveOpArray
.reset();
572 //call SvXMLImport dtor contents before deleting pSolarMutexGuard
575 pSolarMutexGuard
.reset();
578 void ScXMLImport::initialize( const css::uno::Sequence
<css::uno::Any
>& aArguments
)
580 SvXMLImport::initialize(aArguments
);
582 uno::Reference
<beans::XPropertySet
> xInfoSet
= getImportInfo();
586 uno::Reference
<beans::XPropertySetInfo
> xInfoSetInfo
= xInfoSet
->getPropertySetInfo();
587 if (!xInfoSetInfo
.is())
590 if (xInfoSetInfo
->hasPropertyByName(SC_UNO_ODS_LOCK_SOLAR_MUTEX
))
591 xInfoSet
->getPropertyValue(SC_UNO_ODS_LOCK_SOLAR_MUTEX
) >>= mbLockSolarMutex
;
593 if (xInfoSetInfo
->hasPropertyByName(SC_UNO_ODS_IMPORT_STYLES
))
594 xInfoSet
->getPropertyValue(SC_UNO_ODS_IMPORT_STYLES
) >>= mbImportStyles
;
597 SvXMLImportContext
*ScXMLImport::CreateFontDeclsContext()
599 XMLFontStylesContext
*pFSContext
= new XMLFontStylesContext(
600 *this, osl_getThreadTextEncoding());
601 SetFontDecls(pFSContext
);
602 SvXMLImportContext
* pContext
= pFSContext
;
606 SvXMLImportContext
*ScXMLImport::CreateStylesContext( bool bIsAutoStyle
)
608 SvXMLImportContext
* pContext
= new XMLTableStylesContext(
609 *this, bIsAutoStyle
);
612 SetAutoStyles(static_cast<SvXMLStylesContext
*>(pContext
));
614 SetStyles(static_cast<SvXMLStylesContext
*>(pContext
));
619 SvXMLImportContext
*ScXMLImport::CreateBodyContext(const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
)
621 return new ScXMLBodyContext(*this, rAttrList
);
624 SvXMLImportContext
*ScXMLImport::CreateMetaContext(
625 const sal_Int32
/*nElement*/ )
627 SvXMLImportContext
* pContext
= nullptr;
629 if (getImportFlags() & SvXMLImportFlags::META
)
631 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
632 GetModel(), uno::UNO_QUERY_THROW
);
633 uno::Reference
<document::XDocumentProperties
> const xDocProps(
634 (IsStylesOnlyMode()) ? nullptr : xDPS
->getDocumentProperties());
635 pContext
= new SvXMLMetaDocumentContext(*this, xDocProps
);
641 SvXMLImportContext
*ScXMLImport::CreateScriptContext()
643 SvXMLImportContext
* pContext
= nullptr;
645 if( !(IsStylesOnlyMode()) )
647 pContext
= new XMLScriptContext( *this, GetModel() );
653 void ScXMLImport::SetStatistics(const uno::Sequence
<beans::NamedValue
> & i_rStats
)
655 static const char* s_stats
[] =
656 { "TableCount", "CellCount", "ObjectCount", nullptr };
658 SvXMLImport::SetStatistics(i_rStats
);
660 sal_uInt32
nCount(0);
661 for (const auto& rStat
: i_rStats
) {
662 for (const char** pStat
= s_stats
; *pStat
!= nullptr; ++pStat
) {
663 if (rStat
.Name
.equalsAscii(*pStat
)) {
665 if (rStat
.Value
>>= val
) {
668 OSL_FAIL("ScXMLImport::SetStatistics: invalid entry");
676 GetProgressBarHelper()->SetReference(nCount
);
677 GetProgressBarHelper()->SetValue(0);
681 ScDocumentImport
& ScXMLImport::GetDoc()
686 sal_Int16
ScXMLImport::GetCellType(const char* rStrValue
, const sal_Int32 nStrLength
)
688 sal_Int16 nCellType
= util::NumberFormat::UNDEFINED
;
689 if (rStrValue
!= nullptr)
691 switch (rStrValue
[0])
694 if (nStrLength
== 7 && !strcmp(rStrValue
, "boolean"))
695 nCellType
= util::NumberFormat::LOGICAL
;
698 if (nStrLength
== 8 && !strcmp(rStrValue
, "currency"))
699 nCellType
= util::NumberFormat::CURRENCY
;
702 if (nStrLength
== 4 && !strcmp(rStrValue
, "date"))
703 nCellType
= util::NumberFormat::DATETIME
;
706 if (nStrLength
== 5 && !strcmp(rStrValue
, "float"))
707 nCellType
= util::NumberFormat::NUMBER
;
710 if (nStrLength
== 10 && !strcmp(rStrValue
, "percentage"))
711 nCellType
= util::NumberFormat::PERCENT
;
714 if (nStrLength
== 6 && !strcmp(rStrValue
, "string"))
715 nCellType
= util::NumberFormat::TEXT
;
718 if (nStrLength
== 4 && !strcmp(rStrValue
, "time"))
719 nCellType
= util::NumberFormat::TIME
;
727 XMLShapeImportHelper
* ScXMLImport::CreateShapeImport()
729 return new XMLTableShapeImportHelper(*this);
732 bool ScXMLImport::GetValidation(const OUString
& sName
, ScMyImportValidation
& aValidation
)
736 auto aItr
= std::find_if(pValidations
->begin(), pValidations
->end(),
737 [&sName
](const ScMyImportValidation
& rValidation
) { return rValidation
.sName
== sName
; });
738 if (aItr
!= pValidations
->end())
740 // source position must be set as string,
741 // so sBaseCellAddress no longer has to be converted here
749 void ScXMLImport::AddNamedExpression(SCTAB nTab
, ScMyNamedExpression
* pNamedExp
)
751 ::std::unique_ptr
<ScMyNamedExpression
> p(pNamedExp
);
752 SheetNamedExpMap::iterator itr
= m_SheetNamedExpressions
.find(nTab
);
753 if (itr
== m_SheetNamedExpressions
.end())
755 // No chain exists for this sheet. Create one.
756 ::std::pair
<SheetNamedExpMap::iterator
, bool> r
=
757 m_SheetNamedExpressions
.insert(std::make_pair(nTab
, std::make_unique
<ScMyNamedExpressions
>()));
764 ScMyNamedExpressions
& r
= *itr
->second
;
765 r
.push_back(std::move(p
));
768 ScXMLChangeTrackingImportHelper
* ScXMLImport::GetChangeTrackingImportHelper()
770 if (!pChangeTrackingImportHelper
)
771 pChangeTrackingImportHelper
.reset(new ScXMLChangeTrackingImportHelper());
772 return pChangeTrackingImportHelper
.get();
775 void ScXMLImport::InsertStyles()
777 GetStyles()->CopyStylesToDoc(true);
779 // if content is going to be loaded with the same import, set bLatinDefaultStyle flag now
780 if ( getImportFlags() & SvXMLImportFlags::CONTENT
)
781 ExamineDefaultStyle();
784 void ScXMLImport::ExamineDefaultStyle()
788 // #i62435# after inserting the styles, check if the default style has a latin-script-only
789 // number format (then, value cells can be pre-initialized with western script type)
791 const ScPatternAttr
* pDefPattern
= pDoc
->GetDefPattern();
792 if (pDefPattern
&& sc::NumFmtUtil::isLatinScript(*pDefPattern
, *pDoc
))
793 mpDocImport
->setDefaultNumericScript(SvtScriptType::LATIN
);
797 void ScXMLImport::SetChangeTrackingViewSettings(const css::uno::Sequence
<css::beans::PropertyValue
>& rChangeProps
)
802 if (!rChangeProps
.hasElements())
805 ScXMLImport::MutexGuard
aGuard(*this);
806 sal_Int16
nTemp16(0);
807 std::unique_ptr
<ScChangeViewSettings
> pViewSettings(new ScChangeViewSettings());
808 for (const auto& rChangeProp
: rChangeProps
)
810 OUString
sName(rChangeProp
.Name
);
811 if (sName
== "ShowChanges")
812 pViewSettings
->SetShowChanges(::cppu::any2bool(rChangeProp
.Value
));
813 else if (sName
== "ShowAcceptedChanges")
814 pViewSettings
->SetShowAccepted(::cppu::any2bool(rChangeProp
.Value
));
815 else if (sName
== "ShowRejectedChanges")
816 pViewSettings
->SetShowRejected(::cppu::any2bool(rChangeProp
.Value
));
817 else if (sName
== "ShowChangesByDatetime")
818 pViewSettings
->SetHasDate(::cppu::any2bool(rChangeProp
.Value
));
819 else if (sName
== "ShowChangesByDatetimeMode")
821 if (rChangeProp
.Value
>>= nTemp16
)
822 pViewSettings
->SetTheDateMode(static_cast<SvxRedlinDateMode
>(nTemp16
));
824 else if (sName
== "ShowChangesByDatetimeFirstDatetime")
826 util::DateTime aDateTime
;
827 if (rChangeProp
.Value
>>= aDateTime
)
829 pViewSettings
->SetTheFirstDateTime(::DateTime(aDateTime
));
832 else if (sName
== "ShowChangesByDatetimeSecondDatetime")
834 util::DateTime aDateTime
;
835 if (rChangeProp
.Value
>>= aDateTime
)
837 pViewSettings
->SetTheLastDateTime(::DateTime(aDateTime
));
840 else if (sName
== "ShowChangesByAuthor")
841 pViewSettings
->SetHasAuthor(::cppu::any2bool(rChangeProp
.Value
));
842 else if (sName
== "ShowChangesByAuthorName")
845 if (rChangeProp
.Value
>>= sOUName
)
847 pViewSettings
->SetTheAuthorToShow(sOUName
);
850 else if (sName
== "ShowChangesByComment")
851 pViewSettings
->SetHasComment(::cppu::any2bool(rChangeProp
.Value
));
852 else if (sName
== "ShowChangesByCommentText")
855 if (rChangeProp
.Value
>>= sOUComment
)
857 pViewSettings
->SetTheComment(sOUComment
);
860 else if (sName
== "ShowChangesByRanges")
861 pViewSettings
->SetHasRange(::cppu::any2bool(rChangeProp
.Value
));
862 else if (sName
== "ShowChangesByRangesList")
865 if ((rChangeProp
.Value
>>= sRanges
) && !sRanges
.isEmpty())
867 ScRangeList aRangeList
;
868 ScRangeStringConverter::GetRangeListFromString(
869 aRangeList
, sRanges
, *pDoc
, FormulaGrammar::CONV_OOO
);
870 pViewSettings
->SetTheRangeList(aRangeList
);
874 pDoc
->SetChangeViewSettings(*pViewSettings
);
877 void ScXMLImport::SetViewSettings(const uno::Sequence
<beans::PropertyValue
>& aViewProps
)
879 sal_Int32
nHeight(0);
883 for (const auto& rViewProp
: aViewProps
)
885 OUString
sName(rViewProp
.Name
);
886 if (sName
== "VisibleAreaHeight")
887 rViewProp
.Value
>>= nHeight
;
888 else if (sName
== "VisibleAreaLeft")
889 rViewProp
.Value
>>= nLeft
;
890 else if (sName
== "VisibleAreaTop")
891 rViewProp
.Value
>>= nTop
;
892 else if (sName
== "VisibleAreaWidth")
893 rViewProp
.Value
>>= nWidth
;
894 else if (sName
== "TrackedChangesViewSettings")
896 uno::Sequence
<beans::PropertyValue
> aChangeProps
;
897 if(rViewProp
.Value
>>= aChangeProps
)
898 SetChangeTrackingViewSettings(aChangeProps
);
901 if (!(nHeight
&& nWidth
&& GetModel().is()))
904 ScModelObj
* pDocObj(comphelper::getUnoTunnelImplementation
<ScModelObj
>( GetModel() ));
908 SfxObjectShell
* pEmbeddedObj
= pDocObj
->GetEmbeddedObject();
911 tools::Rectangle aRect
;
914 aRect
.setWidth( nWidth
);
915 aRect
.setHeight( nHeight
);
916 pEmbeddedObj
->SetVisArea(aRect
);
920 void ScXMLImport::SetConfigurationSettings(const uno::Sequence
<beans::PropertyValue
>& aConfigProps
)
922 if (!GetModel().is())
925 uno::Reference
<lang::XMultiServiceFactory
> xMultiServiceFactory(GetModel(), uno::UNO_QUERY
);
926 if (!xMultiServiceFactory
.is())
929 sal_Int32
nCount(aConfigProps
.getLength());
930 css::uno::Sequence
<css::beans::PropertyValue
> aFilteredProps(nCount
);
931 sal_Int32 nFilteredPropsLen
= 0;
932 for (sal_Int32 i
= nCount
- 1; i
>= 0; --i
)
934 if (aConfigProps
[i
].Name
== "TrackedChangesProtectionKey")
937 if (aConfigProps
[i
].Value
>>= sKey
)
939 uno::Sequence
<sal_Int8
> aPass
;
940 ::comphelper::Base64::decode(aPass
, sKey
);
941 if (aPass
.hasElements())
943 if (pDoc
->GetChangeTrack())
944 pDoc
->GetChangeTrack()->SetProtection(aPass
);
947 std::set
<OUString
> aUsers
;
948 std::unique_ptr
<ScChangeTrack
> pTrack( new ScChangeTrack(*pDoc
, aUsers
) );
949 pTrack
->SetProtection(aPass
);
950 pDoc
->SetChangeTrack(std::move(pTrack
));
955 // store the following items for later use (after document is loaded)
956 else if ((aConfigProps
[i
].Name
== "VBACompatibilityMode") || (aConfigProps
[i
].Name
== "ScriptConfiguration"))
958 uno::Reference
< beans::XPropertySet
> xImportInfo
= getImportInfo();
959 if (xImportInfo
.is())
961 uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo
= xImportInfo
->getPropertySetInfo();
962 if (xPropertySetInfo
.is() && xPropertySetInfo
->hasPropertyByName(aConfigProps
[i
].Name
))
963 xImportInfo
->setPropertyValue( aConfigProps
[i
].Name
, aConfigProps
[i
].Value
);
966 if (aConfigProps
[i
].Name
!= "LinkUpdateMode")
968 aFilteredProps
[nFilteredPropsLen
++] = aConfigProps
[i
];
971 aFilteredProps
.realloc(nFilteredPropsLen
);
972 uno::Reference
<uno::XInterface
> xInterface
= xMultiServiceFactory
->createInstance("com.sun.star.comp.SpreadsheetSettings");
973 uno::Reference
<beans::XPropertySet
> xProperties(xInterface
, uno::UNO_QUERY
);
974 if (xProperties
.is())
975 SvXMLUnitConverter::convertPropertySet(xProperties
, aFilteredProps
);
978 sal_Int32
ScXMLImport::SetCurrencySymbol(const sal_Int32 nKey
, const OUString
& rCurrency
)
980 uno::Reference
<util::XNumberFormatsSupplier
> xNumberFormatsSupplier(GetNumberFormatsSupplier());
981 if (xNumberFormatsSupplier
.is())
983 uno::Reference
<util::XNumberFormats
> xLocalNumberFormats(xNumberFormatsSupplier
->getNumberFormats());
984 if (xLocalNumberFormats
.is())
986 OUString sFormatString
;
989 uno::Reference
<beans::XPropertySet
> xProperties(xLocalNumberFormats
->getByKey(nKey
));
990 if (xProperties
.is())
992 lang::Locale aLocale
;
993 if (GetDocument() && (xProperties
->getPropertyValue(gsLocale
) >>= aLocale
))
996 ScXMLImport::MutexGuard
aGuard(*this);
997 LocaleDataWrapper
aLocaleData( comphelper::getProcessComponentContext(), LanguageTag( aLocale
) );
998 OUStringBuffer
aBuffer(15);
1000 aBuffer
.append( aLocaleData
.getNumThousandSep() );
1001 aBuffer
.append("##0");
1002 aBuffer
.append( aLocaleData
.getNumDecimalSep() );
1003 aBuffer
.append("00 [$");
1004 aBuffer
.append(rCurrency
);
1005 aBuffer
.append("]");
1006 sFormatString
= aBuffer
.makeStringAndClear();
1008 sal_Int32 nNewKey
= xLocalNumberFormats
->queryKey(sFormatString
, aLocale
, true);
1010 nNewKey
= xLocalNumberFormats
->addNew(sFormatString
, aLocale
);
1015 catch ( const util::MalformedNumberFormatException
& rException
)
1017 OUString sErrorMessage
="Error in Formatstring " +
1018 sFormatString
+ " at position " +
1019 OUString::number(rException
.CheckPos
);
1020 uno::Sequence
<OUString
> aSeq
{ sErrorMessage
};
1021 uno::Reference
<xml::sax::XLocator
> xLocator
;
1022 SetError(XMLERROR_API
| XMLERROR_FLAG_ERROR
, aSeq
, rException
.Message
, xLocator
);
1029 bool ScXMLImport::IsCurrencySymbol(const sal_Int32 nNumberFormat
, const OUString
& sCurrentCurrency
, const OUString
& sBankSymbol
)
1031 uno::Reference
<util::XNumberFormatsSupplier
> xNumberFormatsSupplier(GetNumberFormatsSupplier());
1032 if (xNumberFormatsSupplier
.is())
1034 uno::Reference
<util::XNumberFormats
> xLocalNumberFormats(xNumberFormatsSupplier
->getNumberFormats());
1035 if (xLocalNumberFormats
.is())
1039 uno::Reference
<beans::XPropertySet
> xNumberPropertySet(xLocalNumberFormats
->getByKey(nNumberFormat
));
1040 if (xNumberPropertySet
.is())
1043 if ( xNumberPropertySet
->getPropertyValue(SC_CURRENCYSYMBOL
) >>= sTemp
)
1045 if (sCurrentCurrency
== sTemp
)
1047 // A release that saved an unknown currency may have
1048 // saved the currency symbol of the number format
1049 // instead of an ISO code bank symbol. In another
1050 // release we may have a match for that. In this case
1051 // sCurrentCurrency is the ISO code obtained through
1052 // XMLNumberFormatAttributesExportHelper::GetCellType()
1053 // and sBankSymbol is the currency symbol.
1054 if (sCurrentCurrency
.getLength() == 3 && sBankSymbol
== sTemp
)
1056 // #i61657# This may be a legacy currency symbol that changed in the meantime.
1057 if (SvNumberFormatter::GetLegacyOnlyCurrencyEntry( sCurrentCurrency
, sBankSymbol
) != nullptr)
1059 // In the rare case that sCurrentCurrency is not the
1060 // currency symbol, but a matching ISO code
1061 // abbreviation instead that was obtained through
1062 // XMLNumberFormatAttributesExportHelper::GetCellType(),
1063 // check with the number format's symbol. This happens,
1064 // for example, in the es_BO locale, where a legacy
1065 // B$,BOB matched B$->BOP, which leads to
1066 // sCurrentCurrency being BOP, and the previous call
1067 // with BOP,BOB didn't find an entry, but B$,BOB will.
1068 return SvNumberFormatter::GetLegacyOnlyCurrencyEntry( sTemp
, sBankSymbol
) != nullptr;
1072 catch ( uno::Exception
& )
1074 OSL_FAIL("Numberformat not found");
1081 void ScXMLImport::SetType(const uno::Reference
<beans::XPropertySet
>& rProperties
,
1082 sal_Int32
& rNumberFormat
,
1083 const sal_Int16 nCellType
,
1084 const OUString
& rCurrency
)
1086 if (!mbImportStyles
)
1089 if ((nCellType
== util::NumberFormat::TEXT
) || (nCellType
== util::NumberFormat::UNDEFINED
))
1092 if (rNumberFormat
== -1)
1093 rProperties
->getPropertyValue( gsNumberFormat
) >>= rNumberFormat
;
1094 OSL_ENSURE(rNumberFormat
!= -1, "no NumberFormat");
1096 // sCurrentCurrency may be the ISO code abbreviation if the currency
1097 // symbol matches such, or if no match found the symbol itself!
1098 OUString sCurrentCurrency
;
1099 sal_Int32
nCurrentCellType(
1100 GetNumberFormatAttributesExportHelper()->GetCellType(
1101 rNumberFormat
, sCurrentCurrency
, bIsStandard
) & ~util::NumberFormat::DEFINED
);
1102 // If the (numeric) cell type (number, currency, date, time, boolean)
1103 // is different from the format type then for some combinations we may
1104 // have to apply a format, e.g. in case the generator deduced format
1105 // from type and did not apply a format but we don't keep a dedicated
1106 // type internally. Specifically this is necessary if the cell type is
1107 // not number but the format type is (i.e. General). Currency cells
1108 // need extra attention, see calls of ScXMLImport::IsCurrencySymbol()
1109 // and description within there and ScXMLImport::SetCurrencySymbol().
1110 if ((nCellType
!= nCurrentCellType
) &&
1111 (nCellType
!= util::NumberFormat::NUMBER
) &&
1112 (bIsStandard
|| (nCellType
== util::NumberFormat::CURRENCY
)))
1114 if (!xNumberFormats
.is())
1116 uno::Reference
<util::XNumberFormatsSupplier
> xNumberFormatsSupplier(GetNumberFormatsSupplier());
1117 if (xNumberFormatsSupplier
.is())
1118 xNumberFormats
.set(xNumberFormatsSupplier
->getNumberFormats());
1120 if (xNumberFormats
.is())
1124 uno::Reference
< beans::XPropertySet
> xNumberFormatProperties(xNumberFormats
->getByKey(rNumberFormat
));
1125 if (xNumberFormatProperties
.is())
1127 if (nCellType
!= util::NumberFormat::CURRENCY
)
1129 lang::Locale aLocale
;
1130 if ( xNumberFormatProperties
->getPropertyValue(gsLocale
) >>= aLocale
)
1132 if (!xNumberFormatTypes
.is())
1133 xNumberFormatTypes
.set(uno::Reference
<util::XNumberFormatTypes
>(xNumberFormats
, uno::UNO_QUERY
));
1134 rProperties
->setPropertyValue( gsNumberFormat
, uno::makeAny(xNumberFormatTypes
->getStandardFormat(nCellType
, aLocale
)) );
1137 else if (!rCurrency
.isEmpty() && !sCurrentCurrency
.isEmpty())
1139 if (sCurrentCurrency
!= rCurrency
)
1140 if (!IsCurrencySymbol(rNumberFormat
, sCurrentCurrency
, rCurrency
))
1141 rProperties
->setPropertyValue( gsNumberFormat
, uno::makeAny(SetCurrencySymbol(rNumberFormat
, rCurrency
)));
1145 catch ( uno::Exception
& )
1147 OSL_FAIL("Numberformat not found");
1153 if ((nCellType
== util::NumberFormat::CURRENCY
) && !rCurrency
.isEmpty() && !sCurrentCurrency
.isEmpty() &&
1154 sCurrentCurrency
!= rCurrency
&& !IsCurrencySymbol(rNumberFormat
, sCurrentCurrency
, rCurrency
))
1155 rProperties
->setPropertyValue( gsNumberFormat
, uno::makeAny(SetCurrencySymbol(rNumberFormat
, rCurrency
)));
1159 void ScXMLImport::SetStyleToRanges()
1161 if (!mbImportStyles
)
1164 if (!sPrevStyleName
.isEmpty())
1166 uno::Reference
<beans::XPropertySet
> xProperties (xSheetCellRanges
, uno::UNO_QUERY
);
1167 if (xProperties
.is())
1169 XMLTableStylesContext
*pStyles(static_cast<XMLTableStylesContext
*>(GetAutoStyles()));
1170 XMLTableStyleContext
* pStyle
= nullptr;
1172 pStyle
= const_cast<XMLTableStyleContext
*>(static_cast<const XMLTableStyleContext
*>(pStyles
->FindStyleChildContext(
1173 XmlStyleFamily::TABLE_CELL
, sPrevStyleName
, true)));
1176 pStyle
->FillPropertySet(xProperties
);
1177 // here needs to be the cond format import method
1178 sal_Int32
nNumberFormat(pStyle
->GetNumberFormat());
1179 SetType(xProperties
, nNumberFormat
, nPrevCellType
, sPrevCurrency
);
1181 css::uno::Any aAny
= xProperties
->getPropertyValue("FormatID");
1182 sal_uInt64 nKey
= 0;
1183 if ((aAny
>>= nKey
) && nKey
)
1185 ScFormatSaveData
* pFormatSaveData
= comphelper::getUnoTunnelImplementation
<ScModelObj
>(GetModel())->GetFormatSaveData();
1186 pFormatSaveData
->maIDToName
.insert(std::pair
<sal_uInt64
, OUString
>(nKey
, sPrevStyleName
));
1189 // store first cell of first range for each style, once per sheet
1190 uno::Sequence
<table::CellRangeAddress
> aAddresses(xSheetCellRanges
->getRangeAddresses());
1191 pStyle
->ApplyCondFormat(aAddresses
);
1192 if ( aAddresses
.hasElements() )
1194 const table::CellRangeAddress
& rRange
= aAddresses
[0];
1195 if ( rRange
.Sheet
!= pStyle
->GetLastSheet() )
1197 ScSheetSaveData
* pSheetData
= comphelper::getUnoTunnelImplementation
<ScModelObj
>(GetModel())->GetSheetSaveData();
1198 pSheetData
->AddCellStyle( sPrevStyleName
,
1199 ScAddress( static_cast<SCCOL
>(rRange
.StartColumn
), static_cast<SCROW
>(rRange
.StartRow
), static_cast<SCTAB
>(rRange
.Sheet
) ) );
1200 pStyle
->SetLastSheet(rRange
.Sheet
);
1206 xProperties
->setPropertyValue(gsCellStyle
, uno::makeAny(GetStyleDisplayName( XmlStyleFamily::TABLE_CELL
, sPrevStyleName
)));
1207 sal_Int32
nNumberFormat(GetStyleNumberFormats()->GetStyleNumberFormat(sPrevStyleName
));
1208 bool bInsert(nNumberFormat
== -1);
1209 SetType(xProperties
, nNumberFormat
, nPrevCellType
, sPrevCurrency
);
1211 GetStyleNumberFormats()->AddStyleNumberFormat(sPrevStyleName
, nNumberFormat
);
1215 if (GetModel().is())
1217 uno::Reference
<lang::XMultiServiceFactory
> xMultiServiceFactory(GetModel(), uno::UNO_QUERY
);
1218 if (xMultiServiceFactory
.is())
1219 xSheetCellRanges
.set(uno::Reference
<sheet::XSheetCellRangeContainer
>(
1220 xMultiServiceFactory
->createInstance("com.sun.star.sheet.SheetCellRanges"),
1223 OSL_ENSURE(xSheetCellRanges
.is(), "didn't get SheetCellRanges");
1226 void ScXMLImport::SetStyleToRanges(const ScRangeList
& rRanges
, const OUString
* pStyleName
,
1227 const sal_Int16 nCellType
, const OUString
* pCurrency
)
1229 if (!mbImportStyles
)
1232 if (sPrevStyleName
.isEmpty())
1234 nPrevCellType
= nCellType
;
1236 sPrevStyleName
= *pStyleName
;
1238 sPrevCurrency
= *pCurrency
;
1239 else if (!sPrevCurrency
.isEmpty())
1240 sPrevCurrency
.clear();
1242 else if ((nCellType
!= nPrevCellType
) ||
1243 ((pStyleName
&& *pStyleName
!= sPrevStyleName
) ||
1244 (!pStyleName
&& !sPrevStyleName
.isEmpty())) ||
1245 ((pCurrency
&& *pCurrency
!= sPrevCurrency
) ||
1246 (!pCurrency
&& !sPrevCurrency
.isEmpty())))
1249 nPrevCellType
= nCellType
;
1251 sPrevStyleName
= *pStyleName
;
1252 else if(!sPrevStyleName
.isEmpty())
1253 sPrevStyleName
.clear();
1255 sPrevCurrency
= *pCurrency
;
1256 else if(!sPrevCurrency
.isEmpty())
1257 sPrevCurrency
.clear();
1260 if (!xSheetCellRanges
.is() && GetModel().is())
1262 uno::Reference
<lang::XMultiServiceFactory
> xMultiServiceFactory(GetModel(), uno::UNO_QUERY
);
1263 if (xMultiServiceFactory
.is())
1264 xSheetCellRanges
.set(uno::Reference
<sheet::XSheetCellRangeContainer
>(xMultiServiceFactory
->createInstance("com.sun.star.sheet.SheetCellRanges"), uno::UNO_QUERY
));
1265 OSL_ENSURE(xSheetCellRanges
.is(), "didn't get SheetCellRanges");
1268 static_cast<ScCellRangesObj
*>(xSheetCellRanges
.get())->SetNewRanges(rRanges
);
1271 bool ScXMLImport::SetNullDateOnUnitConverter()
1273 if (!bNullDateSetted
)
1274 bNullDateSetted
= GetMM100UnitConverter().setNullDate(GetModel());
1275 OSL_ENSURE(bNullDateSetted
, "could not set the null date");
1276 return bNullDateSetted
;
1279 XMLNumberFormatAttributesExportHelper
* ScXMLImport::GetNumberFormatAttributesExportHelper()
1281 if (!pNumberFormatAttributesExportHelper
)
1282 pNumberFormatAttributesExportHelper
.reset(new XMLNumberFormatAttributesExportHelper(GetNumberFormatsSupplier()));
1283 return pNumberFormatAttributesExportHelper
.get();
1286 ScMyStyleNumberFormats
* ScXMLImport::GetStyleNumberFormats()
1288 if (!pStyleNumberFormats
)
1289 pStyleNumberFormats
.reset(new ScMyStyleNumberFormats
);
1290 return pStyleNumberFormats
.get();
1293 void ScXMLImport::SetStylesToRangesFinished()
1296 sPrevStyleName
.clear();
1300 void SAL_CALL
ScXMLImport::setTargetDocument( const css::uno::Reference
< css::lang::XComponent
>& xDoc
)
1302 ScXMLImport::MutexGuard
aGuard(*this);
1303 SvXMLImport::setTargetDocument( xDoc
);
1305 uno::Reference
<frame::XModel
> xModel(xDoc
, uno::UNO_QUERY
);
1306 pDoc
= ScXMLConverter::GetScDocument( xModel
);
1307 OSL_ENSURE( pDoc
, "ScXMLImport::setTargetDocument - no ScDocument!" );
1309 throw lang::IllegalArgumentException();
1311 if (ScDocShell
* pDocSh
= static_cast<ScDocShell
*>(pDoc
->GetDocumentShell()))
1312 pDocSh
->SetInitialLinkUpdate( pDocSh
->GetMedium());
1314 mpDocImport
.reset(new ScDocumentImport(*pDoc
));
1315 mpComp
.reset(new ScCompiler(*pDoc
, ScAddress(), formula::FormulaGrammar::GRAM_ODFF
));
1317 uno::Reference
<document::XActionLockable
> xActionLockable(xDoc
, uno::UNO_QUERY
);
1318 if (xActionLockable
.is())
1319 xActionLockable
->addActionLock();
1322 // css::xml::sax::XDocumentHandler
1323 void SAL_CALL
ScXMLImport::startDocument()
1325 ScXMLImport::MutexGuard
aGuard(*this);
1326 SvXMLImport::startDocument();
1327 if (pDoc
&& !pDoc
->IsImportingXML())
1329 comphelper::getUnoTunnelImplementation
<ScModelObj
>(GetModel())->BeforeXMLLoading();
1330 bSelfImportingXMLSet
= true;
1333 // if content and styles are loaded with separate imports,
1334 // set bLatinDefaultStyle flag at the start of the content import
1335 SvXMLImportFlags nFlags
= getImportFlags();
1336 if ( ( nFlags
& SvXMLImportFlags::CONTENT
) && !( nFlags
& SvXMLImportFlags::STYLES
) )
1337 ExamineDefaultStyle();
1339 if (getImportFlags() & SvXMLImportFlags::CONTENT
)
1341 if (GetModel().is())
1343 // store initial namespaces, to find the ones that were added from the file later
1344 ScSheetSaveData
* pSheetData
= comphelper::getUnoTunnelImplementation
<ScModelObj
>(GetModel())->GetSheetSaveData();
1345 const SvXMLNamespaceMap
& rNamespaces
= GetNamespaceMap();
1346 pSheetData
->StoreInitialNamespaces(rNamespaces
);
1350 uno::Reference
< beans::XPropertySet
> const xImportInfo( getImportInfo() );
1351 uno::Reference
< beans::XPropertySetInfo
> const xPropertySetInfo(
1352 xImportInfo
.is() ? xImportInfo
->getPropertySetInfo() : nullptr);
1353 if (xPropertySetInfo
.is())
1355 OUString
const sOrganizerMode(
1357 if (xPropertySetInfo
->hasPropertyByName(sOrganizerMode
))
1359 bool bStyleOnly(false);
1360 if (xImportInfo
->getPropertyValue(sOrganizerMode
) >>= bStyleOnly
)
1362 bLoadDoc
= !bStyleOnly
;
1370 sal_Int32
ScXMLImport::GetRangeType(const OUString
& sRangeType
)
1372 sal_Int32
nRangeType(0);
1373 OUStringBuffer sBuffer
;
1375 while (i
<= sRangeType
.getLength())
1377 if ((i
== sRangeType
.getLength()) || (sRangeType
[i
] == ' '))
1379 OUString sTemp
= sBuffer
.makeStringAndClear();
1380 if (sTemp
== "repeat-column")
1381 nRangeType
|= sheet::NamedRangeFlag::COLUMN_HEADER
;
1382 else if (sTemp
== SC_REPEAT_ROW
)
1383 nRangeType
|= sheet::NamedRangeFlag::ROW_HEADER
;
1384 else if (sTemp
== SC_FILTER
)
1385 nRangeType
|= sheet::NamedRangeFlag::FILTER_CRITERIA
;
1386 else if (sTemp
== SC_PRINT_RANGE
)
1387 nRangeType
|= sheet::NamedRangeFlag::PRINT_AREA
;
1389 else if (i
< sRangeType
.getLength())
1390 sBuffer
.append(sRangeType
[i
]);
1396 void ScXMLImport::SetLabelRanges()
1398 if (!pMyLabelRanges
)
1401 uno::Reference
<beans::XPropertySet
> xPropertySet (GetModel(), uno::UNO_QUERY
);
1402 if (!xPropertySet
.is())
1405 uno::Any aColAny
= xPropertySet
->getPropertyValue(SC_UNO_COLLABELRNG
);
1406 uno::Any aRowAny
= xPropertySet
->getPropertyValue(SC_UNO_ROWLABELRNG
);
1408 uno::Reference
< sheet::XLabelRanges
> xColRanges
;
1409 uno::Reference
< sheet::XLabelRanges
> xRowRanges
;
1411 if ( !(( aColAny
>>= xColRanges
) && ( aRowAny
>>= xRowRanges
)) )
1414 table::CellRangeAddress aLabelRange
;
1415 table::CellRangeAddress aDataRange
;
1417 for (const auto& rxLabelRange
: *pMyLabelRanges
)
1419 sal_Int32
nOffset1(0);
1420 sal_Int32
nOffset2(0);
1421 FormulaGrammar::AddressConvention eConv
= FormulaGrammar::CONV_OOO
;
1424 if (ScRangeStringConverter::GetRangeFromString( aLabelRange
, rxLabelRange
->sLabelRangeStr
, *pDoc
, eConv
, nOffset1
) &&
1425 ScRangeStringConverter::GetRangeFromString( aDataRange
, rxLabelRange
->sDataRangeStr
, *pDoc
, eConv
, nOffset2
))
1427 if ( rxLabelRange
->bColumnOrientation
)
1428 xColRanges
->addNew( aLabelRange
, aDataRange
);
1430 xRowRanges
->addNew( aLabelRange
, aDataRange
);
1434 pMyLabelRanges
->clear();
1439 class RangeNameInserter
1442 ScRangeName
& mrRangeName
;
1445 RangeNameInserter(ScDocument
& rDoc
, ScRangeName
& rRangeName
) :
1446 mrDoc(rDoc
), mrRangeName(rRangeName
) {}
1448 void operator() (const std::unique_ptr
<ScMyNamedExpression
>& p
) const
1450 using namespace formula
;
1452 const OUString
& aType
= p
->sRangeType
;
1453 sal_uInt32 nUnoType
= ScXMLImport::GetRangeType(aType
);
1455 ScRangeData::Type nNewType
= ScRangeData::Type::Name
;
1456 if ( nUnoType
& sheet::NamedRangeFlag::FILTER_CRITERIA
) nNewType
|= ScRangeData::Type::Criteria
;
1457 if ( nUnoType
& sheet::NamedRangeFlag::PRINT_AREA
) nNewType
|= ScRangeData::Type::PrintArea
;
1458 if ( nUnoType
& sheet::NamedRangeFlag::COLUMN_HEADER
) nNewType
|= ScRangeData::Type::ColHeader
;
1459 if ( nUnoType
& sheet::NamedRangeFlag::ROW_HEADER
) nNewType
|= ScRangeData::Type::RowHeader
;
1461 // Insert a new name.
1463 sal_Int32 nOffset
= 0;
1464 bool bSuccess
= ScRangeStringConverter::GetAddressFromString(
1465 aPos
, p
->sBaseCellAddress
, mrDoc
, FormulaGrammar::CONV_OOO
, nOffset
);
1469 OUString aContent
= p
->sContent
;
1470 if (!p
->bIsExpression
)
1471 ScXMLConverter::ConvertCellRangeAddress(aContent
);
1473 ScRangeData
* pData
= new ScRangeData(
1474 mrDoc
, p
->sName
, aContent
, aPos
, nNewType
, p
->eGrammar
);
1475 mrRangeName
.insert(pData
);
1482 void ScXMLImport::SetNamedRanges()
1484 if (!m_pMyNamedExpressions
)
1490 // Insert the namedRanges
1491 ScRangeName
* pRangeNames
= pDoc
->GetRangeName();
1492 ::std::for_each(m_pMyNamedExpressions
->begin(), m_pMyNamedExpressions
->end(), RangeNameInserter(*pDoc
, *pRangeNames
));
1495 void ScXMLImport::SetSheetNamedRanges()
1500 for (auto const& itr
: m_SheetNamedExpressions
)
1502 const SCTAB nTab
= itr
.first
;
1503 ScRangeName
* pRangeNames
= pDoc
->GetRangeName(nTab
);
1507 const ScMyNamedExpressions
& rNames
= *itr
.second
;
1508 ::std::for_each(rNames
.begin(), rNames
.end(), RangeNameInserter(*pDoc
, *pRangeNames
));
1512 void ScXMLImport::SetStringRefSyntaxIfMissing()
1517 ScCalcConfig aCalcConfig
= pDoc
->GetCalcConfig();
1519 // Has any string ref syntax been imported?
1520 // If not, we need to take action
1521 if ( !aCalcConfig
.mbHasStringRefSyntax
)
1523 aCalcConfig
.meStringRefAddressSyntax
= formula::FormulaGrammar::CONV_A1_XL_A1
;
1524 pDoc
->SetCalcConfig(aCalcConfig
);
1528 void SAL_CALL
ScXMLImport::endDocument()
1530 ScXMLImport::MutexGuard
aGuard(*this);
1531 if (getImportFlags() & SvXMLImportFlags::CONTENT
)
1533 if (GetModel().is())
1535 mpDocImport
->finalize();
1537 uno::Reference
<document::XViewDataSupplier
> xViewDataSupplier(GetModel(), uno::UNO_QUERY
);
1538 if (xViewDataSupplier
.is())
1540 uno::Reference
<container::XIndexAccess
> xIndexAccess(xViewDataSupplier
->getViewData());
1541 if (xIndexAccess
.is() && xIndexAccess
->getCount() > 0)
1543 uno::Sequence
< beans::PropertyValue
> aSeq
;
1544 if (xIndexAccess
->getByIndex(0) >>= aSeq
)
1546 for (const auto& rProp
: std::as_const(aSeq
))
1548 OUString
sName(rProp
.Name
);
1549 if (sName
== SC_ACTIVETABLE
)
1552 if(rProp
.Value
>>= sTabName
)
1555 if (pDoc
->GetTable(sTabName
, nTab
))
1557 pDoc
->SetVisibleTab(nTab
);
1568 SetSheetNamedRanges();
1569 SetStringRefSyntaxIfMissing();
1571 // Process pivot table sources after the named ranges have been set.
1572 mpPivotSources
->process();
1574 GetProgressBarHelper()->End(); // make room for subsequent SfxProgressBars
1579 // After CompileXML, links must be completely changed to the new URLs.
1580 // Otherwise, hasExternalFile for API wouldn't work (#i116940#),
1581 // and typing a new formula would create a second link with the same "real" file name.
1582 if (pDoc
->HasExternalRefManager())
1583 pDoc
->GetExternalRefManager()->updateAbsAfterLoad();
1586 // If the stream contains cells outside of the current limits, the styles can't be re-created,
1587 // so stream copying is disabled then.
1588 if (pDoc
&& GetModel().is() && !pDoc
->HasRangeOverflow())
1590 // set "valid stream" flags after loading (before UpdateRowHeights, so changed formula results
1591 // in UpdateRowHeights can already clear the flags again)
1592 ScSheetSaveData
* pSheetData
= comphelper::getUnoTunnelImplementation
<ScModelObj
>(GetModel())->GetSheetSaveData();
1594 SCTAB nTabCount
= pDoc
->GetTableCount();
1595 for (SCTAB nTab
=0; nTab
<nTabCount
; ++nTab
)
1597 pDoc
->SetDrawPageSize(nTab
);
1598 if (!pSheetData
->IsSheetBlocked( nTab
))
1599 pDoc
->SetStreamValid( nTab
, true );
1603 // There are rows with optimal height which need to be updated
1604 if (pDoc
&& !maRecalcRowRanges
.empty())
1606 bool bLockHeight
= pDoc
->IsAdjustHeightLocked();
1609 pDoc
->UnlockAdjustHeight();
1612 ScSizeDeviceProvider
aProv(static_cast<ScDocShell
*>(pDoc
->GetDocumentShell()));
1613 ScDocRowHeightUpdater
aUpdater(*pDoc
, aProv
.GetDevice(), aProv
.GetPPTX(), aProv
.GetPPTY(), &maRecalcRowRanges
);
1618 pDoc
->LockAdjustHeight();
1622 // Initialize and set position and size of objects
1623 if (pDoc
&& pDoc
->GetDrawLayer())
1625 ScDrawLayer
* pDrawLayer
= pDoc
->GetDrawLayer();
1626 SCTAB nTabCount
= pDoc
->GetTableCount();
1627 for (SCTAB nTab
= 0; nTab
< nTabCount
; ++nTab
)
1629 const SdrPage
* pPage
= pDrawLayer
->GetPage(nTab
);
1632 bool bNegativePage
= pDoc
->IsNegativePage(nTab
);
1633 const size_t nCount
= pPage
->GetObjCount();
1634 for (size_t i
= 0; i
< nCount
; ++i
)
1636 SdrObject
* pObj
= pPage
->GetObj(i
);
1637 ScDrawObjData
* pData
1638 = ScDrawLayer::GetObjDataTab(pObj
, nTab
);
1639 // Existence of pData means, that it is a cell anchored object
1642 // Finish and correct import based on full size (no hidden row/col) and LTR
1643 pDrawLayer
->InitializeCellAnchoredObj(pObj
, *pData
);
1644 // Adapt object to hidden row/col and RTL
1645 pDrawLayer
->RecalcPos(pObj
, *pData
, bNegativePage
,
1646 true /*bUpdateNoteCaptionPos*/);
1652 aTables
.FixupOLEs();
1654 if (GetModel().is())
1656 uno::Reference
<document::XActionLockable
> xActionLockable(GetModel(), uno::UNO_QUERY
);
1657 if (xActionLockable
.is())
1658 xActionLockable
->removeActionLock();
1660 SvXMLImport::endDocument();
1664 pDoc
->BroadcastUno(SfxHint(SfxHintId::ScClearCache
));
1667 if(pDoc
&& bSelfImportingXMLSet
)
1668 comphelper::getUnoTunnelImplementation
<ScModelObj
>(GetModel())->AfterXMLLoading();
1672 void ScXMLImport::DisposingModel()
1674 SvXMLImport::DisposingModel();
1678 ScXMLImport::MutexGuard::MutexGuard(ScXMLImport
& rImport
) :
1681 mrImport
.LockSolarMutex();
1684 ScXMLImport::MutexGuard::~MutexGuard()
1686 mrImport
.UnlockSolarMutex();
1689 void ScXMLImport::LockSolarMutex()
1691 // #i62677# When called from DocShell/Wrapper, the SolarMutex is already locked,
1692 // so there's no need to allocate (and later delete) the SolarMutexGuard.
1693 if (!mbLockSolarMutex
)
1695 DBG_TESTSOLARMUTEX();
1699 if (nSolarMutexLocked
== 0)
1701 OSL_ENSURE(!pSolarMutexGuard
, "Solar Mutex is locked");
1702 pSolarMutexGuard
.reset(new SolarMutexGuard());
1704 ++nSolarMutexLocked
;
1707 void ScXMLImport::UnlockSolarMutex()
1709 if (nSolarMutexLocked
> 0)
1711 nSolarMutexLocked
--;
1712 if (nSolarMutexLocked
== 0)
1714 OSL_ENSURE(pSolarMutexGuard
, "Solar Mutex is always unlocked");
1715 pSolarMutexGuard
.reset();
1720 sal_Int32
ScXMLImport::GetByteOffset() const
1722 sal_Int32 nOffset
= -1;
1723 uno::Reference
<xml::sax::XLocator
> xLocator
= GetLocator();
1724 uno::Reference
<io::XSeekable
> xSeek( xLocator
, uno::UNO_QUERY
); //! should use different interface
1726 nOffset
= static_cast<sal_Int32
>(xSeek
->getPosition());
1730 void ScXMLImport::SetRangeOverflowType(ErrCode nType
)
1732 // #i31130# Overflow is stored in the document, because the ScXMLImport object
1733 // isn't available in ScXMLImportWrapper::ImportFromComponent when using the
1734 // OOo->Oasis transformation.
1737 pDoc
->SetRangeOverflowType( nType
);
1740 void ScXMLImport::ProgressBarIncrement()
1743 if (nProgressCount
> 100)
1745 GetProgressBarHelper()->Increment(nProgressCount
);
1750 void ScXMLImport::ExtractFormulaNamespaceGrammar(
1751 OUString
& rFormula
, OUString
& rFormulaNmsp
, FormulaGrammar::Grammar
& reGrammar
,
1752 const OUString
& rAttrValue
, bool bRestrictToExternalNmsp
) const
1754 // parse the attribute value, extract namespace ID, literal namespace, and formula string
1755 rFormulaNmsp
.clear();
1756 sal_uInt16 nNsId
= GetNamespaceMap().GetKeyByQName(rAttrValue
, nullptr, &rFormula
, &rFormulaNmsp
, SvXMLNamespaceMap::QNameMode::AttrValue
);
1758 // check if we have an ODF formula namespace
1759 if( !bRestrictToExternalNmsp
) switch( nNsId
)
1761 case XML_NAMESPACE_OOOC
:
1762 rFormulaNmsp
.clear(); // remove namespace string for built-in grammar
1763 reGrammar
= FormulaGrammar::GRAM_PODF
;
1765 case XML_NAMESPACE_OF
:
1766 rFormulaNmsp
.clear(); // remove namespace string for built-in grammar
1767 reGrammar
= FormulaGrammar::GRAM_ODFF
;
1771 /* Find default grammar for formulas without namespace. There may be
1772 documents in the wild that stored no namespace in ODF 1.0/1.1. Use
1773 GRAM_PODF then (old style ODF 1.0/1.1 formulas). The default for ODF
1774 1.2 and later without namespace is GRAM_ODFF (OpenFormula). */
1775 FormulaGrammar::Grammar eDefaultGrammar
=
1776 (GetDocument()->GetStorageGrammar() == FormulaGrammar::GRAM_PODF
) ?
1777 FormulaGrammar::GRAM_PODF
: FormulaGrammar::GRAM_ODFF
;
1779 /* Check if we have no namespace at all. The value XML_NAMESPACE_NONE
1780 indicates that there is no colon. If the first character of the
1781 attribute value is the equality sign, the value XML_NAMESPACE_UNKNOWN
1782 indicates that there is a colon somewhere in the formula string. */
1783 if( (nNsId
== XML_NAMESPACE_NONE
) || ((nNsId
== XML_NAMESPACE_UNKNOWN
) && (rAttrValue
.toChar() == '=')) )
1785 rFormula
= rAttrValue
; // return entire string as formula
1786 reGrammar
= eDefaultGrammar
;
1790 /* Check if a namespace URL could be resolved from the attribute value.
1791 Use that namespace only, if the Calc document knows an associated
1792 external formula parser. This prevents that the range operator in
1793 conjunction with defined names is confused as namespaces prefix, e.g.
1794 in the expression 'table:A1' where 'table' is a named reference. */
1795 if( ((nNsId
& XML_NAMESPACE_UNKNOWN_FLAG
) != 0) && !rFormulaNmsp
.isEmpty() &&
1796 GetDocument()->GetFormulaParserPool().hasFormulaParser( rFormulaNmsp
) )
1798 reGrammar
= FormulaGrammar::GRAM_EXTERNAL
;
1802 /* All attempts failed (e.g. no namespace and no leading equality sign, or
1803 an invalid namespace prefix), continue with the entire attribute value. */
1804 rFormula
= rAttrValue
;
1805 rFormulaNmsp
.clear(); // remove any namespace string
1806 reGrammar
= eDefaultGrammar
;
1809 FormulaError
ScXMLImport::GetFormulaErrorConstant( const OUString
& rStr
) const
1812 return FormulaError::NONE
;
1814 return mpComp
->GetErrorConstant(rStr
);
1817 ScEditEngineDefaulter
* ScXMLImport::GetEditEngine()
1821 mpEditEngine
.reset(new ScEditEngineDefaulter(pDoc
->GetEnginePool()));
1822 mpEditEngine
->SetRefMapMode(MapMode(MapUnit::Map100thMM
));
1823 mpEditEngine
->SetEditTextObjectPool(pDoc
->GetEditPool());
1824 mpEditEngine
->SetUpdateMode(false);
1825 mpEditEngine
->EnableUndo(false);
1826 mpEditEngine
->SetControlWord(mpEditEngine
->GetControlWord() & ~EEControlBits::ALLOWBIGOBJS
);
1828 return mpEditEngine
.get();
1831 const ScXMLEditAttributeMap
& ScXMLImport::GetEditAttributeMap() const
1834 mpEditAttrMap
.reset(new ScXMLEditAttributeMap
);
1835 return *mpEditAttrMap
;
1838 void ScXMLImport::NotifyContainsEmbeddedFont()
1841 pDoc
->SetEmbedFonts(true);
1844 ScMyImpDetectiveOpArray
* ScXMLImport::GetDetectiveOpArray()
1846 if (!pDetectiveOpArray
)
1847 pDetectiveOpArray
.reset(new ScMyImpDetectiveOpArray());
1848 return pDetectiveOpArray
.get();
1851 extern "C" SAL_DLLPUBLIC_EXPORT
bool TestImportFODS(SvStream
&rStream
)
1855 SfxObjectShellLock
xDocSh(new ScDocShell
);
1856 xDocSh
->DoInitNew();
1857 uno::Reference
<frame::XModel
> xModel(xDocSh
->GetModel());
1859 uno::Reference
<lang::XMultiServiceFactory
> xMultiServiceFactory(comphelper::getProcessServiceFactory());
1860 uno::Reference
<io::XInputStream
> xStream(new ::utl::OSeekableInputStreamWrapper(rStream
));
1861 uno::Reference
<uno::XInterface
> xInterface(xMultiServiceFactory
->createInstance("com.sun.star.comp.Writer.XmlFilterAdaptor"), uno::UNO_SET_THROW
);
1863 css::uno::Sequence
<OUString
> aUserData(7);
1864 aUserData
[0] = "com.sun.star.comp.filter.OdfFlatXml";
1865 aUserData
[2] = "com.sun.star.comp.Calc.XMLOasisImporter";
1866 aUserData
[3] = "com.sun.star.comp.Calc.XMLOasisExporter";
1867 aUserData
[6] = "true";
1868 uno::Sequence
<beans::PropertyValue
> aAdaptorArgs(comphelper::InitPropertySequence(
1870 { "UserData", uno::Any(aUserData
) },
1872 css::uno::Sequence
<uno::Any
> aOuterArgs(1);
1873 aOuterArgs
[0] <<= aAdaptorArgs
;
1875 uno::Reference
<lang::XInitialization
> xInit(xInterface
, uno::UNO_QUERY_THROW
);
1876 xInit
->initialize(aOuterArgs
);
1878 uno::Reference
<document::XImporter
> xImporter(xInterface
, uno::UNO_QUERY_THROW
);
1879 uno::Sequence
<beans::PropertyValue
> aArgs(comphelper::InitPropertySequence(
1881 { "InputStream", uno::Any(xStream
) },
1882 { "URL", uno::Any(OUString("private:stream")) },
1884 xImporter
->setTargetDocument(xModel
);
1886 uno::Reference
<document::XFilter
> xFilter(xInterface
, uno::UNO_QUERY_THROW
);
1887 //SetLoading hack because the document properties will be re-initted
1888 //by the xml filter and during the init, while it's considered uninitialized,
1889 //setting a property will inform the document it's modified, which attempts
1890 //to update the properties, which throws cause the properties are uninitialized
1891 xDocSh
->SetLoading(SfxLoadedFlags::NONE
);
1892 bool ret
= xFilter
->filter(aArgs
);
1893 xDocSh
->SetLoading(SfxLoadedFlags::ALL
);
1900 extern "C" SAL_DLLPUBLIC_EXPORT
bool TestImportXLSX(SvStream
&rStream
)
1904 SfxObjectShellLock
xDocSh(new ScDocShell
);
1905 xDocSh
->DoInitNew();
1906 uno::Reference
<frame::XModel
> xModel(xDocSh
->GetModel());
1908 uno::Reference
<lang::XMultiServiceFactory
> xMultiServiceFactory(comphelper::getProcessServiceFactory());
1909 uno::Reference
<io::XInputStream
> xStream(new utl::OSeekableInputStreamWrapper(rStream
));
1911 uno::Reference
<document::XFilter
> xFilter(xMultiServiceFactory
->createInstance("com.sun.star.comp.oox.xls.ExcelFilter"), uno::UNO_QUERY_THROW
);
1913 uno::Reference
<document::XImporter
> xImporter(xFilter
, uno::UNO_QUERY_THROW
);
1914 uno::Sequence
<beans::PropertyValue
> aArgs(comphelper::InitPropertySequence(
1916 { "InputStream", uno::makeAny(xStream
) },
1917 { "InputMode", uno::makeAny(true) },
1919 xImporter
->setTargetDocument(xModel
);
1921 //SetLoading hack because the document properties will be re-initted
1922 //by the xml filter and during the init, while it's considered uninitialized,
1923 //setting a property will inform the document it's modified, which attempts
1924 //to update the properties, which throws cause the properties are uninitialized
1925 xDocSh
->SetLoading(SfxLoadedFlags::NONE
);
1929 ret
= xFilter
->filter(aArgs
);
1931 catch (const css::io::IOException
&)
1934 catch (const css::lang::WrappedTargetRuntimeException
&)
1937 xDocSh
->SetLoading(SfxLoadedFlags::ALL
);
1944 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */