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/nmspmap.hxx>
27 #include <xmloff/xmlnmspe.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>
42 #include <svl/languageoptions.hxx>
43 #include <editeng/editstat.hxx>
44 #include <formula/errorcodes.hxx>
45 #include <vcl/svapp.hxx>
47 #include <appluno.hxx>
48 #include "xmlimprt.hxx"
49 #include "importcontext.hxx"
50 #include <document.hxx>
53 #include "xmlbodyi.hxx"
54 #include "xmlstyli.hxx"
55 #include <ViewSettingsSequenceDefines.hxx>
57 #include <compiler.hxx>
59 #include "XMLConverter.hxx"
60 #include "XMLDetectiveContext.hxx"
61 #include "XMLTableShapeImportHelper.hxx"
62 #include "XMLChangeTrackingImportHelper.hxx"
63 #include <chgviset.hxx>
64 #include "XMLStylesImportHelper.hxx"
65 #include <sheetdata.hxx>
66 #include <rangeutl.hxx>
67 #include <formulaparserpool.hxx>
68 #include <externalrefmgr.hxx>
69 #include <editutil.hxx>
70 #include "editattributemap.hxx"
71 #include <documentimport.hxx>
72 #include "pivotsource.hxx"
73 #include <unonames.hxx>
74 #include <numformat.hxx>
75 #include <sizedev.hxx>
77 #include "xmlstyle.hxx"
79 #include <comphelper/base64.hxx>
80 #include <comphelper/extract.hxx>
81 #include <comphelper/propertysequence.hxx>
82 #include <comphelper/processfactory.hxx>
84 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
85 #include <com/sun/star/frame/XModel.hpp>
86 #include <com/sun/star/io/IOException.hpp>
87 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
88 #include <com/sun/star/document/XActionLockable.hpp>
89 #include <com/sun/star/util/MalformedNumberFormatException.hpp>
90 #include <com/sun/star/util/NumberFormat.hpp>
91 #include <com/sun/star/util/XNumberFormatTypes.hpp>
92 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
93 #include <com/sun/star/sheet/NamedRangeFlag.hpp>
94 #include <com/sun/star/sheet/XLabelRanges.hpp>
95 #include <com/sun/star/io/XSeekable.hpp>
96 #include <com/sun/star/beans/XPropertySet.hpp>
97 #include <com/sun/star/sheet/XSheetCellRangeContainer.hpp>
102 #define SC_LOCALE "Locale"
103 #define SC_CURRENCYSYMBOL "CurrencySymbol"
104 #define SC_REPEAT_ROW "repeat-row"
105 #define SC_FILTER "filter"
106 #define SC_PRINT_RANGE "print-range"
108 using namespace com::sun::star
;
109 using namespace ::xmloff::token
;
110 using namespace ::formula
;
112 OUString
ScXMLImport_getImplementationName() throw()
114 return "com.sun.star.comp.Calc.XMLOasisImporter";
117 uno::Sequence
< OUString
> ScXMLImport_getSupportedServiceNames() throw()
119 return { ScXMLImport_getImplementationName() };
122 uno::Reference
< uno::XInterface
> ScXMLImport_createInstance(
123 const uno::Reference
< lang::XMultiServiceFactory
> & rSMgr
)
125 // return (cppu::OWeakObject*)new ScXMLImport(IMPORT_ALL);
126 return static_cast<cppu::OWeakObject
*>(new ScXMLImport( comphelper::getComponentContext(rSMgr
), ScXMLImport_getImplementationName(), SvXMLImportFlags::ALL
));
129 OUString
ScXMLImport_Meta_getImplementationName() throw()
131 return "com.sun.star.comp.Calc.XMLOasisMetaImporter";
134 uno::Sequence
< OUString
> ScXMLImport_Meta_getSupportedServiceNames() throw()
136 return { ScXMLImport_Meta_getImplementationName() };
139 uno::Reference
< uno::XInterface
> ScXMLImport_Meta_createInstance(
140 const uno::Reference
< lang::XMultiServiceFactory
> & rSMgr
)
142 // return (cppu::OWeakObject*)new ScXMLImport(IMPORT_META);
143 return static_cast<cppu::OWeakObject
*>(new ScXMLImport( comphelper::getComponentContext(rSMgr
), ScXMLImport_Meta_getImplementationName(), SvXMLImportFlags::META
));
146 OUString
ScXMLImport_Styles_getImplementationName() throw()
148 return "com.sun.star.comp.Calc.XMLOasisStylesImporter";
151 uno::Sequence
< OUString
> ScXMLImport_Styles_getSupportedServiceNames() throw()
153 return { ScXMLImport_Styles_getImplementationName() };
156 uno::Reference
< uno::XInterface
> ScXMLImport_Styles_createInstance(
157 const uno::Reference
< lang::XMultiServiceFactory
> & rSMgr
)
159 // return (cppu::OWeakObject*)new ScXMLImport(SvXMLImportFlagsSTYLES|SvXMLImportFlags::AUTOSTYLES|SvXMLImportFlags::MASTERSTYLES|SvXMLImportFlags::FONTDECLS);
160 return static_cast<cppu::OWeakObject
*>(new ScXMLImport( comphelper::getComponentContext(rSMgr
), ScXMLImport_Styles_getImplementationName(), SvXMLImportFlags::STYLES
|SvXMLImportFlags::AUTOSTYLES
|SvXMLImportFlags::MASTERSTYLES
|SvXMLImportFlags::FONTDECLS
));
163 OUString
ScXMLImport_Content_getImplementationName() throw()
165 return "com.sun.star.comp.Calc.XMLOasisContentImporter";
168 uno::Sequence
< OUString
> ScXMLImport_Content_getSupportedServiceNames() throw()
170 return { ScXMLImport_Content_getImplementationName() };
173 uno::Reference
< uno::XInterface
> ScXMLImport_Content_createInstance(
174 const uno::Reference
< lang::XMultiServiceFactory
> & rSMgr
)
176 // return (cppu::OWeakObject*)new ScXMLImport(SvXMLImportFlags::META|SvXMLImportFlags::STYLES|SvXMLImportFlags::MASTERSTYLES|SvXMLImportFlags::AUTOSTYLES|SvXMLImportFlags::CONTENT|SvXMLImportFlags::SCRIPTS|SvXMLImportFlags::SETTINGS|SvXMLImportFlags::FONTDECLS);
177 return static_cast<cppu::OWeakObject
*>(new ScXMLImport( comphelper::getComponentContext(rSMgr
), ScXMLImport_Content_getImplementationName(), SvXMLImportFlags::AUTOSTYLES
|SvXMLImportFlags::CONTENT
|SvXMLImportFlags::SCRIPTS
|SvXMLImportFlags::FONTDECLS
));
180 OUString
ScXMLImport_Settings_getImplementationName() throw()
182 return "com.sun.star.comp.Calc.XMLOasisSettingsImporter";
185 uno::Sequence
< OUString
> ScXMLImport_Settings_getSupportedServiceNames() throw()
187 return { ScXMLImport_Settings_getImplementationName() };
190 uno::Reference
< uno::XInterface
> ScXMLImport_Settings_createInstance(
191 const uno::Reference
< lang::XMultiServiceFactory
> & rSMgr
)
193 // return (cppu::OWeakObject*)new ScXMLImport(SvXMLImportFlags::SETTINGS);
194 return static_cast<cppu::OWeakObject
*>(new ScXMLImport( comphelper::getComponentContext(rSMgr
), ScXMLImport_Settings_getImplementationName(), SvXMLImportFlags::SETTINGS
));
197 const SvXMLTokenMap
& ScXMLImport::GetTableRowCellAttrTokenMap()
199 static const SvXMLTokenMapEntry aTableRowCellAttrTokenMap
[] =
201 { XML_NAMESPACE_TABLE
, XML_STYLE_NAME
, XML_TOK_TABLE_ROW_CELL_ATTR_STYLE_NAME
},
202 { XML_NAMESPACE_TABLE
, XML_CONTENT_VALIDATION_NAME
, XML_TOK_TABLE_ROW_CELL_ATTR_CONTENT_VALIDATION_NAME
},
203 { XML_NAMESPACE_TABLE
, XML_NUMBER_ROWS_SPANNED
, XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_ROWS
},
204 { XML_NAMESPACE_TABLE
, XML_NUMBER_COLUMNS_SPANNED
, XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_COLS
},
205 { XML_NAMESPACE_TABLE
, XML_NUMBER_MATRIX_COLUMNS_SPANNED
, XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_MATRIX_COLS
},
206 { XML_NAMESPACE_TABLE
, XML_NUMBER_MATRIX_ROWS_SPANNED
, XML_TOK_TABLE_ROW_CELL_ATTR_SPANNED_MATRIX_ROWS
},
207 { XML_NAMESPACE_TABLE
, XML_NUMBER_COLUMNS_REPEATED
, XML_TOK_TABLE_ROW_CELL_ATTR_REPEATED
},
208 { XML_NAMESPACE_OFFICE
, XML_VALUE_TYPE
, XML_TOK_TABLE_ROW_CELL_ATTR_VALUE_TYPE
},
209 { XML_NAMESPACE_CALC_EXT
, XML_VALUE_TYPE
, XML_TOK_TABLE_ROW_CELL_ATTR_NEW_VALUE_TYPE
},
210 { XML_NAMESPACE_OFFICE
, XML_VALUE
, XML_TOK_TABLE_ROW_CELL_ATTR_VALUE
},
211 { XML_NAMESPACE_OFFICE
, XML_DATE_VALUE
, XML_TOK_TABLE_ROW_CELL_ATTR_DATE_VALUE
},
212 { XML_NAMESPACE_OFFICE
, XML_TIME_VALUE
, XML_TOK_TABLE_ROW_CELL_ATTR_TIME_VALUE
},
213 { XML_NAMESPACE_OFFICE
, XML_STRING_VALUE
, XML_TOK_TABLE_ROW_CELL_ATTR_STRING_VALUE
},
214 { XML_NAMESPACE_OFFICE
, XML_BOOLEAN_VALUE
, XML_TOK_TABLE_ROW_CELL_ATTR_BOOLEAN_VALUE
},
215 { XML_NAMESPACE_TABLE
, XML_FORMULA
, XML_TOK_TABLE_ROW_CELL_ATTR_FORMULA
},
216 { XML_NAMESPACE_OFFICE
, XML_CURRENCY
, XML_TOK_TABLE_ROW_CELL_ATTR_CURRENCY
},
220 if ( !pTableRowCellAttrTokenMap
)
221 pTableRowCellAttrTokenMap
.reset(new SvXMLTokenMap( aTableRowCellAttrTokenMap
));
222 return *pTableRowCellAttrTokenMap
;
225 // NB: virtually inherit so we can multiply inherit properly
226 // in ScXMLFlatDocContext_Impl
227 class ScXMLDocContext_Impl
: public virtual SvXMLImportContext
230 ScXMLImport
& GetScImport() { return static_cast<ScXMLImport
&>(GetImport()); }
233 ScXMLDocContext_Impl( ScXMLImport
& rImport
);
235 virtual SvXMLImportContextRef
CreateChildContext( sal_uInt16 nPrefix
,
236 const OUString
& rLocalName
,
237 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
) override
;
239 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
240 createFastChildContext( sal_Int32 nElement
,
241 const css::uno::Reference
<css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
243 virtual void SAL_CALL
startFastElement (sal_Int32 nElement
,
244 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
246 virtual void SAL_CALL
characters(const OUString
& aChars
) override
;
248 virtual void SAL_CALL
endFastElement(sal_Int32 nElement
) override
;
251 ScXMLDocContext_Impl::ScXMLDocContext_Impl( ScXMLImport
& rImport
) :
252 SvXMLImportContext( rImport
)
256 // context for flat file xml format
257 class ScXMLFlatDocContext_Impl
258 : public ScXMLDocContext_Impl
, public SvXMLMetaDocumentContext
262 ScXMLFlatDocContext_Impl( ScXMLImport
& i_rImport
,
263 const uno::Reference
<document::XDocumentProperties
>& i_xDocProps
);
265 virtual void SAL_CALL
startFastElement (sal_Int32 nElement
,
266 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
268 virtual void SAL_CALL
endFastElement(sal_Int32 nElement
) override
;
270 virtual void SAL_CALL
characters( const OUString
& aChars
) override
;
272 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
273 createFastChildContext( sal_Int32 nElement
,
274 const css::uno::Reference
<css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
277 ScXMLFlatDocContext_Impl::ScXMLFlatDocContext_Impl( ScXMLImport
& i_rImport
,
278 const uno::Reference
<document::XDocumentProperties
>& i_xDocProps
) :
279 SvXMLImportContext(i_rImport
),
280 ScXMLDocContext_Impl(i_rImport
),
281 SvXMLMetaDocumentContext(i_rImport
, i_xDocProps
)
285 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
286 ScXMLFlatDocContext_Impl::createFastChildContext( sal_Int32 nElement
,
287 const uno::Reference
< xml::sax::XFastAttributeList
> & xAttrList
)
289 if ( nElement
== XML_ELEMENT( OFFICE
, XML_META
) )
290 return SvXMLMetaDocumentContext::createFastChildContext( nElement
, xAttrList
);
292 return ScXMLDocContext_Impl::createFastChildContext( nElement
, xAttrList
);
295 void SAL_CALL
ScXMLFlatDocContext_Impl::startFastElement(sal_Int32 nElement
,
296 const uno::Reference
< xml::sax::XFastAttributeList
> & xAttrList
)
298 SvXMLMetaDocumentContext::startFastElement( nElement
, xAttrList
);
301 void SAL_CALL
ScXMLFlatDocContext_Impl::endFastElement(sal_Int32 nElement
)
303 SvXMLMetaDocumentContext::endFastElement( nElement
);
306 void SAL_CALL
ScXMLFlatDocContext_Impl::characters(const OUString
& rChars
)
308 SvXMLMetaDocumentContext::characters(rChars
);
311 class ScXMLBodyContext_Impl
: public ScXMLImportContext
314 ScXMLBodyContext_Impl( ScXMLImport
& rImport
);
316 virtual css::uno::Reference
< css::xml::sax::XFastContextHandler
> SAL_CALL
317 createFastChildContext( sal_Int32 nElement
,
318 const css::uno::Reference
<css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
321 ScXMLBodyContext_Impl::ScXMLBodyContext_Impl( ScXMLImport
& rImport
) :
322 ScXMLImportContext( rImport
)
326 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
327 ScXMLBodyContext_Impl::createFastChildContext( sal_Int32
/*nElement*/,
328 const uno::Reference
< xml::sax::XFastAttributeList
> & xAttrList
)
330 sax_fastparser::FastAttributeList
*pAttribList
=
331 sax_fastparser::FastAttributeList::castToFastAttributeList( xAttrList
);
332 return GetScImport().CreateBodyContext( pAttribList
);
335 SvXMLImportContextRef
ScXMLDocContext_Impl::CreateChildContext( sal_uInt16 nPrefix
,
336 const OUString
& rLocalName
,
337 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
)
339 SvXMLImportContext
*pContext(nullptr);
341 const SvXMLTokenMap
& rTokenMap(GetScImport().GetDocElemTokenMap());
342 switch( rTokenMap
.Get( nPrefix
, rLocalName
) )
344 case XML_TOK_DOC_FONTDECLS
:
345 if (GetScImport().getImportFlags() & SvXMLImportFlags::FONTDECLS
)
346 pContext
= GetScImport().CreateFontDeclsContext(nPrefix
, rLocalName
, xAttrList
);
348 case XML_TOK_DOC_STYLES
:
349 if (GetScImport().getImportFlags() & SvXMLImportFlags::STYLES
)
350 pContext
= GetScImport().CreateStylesContext( rLocalName
, xAttrList
, false);
352 case XML_TOK_DOC_AUTOSTYLES
:
353 if (GetScImport().getImportFlags() & SvXMLImportFlags::AUTOSTYLES
)
354 pContext
= GetScImport().CreateStylesContext( rLocalName
, xAttrList
, true);
356 case XML_TOK_DOC_MASTERSTYLES
:
357 if (GetScImport().getImportFlags() & SvXMLImportFlags::MASTERSTYLES
)
358 pContext
= new ScXMLMasterStylesContext( GetImport(), nPrefix
, rLocalName
,
361 case XML_TOK_DOC_META
:
362 SAL_INFO("sc", "XML_TOK_DOC_META: should not have come here, maybe document is invalid?");
364 case XML_TOK_DOC_SCRIPTS
:
365 if (GetScImport().getImportFlags() & SvXMLImportFlags::SCRIPTS
)
366 pContext
= GetScImport().CreateScriptContext( rLocalName
);
368 case XML_TOK_DOC_SETTINGS
:
369 if (GetScImport().getImportFlags() & SvXMLImportFlags::SETTINGS
)
370 pContext
= new XMLDocumentSettingsContext(GetScImport(), nPrefix
, rLocalName
, xAttrList
);
375 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
380 uno::Reference
< xml::sax::XFastContextHandler
> SAL_CALL
381 ScXMLDocContext_Impl::createFastChildContext( sal_Int32 nElement
,
382 const uno::Reference
< xml::sax::XFastAttributeList
> & /*xAttrList*/ )
384 SvXMLImportContext
*pContext(nullptr);
388 case XML_ELEMENT( OFFICE
, XML_BODY
):
389 if (GetScImport().getImportFlags() & SvXMLImportFlags::CONTENT
)
390 pContext
= new ScXMLBodyContext_Impl( GetScImport() );
393 //TODO: handle all other cases
395 pContext
= new SvXMLImportContext( GetImport() );
399 pContext
= new SvXMLImportContext( GetImport() );
404 void SAL_CALL
ScXMLDocContext_Impl::startFastElement(sal_Int32
/*nElement*/,
405 const uno::Reference
< xml::sax::XFastAttributeList
> & /*xAttrList*/)
409 void SAL_CALL
ScXMLDocContext_Impl::endFastElement(sal_Int32
/*nElement*/)
413 void SAL_CALL
ScXMLDocContext_Impl::characters(const OUString
&)
417 const SvXMLTokenMap
& ScXMLImport::GetDocElemTokenMap()
419 if( !pDocElemTokenMap
)
421 static const SvXMLTokenMapEntry aDocTokenMap
[] =
423 { XML_NAMESPACE_OFFICE
, XML_FONT_FACE_DECLS
, XML_TOK_DOC_FONTDECLS
},
424 { XML_NAMESPACE_OFFICE
, XML_STYLES
, XML_TOK_DOC_STYLES
},
425 { XML_NAMESPACE_OFFICE
, XML_AUTOMATIC_STYLES
, XML_TOK_DOC_AUTOSTYLES
},
426 { XML_NAMESPACE_OFFICE
, XML_MASTER_STYLES
, XML_TOK_DOC_MASTERSTYLES
},
427 { XML_NAMESPACE_OFFICE
, XML_META
, XML_TOK_DOC_META
},
428 { XML_NAMESPACE_OFFICE
, XML_SCRIPTS
, XML_TOK_DOC_SCRIPTS
},
429 { XML_NAMESPACE_OFFICE
, XML_BODY
, XML_TOK_DOC_BODY
},
430 { XML_NAMESPACE_OFFICE
, XML_SETTINGS
, XML_TOK_DOC_SETTINGS
},
434 pDocElemTokenMap
.reset(new SvXMLTokenMap( aDocTokenMap
));
436 } // if( !pDocElemTokenMap )
438 return *pDocElemTokenMap
;
441 const SvXMLTokenMap
& ScXMLImport::GetContentValidationElemTokenMap()
443 if( !pContentValidationElemTokenMap
)
445 static const SvXMLTokenMapEntry aContentValidationElemTokenMap
[] =
447 { XML_NAMESPACE_TABLE
, XML_HELP_MESSAGE
, XML_TOK_CONTENT_VALIDATION_ELEM_HELP_MESSAGE
},
448 { XML_NAMESPACE_TABLE
, XML_ERROR_MESSAGE
, XML_TOK_CONTENT_VALIDATION_ELEM_ERROR_MESSAGE
},
449 { XML_NAMESPACE_TABLE
, XML_ERROR_MACRO
, XML_TOK_CONTENT_VALIDATION_ELEM_ERROR_MACRO
},
450 { XML_NAMESPACE_OFFICE
, XML_EVENT_LISTENERS
, XML_TOK_CONTENT_VALIDATION_ELEM_EVENT_LISTENERS
},
454 pContentValidationElemTokenMap
.reset(new SvXMLTokenMap( aContentValidationElemTokenMap
));
455 } // if( !pContentValidationElemTokenMap )
457 return *pContentValidationElemTokenMap
;
460 const SvXMLTokenMap
& ScXMLImport::GetContentValidationMessageElemTokenMap()
462 if( !pContentValidationMessageElemTokenMap
)
464 static const SvXMLTokenMapEntry aContentValidationMessageElemTokenMap
[] =
466 { XML_NAMESPACE_TEXT
, XML_P
, XML_TOK_P
},
470 pContentValidationMessageElemTokenMap
.reset(new SvXMLTokenMap( aContentValidationMessageElemTokenMap
));
471 } // if( !pContentValidationMessageElemTokenMap )
473 return *pContentValidationMessageElemTokenMap
;
477 const SvXMLTokenMap
& ScXMLImport::GetTableElemTokenMap()
479 if( !pTableElemTokenMap
)
481 static const SvXMLTokenMapEntry aTableTokenMap
[] =
483 { XML_NAMESPACE_TABLE
, XML_NAMED_EXPRESSIONS
, XML_TOK_TABLE_NAMED_EXPRESSIONS
},
484 { XML_NAMESPACE_TABLE
, XML_TABLE_COLUMN_GROUP
, XML_TOK_TABLE_COL_GROUP
},
485 { XML_NAMESPACE_TABLE
, XML_TABLE_HEADER_COLUMNS
, XML_TOK_TABLE_HEADER_COLS
},
486 { XML_NAMESPACE_TABLE
, XML_TABLE_COLUMNS
, XML_TOK_TABLE_COLS
},
487 { XML_NAMESPACE_TABLE
, XML_TABLE_COLUMN
, XML_TOK_TABLE_COL
},
488 { XML_NAMESPACE_TABLE
, XML_TABLE_PROTECTION
, XML_TOK_TABLE_PROTECTION
},
489 { XML_NAMESPACE_LO_EXT
, XML_TABLE_PROTECTION
, XML_TOK_TABLE_PROTECTION_EXT
},
490 { XML_NAMESPACE_OFFICE_EXT
, XML_TABLE_PROTECTION
, XML_TOK_TABLE_PROTECTION_EXT
},
491 { XML_NAMESPACE_TABLE
, XML_TABLE_ROW_GROUP
, XML_TOK_TABLE_ROW_GROUP
},
492 { XML_NAMESPACE_TABLE
, XML_TABLE_HEADER_ROWS
, XML_TOK_TABLE_HEADER_ROWS
},
493 { XML_NAMESPACE_TABLE
, XML_TABLE_ROWS
, XML_TOK_TABLE_ROWS
},
494 { XML_NAMESPACE_TABLE
, XML_TABLE_ROW
, XML_TOK_TABLE_ROW
},
495 { XML_NAMESPACE_TABLE
, XML_TABLE_SOURCE
, XML_TOK_TABLE_SOURCE
},
496 { XML_NAMESPACE_TABLE
, XML_SCENARIO
, XML_TOK_TABLE_SCENARIO
},
497 { XML_NAMESPACE_TABLE
, XML_SHAPES
, XML_TOK_TABLE_SHAPES
},
498 { XML_NAMESPACE_OFFICE
, XML_FORMS
, XML_TOK_TABLE_FORMS
},
499 { XML_NAMESPACE_OFFICE
, XML_EVENT_LISTENERS
, XML_TOK_TABLE_EVENT_LISTENERS
},
500 { XML_NAMESPACE_OFFICE_EXT
, XML_EVENT_LISTENERS
, XML_TOK_TABLE_EVENT_LISTENERS_EXT
},
501 { XML_NAMESPACE_CALC_EXT
, XML_CONDITIONAL_FORMATS
, XML_TOK_TABLE_CONDFORMATS
},
505 pTableElemTokenMap
.reset(new SvXMLTokenMap( aTableTokenMap
));
506 } // if( !pTableElemTokenMap )
508 return *pTableElemTokenMap
;
511 const SvXMLTokenMap
& ScXMLImport::GetTableRowsElemTokenMap()
513 if( !pTableRowsElemTokenMap
)
515 static const SvXMLTokenMapEntry aTableRowsElemTokenMap
[] =
517 { XML_NAMESPACE_TABLE
, XML_TABLE_ROW_GROUP
, XML_TOK_TABLE_ROWS_ROW_GROUP
},
518 { XML_NAMESPACE_TABLE
, XML_TABLE_HEADER_ROWS
, XML_TOK_TABLE_ROWS_HEADER_ROWS
},
519 { XML_NAMESPACE_TABLE
, XML_TABLE_ROWS
, XML_TOK_TABLE_ROWS_ROWS
},
520 { XML_NAMESPACE_TABLE
, XML_TABLE_ROW
, XML_TOK_TABLE_ROWS_ROW
},
524 pTableRowsElemTokenMap
.reset(new SvXMLTokenMap( aTableRowsElemTokenMap
));
525 } // if( !pTableRowsElemTokenMap )
527 return *pTableRowsElemTokenMap
;
530 const SvXMLTokenMap
& ScXMLImport::GetTableRowElemTokenMap()
532 if( !pTableRowElemTokenMap
)
534 static const SvXMLTokenMapEntry aTableRowTokenMap
[] =
536 { XML_NAMESPACE_TABLE
, XML_TABLE_CELL
, XML_TOK_TABLE_ROW_CELL
},
537 { XML_NAMESPACE_TABLE
, XML_COVERED_TABLE_CELL
, XML_TOK_TABLE_ROW_COVERED_CELL
},
541 pTableRowElemTokenMap
.reset(new SvXMLTokenMap( aTableRowTokenMap
));
542 } // if( !pTableRowElemTokenMap )
544 return *pTableRowElemTokenMap
;
547 const SvXMLTokenMap
& ScXMLImport::GetTableRowAttrTokenMap()
549 if( !pTableRowAttrTokenMap
)
551 static const SvXMLTokenMapEntry aTableRowAttrTokenMap
[] =
553 { XML_NAMESPACE_TABLE
, XML_STYLE_NAME
, XML_TOK_TABLE_ROW_ATTR_STYLE_NAME
},
554 { XML_NAMESPACE_TABLE
, XML_VISIBILITY
, XML_TOK_TABLE_ROW_ATTR_VISIBILITY
},
555 { XML_NAMESPACE_TABLE
, XML_NUMBER_ROWS_REPEATED
, XML_TOK_TABLE_ROW_ATTR_REPEATED
},
556 { XML_NAMESPACE_TABLE
, XML_DEFAULT_CELL_STYLE_NAME
, XML_TOK_TABLE_ROW_ATTR_DEFAULT_CELL_STYLE_NAME
},
557 // { XML_NAMESPACE_TABLE, XML_USE_OPTIMAL_HEIGHT, XML_TOK_TABLE_ROW_ATTR_USE_OPTIMAL_HEIGHT },
561 pTableRowAttrTokenMap
.reset(new SvXMLTokenMap( aTableRowAttrTokenMap
));
562 } // if( !pTableRowAttrTokenMap )
564 return *pTableRowAttrTokenMap
;
567 const SvXMLTokenMap
& ScXMLImport::GetTableRowCellElemTokenMap()
569 if( !pTableRowCellElemTokenMap
)
571 static const SvXMLTokenMapEntry aTableRowCellTokenMap
[] =
573 { XML_NAMESPACE_TEXT
, XML_P
, XML_TOK_TABLE_ROW_CELL_P
},
574 { XML_NAMESPACE_TABLE
, XML_SUB_TABLE
, XML_TOK_TABLE_ROW_CELL_TABLE
},
575 { XML_NAMESPACE_OFFICE
, XML_ANNOTATION
, XML_TOK_TABLE_ROW_CELL_ANNOTATION
},
576 { XML_NAMESPACE_TABLE
, XML_DETECTIVE
, XML_TOK_TABLE_ROW_CELL_DETECTIVE
},
577 { XML_NAMESPACE_TABLE
, XML_CELL_RANGE_SOURCE
, XML_TOK_TABLE_ROW_CELL_CELL_RANGE_SOURCE
},
581 pTableRowCellElemTokenMap
.reset(new SvXMLTokenMap( aTableRowCellTokenMap
));
582 } // if( !pTableRowCellElemTokenMap )
584 return *pTableRowCellElemTokenMap
;
587 const SvXMLTokenMap
& ScXMLImport::GetTableAnnotationAttrTokenMap()
589 if( !pTableAnnotationAttrTokenMap
)
591 static const SvXMLTokenMapEntry aTableAnnotationAttrTokenMap
[] =
593 { XML_NAMESPACE_OFFICE
, XML_AUTHOR
, XML_TOK_TABLE_ANNOTATION_ATTR_AUTHOR
},
594 { XML_NAMESPACE_OFFICE
, XML_CREATE_DATE
, XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE
},
595 { XML_NAMESPACE_OFFICE
, XML_CREATE_DATE_STRING
, XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE_STRING
},
596 { XML_NAMESPACE_OFFICE
, XML_DISPLAY
, XML_TOK_TABLE_ANNOTATION_ATTR_DISPLAY
},
597 { XML_NAMESPACE_SVG
, XML_X
, XML_TOK_TABLE_ANNOTATION_ATTR_X
},
598 { XML_NAMESPACE_SVG
, XML_Y
, XML_TOK_TABLE_ANNOTATION_ATTR_Y
},
602 pTableAnnotationAttrTokenMap
.reset(new SvXMLTokenMap( aTableAnnotationAttrTokenMap
));
603 } // if( !pTableAnnotationAttrTokenMap )
605 return *pTableAnnotationAttrTokenMap
;
609 void ScXMLImport::SetPostProcessData( sc::ImportPostProcessData
* p
)
611 mpPostProcessData
= p
;
614 sc::PivotTableSources
& ScXMLImport::GetPivotTableSources()
617 mpPivotSources
.reset(new sc::PivotTableSources
);
619 return *mpPivotSources
;
622 SvXMLImportContext
*ScXMLImport::CreateFastContext( sal_Int32 nElement
,
623 const uno::Reference
< xml::sax::XFastAttributeList
>& /*xAttrList*/ )
625 SvXMLImportContext
*pContext
= nullptr;
629 case XML_ELEMENT( OFFICE
, XML_DOCUMENT_STYLES
):
630 case XML_ELEMENT( OFFICE
, XML_DOCUMENT_CONTENT
):
631 case XML_ELEMENT( OFFICE
, XML_DOCUMENT_SETTINGS
):
632 pContext
= new ScXMLDocContext_Impl( *this );
635 case XML_ELEMENT( OFFICE
, XML_DOCUMENT_META
):
636 pContext
= CreateMetaContext(nElement
);
639 case XML_ELEMENT( OFFICE
, XML_DOCUMENT
):
641 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
642 GetModel(), uno::UNO_QUERY_THROW
);
643 // flat OpenDocument file format
644 pContext
= new ScXMLFlatDocContext_Impl( *this,
645 xDPS
->getDocumentProperties());
650 pContext
= new SvXMLImportContext( *this );
656 static constexpr OUStringLiteral
gsNumberFormat(SC_UNONAME_NUMFMT
);
657 static constexpr OUStringLiteral
gsLocale(SC_LOCALE
);
658 static constexpr OUStringLiteral
gsCellStyle(SC_UNONAME_CELLSTYL
);
660 ScXMLImport::ScXMLImport(
661 const css::uno::Reference
< css::uno::XComponentContext
>& rContext
,
662 OUString
const & implementationName
, SvXMLImportFlags nImportFlag
)
663 : SvXMLImport( rContext
, implementationName
, nImportFlag
),
665 mpPostProcessData(nullptr),
669 nSolarMutexLocked(0),
673 bNullDateSetted(false),
674 bSelfImportingXMLSet(false),
675 mbLockSolarMutex(true),
676 mbImportStyles(true),
677 mbHasNewCondFormatData(false)
679 pStylesImportHelper
.reset(new ScMyStylesImportHelper(*this));
681 xScPropHdlFactory
= new XMLScPropHdlFactory
;
682 xCellStylesPropertySetMapper
= new XMLPropertySetMapper(aXMLScCellStylesProperties
, xScPropHdlFactory
, false);
683 xColumnStylesPropertySetMapper
= new XMLPropertySetMapper(aXMLScColumnStylesProperties
, xScPropHdlFactory
, false);
684 xRowStylesPropertySetMapper
= new XMLPropertySetMapper(aXMLScRowStylesImportProperties
, xScPropHdlFactory
, false);
685 xTableStylesPropertySetMapper
= new XMLPropertySetMapper(aXMLScTableStylesImportProperties
, xScPropHdlFactory
, false);
687 // #i66550# needed for 'presentation:event-listener' element for URLs in shapes
688 GetNamespaceMap().Add(
689 GetXMLToken( XML_NP_PRESENTATION
),
690 GetXMLToken( XML_N_PRESENTATION
),
691 XML_NAMESPACE_PRESENTATION
);
694 ScXMLImport::~ScXMLImport() throw()
697 pDocElemTokenMap
.reset();
698 pContentValidationElemTokenMap
.reset();
699 pContentValidationMessageElemTokenMap
.reset();
700 pTableElemTokenMap
.reset();
701 pTableRowsElemTokenMap
.reset();
702 pTableRowElemTokenMap
.reset();
703 pTableRowAttrTokenMap
.reset();
704 pTableRowCellElemTokenMap
.reset();
705 pTableRowCellAttrTokenMap
.reset();
706 pTableAnnotationAttrTokenMap
.reset();
708 pChangeTrackingImportHelper
.reset();
709 pNumberFormatAttributesExportHelper
.reset();
710 pStyleNumberFormats
.reset();
711 pStylesImportHelper
.reset();
713 m_pMyNamedExpressions
.reset();
714 pMyLabelRanges
.reset();
715 pValidations
.reset();
716 pDetectiveOpArray
.reset();
718 //call SvXMLImport dtor contents before deleting pSolarMutexGuard
721 pSolarMutexGuard
.reset();
724 void ScXMLImport::initialize( const css::uno::Sequence
<css::uno::Any
>& aArguments
)
726 SvXMLImport::initialize(aArguments
);
728 uno::Reference
<beans::XPropertySet
> xInfoSet
= getImportInfo();
732 uno::Reference
<beans::XPropertySetInfo
> xInfoSetInfo
= xInfoSet
->getPropertySetInfo();
733 if (!xInfoSetInfo
.is())
736 if (xInfoSetInfo
->hasPropertyByName(SC_UNO_ODS_LOCK_SOLAR_MUTEX
))
737 xInfoSet
->getPropertyValue(SC_UNO_ODS_LOCK_SOLAR_MUTEX
) >>= mbLockSolarMutex
;
739 if (xInfoSetInfo
->hasPropertyByName(SC_UNO_ODS_IMPORT_STYLES
))
740 xInfoSet
->getPropertyValue(SC_UNO_ODS_IMPORT_STYLES
) >>= mbImportStyles
;
743 SvXMLImportContext
*ScXMLImport::CreateFontDeclsContext(const sal_uInt16 nPrefix
, const OUString
& rLocalName
,
744 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
)
746 XMLFontStylesContext
*pFSContext
= new XMLFontStylesContext(
747 *this, nPrefix
, rLocalName
, xAttrList
, osl_getThreadTextEncoding());
748 SetFontDecls(pFSContext
);
749 SvXMLImportContext
* pContext
= pFSContext
;
753 SvXMLImportContext
*ScXMLImport::CreateStylesContext(const OUString
& rLocalName
,
754 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
, bool bIsAutoStyle
)
756 SvXMLImportContext
* pContext
= new XMLTableStylesContext(
757 *this, XML_NAMESPACE_OFFICE
, rLocalName
, xAttrList
, bIsAutoStyle
);
760 SetAutoStyles(static_cast<SvXMLStylesContext
*>(pContext
));
762 SetStyles(static_cast<SvXMLStylesContext
*>(pContext
));
767 SvXMLImportContext
*ScXMLImport::CreateBodyContext(const rtl::Reference
<sax_fastparser::FastAttributeList
>& rAttrList
)
769 return new ScXMLBodyContext(*this, rAttrList
);
772 SvXMLImportContext
*ScXMLImport::CreateMetaContext(
773 const sal_Int32
/*nElement*/ )
775 SvXMLImportContext
* pContext
= nullptr;
777 if (getImportFlags() & SvXMLImportFlags::META
)
779 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
780 GetModel(), uno::UNO_QUERY_THROW
);
781 uno::Reference
<document::XDocumentProperties
> const xDocProps(
782 (IsStylesOnlyMode()) ? nullptr : xDPS
->getDocumentProperties());
783 pContext
= new SvXMLMetaDocumentContext(*this, xDocProps
);
787 pContext
= new SvXMLImportContext( *this );
792 SvXMLImportContext
*ScXMLImport::CreateScriptContext(
793 const OUString
& rLocalName
)
795 SvXMLImportContext
* pContext
= nullptr;
797 if( !(IsStylesOnlyMode()) )
799 pContext
= new XMLScriptContext( *this, rLocalName
, GetModel() );
803 pContext
= new SvXMLImportContext( *this, XML_NAMESPACE_OFFICE
,
809 void ScXMLImport::SetStatistics(const uno::Sequence
<beans::NamedValue
> & i_rStats
)
811 static const char* s_stats
[] =
812 { "TableCount", "CellCount", "ObjectCount", nullptr };
814 SvXMLImport::SetStatistics(i_rStats
);
816 sal_uInt32
nCount(0);
817 for (const auto& rStat
: i_rStats
) {
818 for (const char** pStat
= s_stats
; *pStat
!= nullptr; ++pStat
) {
819 if (rStat
.Name
.equalsAscii(*pStat
)) {
821 if (rStat
.Value
>>= val
) {
824 OSL_FAIL("ScXMLImport::SetStatistics: invalid entry");
832 GetProgressBarHelper()->SetReference(nCount
);
833 GetProgressBarHelper()->SetValue(0);
837 ScDocumentImport
& ScXMLImport::GetDoc()
842 sal_Int16
ScXMLImport::GetCellType(const char* rStrValue
, const sal_Int32 nStrLength
)
844 sal_Int16 nCellType
= util::NumberFormat::UNDEFINED
;
845 if (rStrValue
!= nullptr)
847 switch (rStrValue
[0])
850 if (nStrLength
== 7 && !strcmp(rStrValue
, "boolean"))
851 nCellType
= util::NumberFormat::LOGICAL
;
854 if (nStrLength
== 8 && !strcmp(rStrValue
, "currency"))
855 nCellType
= util::NumberFormat::CURRENCY
;
858 if (nStrLength
== 4 && !strcmp(rStrValue
, "date"))
859 nCellType
= util::NumberFormat::DATETIME
;
862 if (nStrLength
== 5 && !strcmp(rStrValue
, "float"))
863 nCellType
= util::NumberFormat::NUMBER
;
866 if (nStrLength
== 10 && !strcmp(rStrValue
, "percentage"))
867 nCellType
= util::NumberFormat::PERCENT
;
870 if (nStrLength
== 6 && !strcmp(rStrValue
, "string"))
871 nCellType
= util::NumberFormat::TEXT
;
874 if (nStrLength
== 4 && !strcmp(rStrValue
, "time"))
875 nCellType
= util::NumberFormat::TIME
;
883 XMLShapeImportHelper
* ScXMLImport::CreateShapeImport()
885 return new XMLTableShapeImportHelper(*this);
888 bool ScXMLImport::GetValidation(const OUString
& sName
, ScMyImportValidation
& aValidation
)
892 auto aItr
= std::find_if(pValidations
->begin(), pValidations
->end(),
893 [&sName
](const ScMyImportValidation
& rValidation
) { return rValidation
.sName
== sName
; });
894 if (aItr
!= pValidations
->end())
896 // source position must be set as string,
897 // so sBaseCellAddress no longer has to be converted here
905 void ScXMLImport::AddNamedExpression(SCTAB nTab
, ScMyNamedExpression
* pNamedExp
)
907 ::std::unique_ptr
<ScMyNamedExpression
> p(pNamedExp
);
908 SheetNamedExpMap::iterator itr
= m_SheetNamedExpressions
.find(nTab
);
909 if (itr
== m_SheetNamedExpressions
.end())
911 // No chain exists for this sheet. Create one.
912 ::std::pair
<SheetNamedExpMap::iterator
, bool> r
=
913 m_SheetNamedExpressions
.insert(std::make_pair(nTab
, std::make_unique
<ScMyNamedExpressions
>()));
920 ScMyNamedExpressions
& r
= *itr
->second
;
921 r
.push_back(std::move(p
));
924 ScXMLChangeTrackingImportHelper
* ScXMLImport::GetChangeTrackingImportHelper()
926 if (!pChangeTrackingImportHelper
)
927 pChangeTrackingImportHelper
.reset(new ScXMLChangeTrackingImportHelper());
928 return pChangeTrackingImportHelper
.get();
931 void ScXMLImport::InsertStyles()
933 GetStyles()->CopyStylesToDoc(true);
935 // if content is going to be loaded with the same import, set bLatinDefaultStyle flag now
936 if ( getImportFlags() & SvXMLImportFlags::CONTENT
)
937 ExamineDefaultStyle();
940 void ScXMLImport::ExamineDefaultStyle()
944 // #i62435# after inserting the styles, check if the default style has a latin-script-only
945 // number format (then, value cells can be pre-initialized with western script type)
947 const ScPatternAttr
* pDefPattern
= pDoc
->GetDefPattern();
948 if (pDefPattern
&& sc::NumFmtUtil::isLatinScript(*pDefPattern
, *pDoc
))
949 mpDocImport
->setDefaultNumericScript(SvtScriptType::LATIN
);
953 void ScXMLImport::SetChangeTrackingViewSettings(const css::uno::Sequence
<css::beans::PropertyValue
>& rChangeProps
)
957 if (rChangeProps
.hasElements())
959 ScXMLImport::MutexGuard
aGuard(*this);
960 sal_Int16
nTemp16(0);
961 std::unique_ptr
<ScChangeViewSettings
> pViewSettings(new ScChangeViewSettings());
962 for (const auto& rChangeProp
: rChangeProps
)
964 OUString
sName(rChangeProp
.Name
);
965 if (sName
== "ShowChanges")
966 pViewSettings
->SetShowChanges(::cppu::any2bool(rChangeProp
.Value
));
967 else if (sName
== "ShowAcceptedChanges")
968 pViewSettings
->SetShowAccepted(::cppu::any2bool(rChangeProp
.Value
));
969 else if (sName
== "ShowRejectedChanges")
970 pViewSettings
->SetShowRejected(::cppu::any2bool(rChangeProp
.Value
));
971 else if (sName
== "ShowChangesByDatetime")
972 pViewSettings
->SetHasDate(::cppu::any2bool(rChangeProp
.Value
));
973 else if (sName
== "ShowChangesByDatetimeMode")
975 if (rChangeProp
.Value
>>= nTemp16
)
976 pViewSettings
->SetTheDateMode(static_cast<SvxRedlinDateMode
>(nTemp16
));
978 else if (sName
== "ShowChangesByDatetimeFirstDatetime")
980 util::DateTime aDateTime
;
981 if (rChangeProp
.Value
>>= aDateTime
)
983 pViewSettings
->SetTheFirstDateTime(::DateTime(aDateTime
));
986 else if (sName
== "ShowChangesByDatetimeSecondDatetime")
988 util::DateTime aDateTime
;
989 if (rChangeProp
.Value
>>= aDateTime
)
991 pViewSettings
->SetTheLastDateTime(::DateTime(aDateTime
));
994 else if (sName
== "ShowChangesByAuthor")
995 pViewSettings
->SetHasAuthor(::cppu::any2bool(rChangeProp
.Value
));
996 else if (sName
== "ShowChangesByAuthorName")
999 if (rChangeProp
.Value
>>= sOUName
)
1001 pViewSettings
->SetTheAuthorToShow(sOUName
);
1004 else if (sName
== "ShowChangesByComment")
1005 pViewSettings
->SetHasComment(::cppu::any2bool(rChangeProp
.Value
));
1006 else if (sName
== "ShowChangesByCommentText")
1008 OUString sOUComment
;
1009 if (rChangeProp
.Value
>>= sOUComment
)
1011 pViewSettings
->SetTheComment(sOUComment
);
1014 else if (sName
== "ShowChangesByRanges")
1015 pViewSettings
->SetHasRange(::cppu::any2bool(rChangeProp
.Value
));
1016 else if (sName
== "ShowChangesByRangesList")
1019 if ((rChangeProp
.Value
>>= sRanges
) && !sRanges
.isEmpty())
1021 ScRangeList aRangeList
;
1022 ScRangeStringConverter::GetRangeListFromString(
1023 aRangeList
, sRanges
, GetDocument(), FormulaGrammar::CONV_OOO
);
1024 pViewSettings
->SetTheRangeList(aRangeList
);
1028 pDoc
->SetChangeViewSettings(*pViewSettings
);
1033 void ScXMLImport::SetViewSettings(const uno::Sequence
<beans::PropertyValue
>& aViewProps
)
1035 sal_Int32
nHeight(0);
1038 sal_Int32
nWidth(0);
1039 for (const auto& rViewProp
: aViewProps
)
1041 OUString
sName(rViewProp
.Name
);
1042 if (sName
== "VisibleAreaHeight")
1043 rViewProp
.Value
>>= nHeight
;
1044 else if (sName
== "VisibleAreaLeft")
1045 rViewProp
.Value
>>= nLeft
;
1046 else if (sName
== "VisibleAreaTop")
1047 rViewProp
.Value
>>= nTop
;
1048 else if (sName
== "VisibleAreaWidth")
1049 rViewProp
.Value
>>= nWidth
;
1050 else if (sName
== "TrackedChangesViewSettings")
1052 uno::Sequence
<beans::PropertyValue
> aChangeProps
;
1053 if(rViewProp
.Value
>>= aChangeProps
)
1054 SetChangeTrackingViewSettings(aChangeProps
);
1057 if (nHeight
&& nWidth
&& GetModel().is())
1059 ScModelObj
* pDocObj(comphelper::getUnoTunnelImplementation
<ScModelObj
>( GetModel() ));
1062 SfxObjectShell
* pEmbeddedObj
= pDocObj
->GetEmbeddedObject();
1065 tools::Rectangle aRect
;
1066 aRect
.setX( nLeft
);
1068 aRect
.setWidth( nWidth
);
1069 aRect
.setHeight( nHeight
);
1070 pEmbeddedObj
->SetVisArea(aRect
);
1076 void ScXMLImport::SetConfigurationSettings(const uno::Sequence
<beans::PropertyValue
>& aConfigProps
)
1078 if (GetModel().is())
1080 uno::Reference
<lang::XMultiServiceFactory
> xMultiServiceFactory(GetModel(), uno::UNO_QUERY
);
1081 if (xMultiServiceFactory
.is())
1083 sal_Int32
nCount(aConfigProps
.getLength());
1084 css::uno::Sequence
<css::beans::PropertyValue
> aFilteredProps(nCount
);
1085 sal_Int32 nFilteredPropsLen
= 0;
1086 for (sal_Int32 i
= nCount
- 1; i
>= 0; --i
)
1088 if (aConfigProps
[i
].Name
== "TrackedChangesProtectionKey")
1091 if (aConfigProps
[i
].Value
>>= sKey
)
1093 uno::Sequence
<sal_Int8
> aPass
;
1094 ::comphelper::Base64::decode(aPass
, sKey
);
1095 if (aPass
.hasElements())
1097 if (pDoc
->GetChangeTrack())
1098 pDoc
->GetChangeTrack()->SetProtection(aPass
);
1101 std::set
<OUString
> aUsers
;
1102 std::unique_ptr
<ScChangeTrack
> pTrack( new ScChangeTrack(pDoc
, aUsers
) );
1103 pTrack
->SetProtection(aPass
);
1104 pDoc
->SetChangeTrack(std::move(pTrack
));
1109 // store the following items for later use (after document is loaded)
1110 else if ((aConfigProps
[i
].Name
== "VBACompatibilityMode") || (aConfigProps
[i
].Name
== "ScriptConfiguration"))
1112 uno::Reference
< beans::XPropertySet
> xImportInfo
= getImportInfo();
1113 if (xImportInfo
.is())
1115 uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo
= xImportInfo
->getPropertySetInfo();
1116 if (xPropertySetInfo
.is() && xPropertySetInfo
->hasPropertyByName(aConfigProps
[i
].Name
))
1117 xImportInfo
->setPropertyValue( aConfigProps
[i
].Name
, aConfigProps
[i
].Value
);
1120 if (aConfigProps
[i
].Name
!= "LinkUpdateMode")
1122 aFilteredProps
[nFilteredPropsLen
++] = aConfigProps
[i
];
1125 aFilteredProps
.realloc(nFilteredPropsLen
);
1126 uno::Reference
<uno::XInterface
> xInterface
= xMultiServiceFactory
->createInstance("com.sun.star.comp.SpreadsheetSettings");
1127 uno::Reference
<beans::XPropertySet
> xProperties(xInterface
, uno::UNO_QUERY
);
1128 if (xProperties
.is())
1129 SvXMLUnitConverter::convertPropertySet(xProperties
, aFilteredProps
);
1134 sal_Int32
ScXMLImport::SetCurrencySymbol(const sal_Int32 nKey
, const OUString
& rCurrency
)
1136 uno::Reference
<util::XNumberFormatsSupplier
> xNumberFormatsSupplier(GetNumberFormatsSupplier());
1137 if (xNumberFormatsSupplier
.is())
1139 uno::Reference
<util::XNumberFormats
> xLocalNumberFormats(xNumberFormatsSupplier
->getNumberFormats());
1140 if (xLocalNumberFormats
.is())
1142 OUString sFormatString
;
1145 uno::Reference
<beans::XPropertySet
> xProperties(xLocalNumberFormats
->getByKey(nKey
));
1146 if (xProperties
.is())
1148 lang::Locale aLocale
;
1149 if (GetDocument() && (xProperties
->getPropertyValue(gsLocale
) >>= aLocale
))
1152 ScXMLImport::MutexGuard
aGuard(*this);
1153 LocaleDataWrapper
aLocaleData( comphelper::getProcessComponentContext(), LanguageTag( aLocale
) );
1154 OUStringBuffer
aBuffer(15);
1155 aBuffer
.append("#");
1156 aBuffer
.append( aLocaleData
.getNumThousandSep() );
1157 aBuffer
.append("##0");
1158 aBuffer
.append( aLocaleData
.getNumDecimalSep() );
1159 aBuffer
.append("00 [$");
1160 aBuffer
.append(rCurrency
);
1161 aBuffer
.append("]");
1162 sFormatString
= aBuffer
.makeStringAndClear();
1164 sal_Int32 nNewKey
= xLocalNumberFormats
->queryKey(sFormatString
, aLocale
, true);
1166 nNewKey
= xLocalNumberFormats
->addNew(sFormatString
, aLocale
);
1171 catch ( const util::MalformedNumberFormatException
& rException
)
1173 OUString sErrorMessage
="Error in Formatstring " +
1174 sFormatString
+ " at position " +
1175 OUString::number(rException
.CheckPos
);
1176 uno::Sequence
<OUString
> aSeq
{ sErrorMessage
};
1177 uno::Reference
<xml::sax::XLocator
> xLocator
;
1178 SetError(XMLERROR_API
| XMLERROR_FLAG_ERROR
, aSeq
, rException
.Message
, xLocator
);
1185 bool ScXMLImport::IsCurrencySymbol(const sal_Int32 nNumberFormat
, const OUString
& sCurrentCurrency
, const OUString
& sBankSymbol
)
1187 uno::Reference
<util::XNumberFormatsSupplier
> xNumberFormatsSupplier(GetNumberFormatsSupplier());
1188 if (xNumberFormatsSupplier
.is())
1190 uno::Reference
<util::XNumberFormats
> xLocalNumberFormats(xNumberFormatsSupplier
->getNumberFormats());
1191 if (xLocalNumberFormats
.is())
1195 uno::Reference
<beans::XPropertySet
> xNumberPropertySet(xLocalNumberFormats
->getByKey(nNumberFormat
));
1196 if (xNumberPropertySet
.is())
1199 if ( xNumberPropertySet
->getPropertyValue(SC_CURRENCYSYMBOL
) >>= sTemp
)
1201 if (sCurrentCurrency
== sTemp
)
1203 // A release that saved an unknown currency may have
1204 // saved the currency symbol of the number format
1205 // instead of an ISO code bank symbol. In another
1206 // release we may have a match for that. In this case
1207 // sCurrentCurrency is the ISO code obtained through
1208 // XMLNumberFormatAttributesExportHelper::GetCellType()
1209 // and sBankSymbol is the currency symbol.
1210 if (sCurrentCurrency
.getLength() == 3 && sBankSymbol
== sTemp
)
1212 // #i61657# This may be a legacy currency symbol that changed in the meantime.
1213 if (SvNumberFormatter::GetLegacyOnlyCurrencyEntry( sCurrentCurrency
, sBankSymbol
) != nullptr)
1215 // In the rare case that sCurrentCurrency is not the
1216 // currency symbol, but a matching ISO code
1217 // abbreviation instead that was obtained through
1218 // XMLNumberFormatAttributesExportHelper::GetCellType(),
1219 // check with the number format's symbol. This happens,
1220 // for example, in the es_BO locale, where a legacy
1221 // B$,BOB matched B$->BOP, which leads to
1222 // sCurrentCurrency being BOP, and the previous call
1223 // with BOP,BOB didn't find an entry, but B$,BOB will.
1224 return SvNumberFormatter::GetLegacyOnlyCurrencyEntry( sTemp
, sBankSymbol
) != nullptr;
1228 catch ( uno::Exception
& )
1230 OSL_FAIL("Numberformat not found");
1237 void ScXMLImport::SetType(const uno::Reference
<beans::XPropertySet
>& rProperties
,
1238 sal_Int32
& rNumberFormat
,
1239 const sal_Int16 nCellType
,
1240 const OUString
& rCurrency
)
1242 if (!mbImportStyles
)
1245 if ((nCellType
!= util::NumberFormat::TEXT
) && (nCellType
!= util::NumberFormat::UNDEFINED
))
1247 if (rNumberFormat
== -1)
1248 rProperties
->getPropertyValue( gsNumberFormat
) >>= rNumberFormat
;
1249 OSL_ENSURE(rNumberFormat
!= -1, "no NumberFormat");
1251 // sCurrentCurrency may be the ISO code abbreviation if the currency
1252 // symbol matches such, or if no match found the symbol itself!
1253 OUString sCurrentCurrency
;
1254 sal_Int32
nCurrentCellType(
1255 GetNumberFormatAttributesExportHelper()->GetCellType(
1256 rNumberFormat
, sCurrentCurrency
, bIsStandard
) & ~util::NumberFormat::DEFINED
);
1257 // If the (numeric) cell type (number, currency, date, time, boolean)
1258 // is different from the format type then for some combinations we may
1259 // have to apply a format, e.g. in case the generator deduced format
1260 // from type and did not apply a format but we don't keep a dedicated
1261 // type internally. Specifically this is necessary if the cell type is
1262 // not number but the format type is (i.e. General). Currency cells
1263 // need extra attention, see calls of ScXMLImport::IsCurrencySymbol()
1264 // and description within there and ScXMLImport::SetCurrencySymbol().
1265 if ((nCellType
!= nCurrentCellType
) &&
1266 (nCellType
!= util::NumberFormat::NUMBER
) &&
1267 (bIsStandard
|| (nCellType
== util::NumberFormat::CURRENCY
)))
1269 if (!xNumberFormats
.is())
1271 uno::Reference
<util::XNumberFormatsSupplier
> xNumberFormatsSupplier(GetNumberFormatsSupplier());
1272 if (xNumberFormatsSupplier
.is())
1273 xNumberFormats
.set(xNumberFormatsSupplier
->getNumberFormats());
1275 if (xNumberFormats
.is())
1279 uno::Reference
< beans::XPropertySet
> xNumberFormatProperties(xNumberFormats
->getByKey(rNumberFormat
));
1280 if (xNumberFormatProperties
.is())
1282 if (nCellType
!= util::NumberFormat::CURRENCY
)
1284 lang::Locale aLocale
;
1285 if ( xNumberFormatProperties
->getPropertyValue(gsLocale
) >>= aLocale
)
1287 if (!xNumberFormatTypes
.is())
1288 xNumberFormatTypes
.set(uno::Reference
<util::XNumberFormatTypes
>(xNumberFormats
, uno::UNO_QUERY
));
1289 rProperties
->setPropertyValue( gsNumberFormat
, uno::makeAny(xNumberFormatTypes
->getStandardFormat(nCellType
, aLocale
)) );
1292 else if (!rCurrency
.isEmpty() && !sCurrentCurrency
.isEmpty())
1294 if (sCurrentCurrency
!= rCurrency
)
1295 if (!IsCurrencySymbol(rNumberFormat
, sCurrentCurrency
, rCurrency
))
1296 rProperties
->setPropertyValue( gsNumberFormat
, uno::makeAny(SetCurrencySymbol(rNumberFormat
, rCurrency
)));
1300 catch ( uno::Exception
& )
1302 OSL_FAIL("Numberformat not found");
1308 if ((nCellType
== util::NumberFormat::CURRENCY
) && !rCurrency
.isEmpty() && !sCurrentCurrency
.isEmpty() &&
1309 sCurrentCurrency
!= rCurrency
&& !IsCurrencySymbol(rNumberFormat
, sCurrentCurrency
, rCurrency
))
1310 rProperties
->setPropertyValue( gsNumberFormat
, uno::makeAny(SetCurrencySymbol(rNumberFormat
, rCurrency
)));
1315 void ScXMLImport::AddStyleRange(const table::CellRangeAddress
& rCellRange
)
1317 if (!mbImportStyles
)
1320 if (!xSheetCellRanges
.is() && GetModel().is())
1322 uno::Reference
<lang::XMultiServiceFactory
> xMultiServiceFactory(GetModel(), uno::UNO_QUERY
);
1323 if (xMultiServiceFactory
.is())
1324 xSheetCellRanges
.set(uno::Reference
<sheet::XSheetCellRangeContainer
>(xMultiServiceFactory
->createInstance("com.sun.star.sheet.SheetCellRanges"), uno::UNO_QUERY
));
1325 OSL_ENSURE(xSheetCellRanges
.is(), "didn't get SheetCellRanges");
1328 xSheetCellRanges
->addRangeAddress(rCellRange
, false);
1331 void ScXMLImport::SetStyleToRanges()
1333 if (!mbImportStyles
)
1336 if (!sPrevStyleName
.isEmpty())
1338 uno::Reference
<beans::XPropertySet
> xProperties (xSheetCellRanges
, uno::UNO_QUERY
);
1339 if (xProperties
.is())
1341 XMLTableStylesContext
*pStyles(static_cast<XMLTableStylesContext
*>(GetAutoStyles()));
1342 XMLTableStyleContext
* pStyle
= nullptr;
1344 pStyle
= const_cast<XMLTableStyleContext
*>(static_cast<const XMLTableStyleContext
*>(pStyles
->FindStyleChildContext(
1345 XML_STYLE_FAMILY_TABLE_CELL
, sPrevStyleName
, true)));
1348 pStyle
->FillPropertySet(xProperties
);
1349 // here needs to be the cond format import method
1350 sal_Int32
nNumberFormat(pStyle
->GetNumberFormat());
1351 SetType(xProperties
, nNumberFormat
, nPrevCellType
, sPrevCurrency
);
1353 css::uno::Any aAny
= xProperties
->getPropertyValue("FormatID");
1354 sal_uInt64 nKey
= 0;
1355 if ((aAny
>>= nKey
) && nKey
)
1357 ScFormatSaveData
* pFormatSaveData
= comphelper::getUnoTunnelImplementation
<ScModelObj
>(GetModel())->GetFormatSaveData();
1358 pFormatSaveData
->maIDToName
.insert(std::pair
<sal_uInt64
, OUString
>(nKey
, sPrevStyleName
));
1361 // store first cell of first range for each style, once per sheet
1362 uno::Sequence
<table::CellRangeAddress
> aAddresses(xSheetCellRanges
->getRangeAddresses());
1363 pStyle
->ApplyCondFormat(aAddresses
);
1364 if ( aAddresses
.hasElements() )
1366 const table::CellRangeAddress
& rRange
= aAddresses
[0];
1367 if ( rRange
.Sheet
!= pStyle
->GetLastSheet() )
1369 ScSheetSaveData
* pSheetData
= comphelper::getUnoTunnelImplementation
<ScModelObj
>(GetModel())->GetSheetSaveData();
1370 pSheetData
->AddCellStyle( sPrevStyleName
,
1371 ScAddress( static_cast<SCCOL
>(rRange
.StartColumn
), static_cast<SCROW
>(rRange
.StartRow
), static_cast<SCTAB
>(rRange
.Sheet
) ) );
1372 pStyle
->SetLastSheet(rRange
.Sheet
);
1378 xProperties
->setPropertyValue(gsCellStyle
, uno::makeAny(GetStyleDisplayName( XML_STYLE_FAMILY_TABLE_CELL
, sPrevStyleName
)));
1379 sal_Int32
nNumberFormat(GetStyleNumberFormats()->GetStyleNumberFormat(sPrevStyleName
));
1380 bool bInsert(nNumberFormat
== -1);
1381 SetType(xProperties
, nNumberFormat
, nPrevCellType
, sPrevCurrency
);
1383 GetStyleNumberFormats()->AddStyleNumberFormat(sPrevStyleName
, nNumberFormat
);
1387 if (GetModel().is())
1389 uno::Reference
<lang::XMultiServiceFactory
> xMultiServiceFactory(GetModel(), uno::UNO_QUERY
);
1390 if (xMultiServiceFactory
.is())
1391 xSheetCellRanges
.set(uno::Reference
<sheet::XSheetCellRangeContainer
>(
1392 xMultiServiceFactory
->createInstance("com.sun.star.sheet.SheetCellRanges"),
1395 OSL_ENSURE(xSheetCellRanges
.is(), "didn't get SheetCellRanges");
1398 void ScXMLImport::SetStyleToRange(const ScRange
& rRange
, const OUString
* pStyleName
,
1399 const sal_Int16 nCellType
, const OUString
* pCurrency
)
1401 if (!mbImportStyles
)
1404 if (sPrevStyleName
.isEmpty())
1406 nPrevCellType
= nCellType
;
1408 sPrevStyleName
= *pStyleName
;
1410 sPrevCurrency
= *pCurrency
;
1411 else if (!sPrevCurrency
.isEmpty())
1412 sPrevCurrency
.clear();
1414 else if ((nCellType
!= nPrevCellType
) ||
1415 ((pStyleName
&& *pStyleName
!= sPrevStyleName
) ||
1416 (!pStyleName
&& !sPrevStyleName
.isEmpty())) ||
1417 ((pCurrency
&& *pCurrency
!= sPrevCurrency
) ||
1418 (!pCurrency
&& !sPrevCurrency
.isEmpty())))
1421 nPrevCellType
= nCellType
;
1423 sPrevStyleName
= *pStyleName
;
1424 else if(!sPrevStyleName
.isEmpty())
1425 sPrevStyleName
.clear();
1427 sPrevCurrency
= *pCurrency
;
1428 else if(!sPrevCurrency
.isEmpty())
1429 sPrevCurrency
.clear();
1431 table::CellRangeAddress aCellRange
;
1432 aCellRange
.StartColumn
= rRange
.aStart
.Col();
1433 aCellRange
.StartRow
= rRange
.aStart
.Row();
1434 aCellRange
.Sheet
= rRange
.aStart
.Tab();
1435 aCellRange
.EndColumn
= rRange
.aEnd
.Col();
1436 aCellRange
.EndRow
= rRange
.aEnd
.Row();
1437 AddStyleRange(aCellRange
);
1440 bool ScXMLImport::SetNullDateOnUnitConverter()
1442 if (!bNullDateSetted
)
1443 bNullDateSetted
= GetMM100UnitConverter().setNullDate(GetModel());
1444 OSL_ENSURE(bNullDateSetted
, "could not set the null date");
1445 return bNullDateSetted
;
1448 XMLNumberFormatAttributesExportHelper
* ScXMLImport::GetNumberFormatAttributesExportHelper()
1450 if (!pNumberFormatAttributesExportHelper
)
1451 pNumberFormatAttributesExportHelper
.reset(new XMLNumberFormatAttributesExportHelper(GetNumberFormatsSupplier()));
1452 return pNumberFormatAttributesExportHelper
.get();
1455 ScMyStyleNumberFormats
* ScXMLImport::GetStyleNumberFormats()
1457 if (!pStyleNumberFormats
)
1458 pStyleNumberFormats
.reset(new ScMyStyleNumberFormats
);
1459 return pStyleNumberFormats
.get();
1462 void ScXMLImport::SetStylesToRangesFinished()
1465 sPrevStyleName
.clear();
1469 void SAL_CALL
ScXMLImport::setTargetDocument( const css::uno::Reference
< css::lang::XComponent
>& xDoc
)
1471 ScXMLImport::MutexGuard
aGuard(*this);
1472 SvXMLImport::setTargetDocument( xDoc
);
1474 uno::Reference
<frame::XModel
> xModel(xDoc
, uno::UNO_QUERY
);
1475 pDoc
= ScXMLConverter::GetScDocument( xModel
);
1476 OSL_ENSURE( pDoc
, "ScXMLImport::setTargetDocument - no ScDocument!" );
1478 throw lang::IllegalArgumentException();
1480 mpDocImport
.reset(new ScDocumentImport(*pDoc
));
1481 mpComp
.reset(new ScCompiler(pDoc
, ScAddress(), formula::FormulaGrammar::GRAM_ODFF
));
1483 uno::Reference
<document::XActionLockable
> xActionLockable(xDoc
, uno::UNO_QUERY
);
1484 if (xActionLockable
.is())
1485 xActionLockable
->addActionLock();
1488 // css::xml::sax::XDocumentHandler
1489 void SAL_CALL
ScXMLImport::startDocument()
1491 ScXMLImport::MutexGuard
aGuard(*this);
1492 SvXMLImport::startDocument();
1493 if (pDoc
&& !pDoc
->IsImportingXML())
1495 comphelper::getUnoTunnelImplementation
<ScModelObj
>(GetModel())->BeforeXMLLoading();
1496 bSelfImportingXMLSet
= true;
1499 // if content and styles are loaded with separate imports,
1500 // set bLatinDefaultStyle flag at the start of the content import
1501 SvXMLImportFlags nFlags
= getImportFlags();
1502 if ( ( nFlags
& SvXMLImportFlags::CONTENT
) && !( nFlags
& SvXMLImportFlags::STYLES
) )
1503 ExamineDefaultStyle();
1505 if (getImportFlags() & SvXMLImportFlags::CONTENT
)
1507 if (GetModel().is())
1509 // store initial namespaces, to find the ones that were added from the file later
1510 ScSheetSaveData
* pSheetData
= comphelper::getUnoTunnelImplementation
<ScModelObj
>(GetModel())->GetSheetSaveData();
1511 const SvXMLNamespaceMap
& rNamespaces
= GetNamespaceMap();
1512 pSheetData
->StoreInitialNamespaces(rNamespaces
);
1516 uno::Reference
< beans::XPropertySet
> const xImportInfo( getImportInfo() );
1517 uno::Reference
< beans::XPropertySetInfo
> const xPropertySetInfo(
1518 xImportInfo
.is() ? xImportInfo
->getPropertySetInfo() : nullptr);
1519 if (xPropertySetInfo
.is())
1521 OUString
const sOrganizerMode(
1523 if (xPropertySetInfo
->hasPropertyByName(sOrganizerMode
))
1525 bool bStyleOnly(false);
1526 if (xImportInfo
->getPropertyValue(sOrganizerMode
) >>= bStyleOnly
)
1528 bLoadDoc
= !bStyleOnly
;
1536 sal_Int32
ScXMLImport::GetRangeType(const OUString
& sRangeType
)
1538 sal_Int32
nRangeType(0);
1539 OUStringBuffer sBuffer
;
1541 while (i
<= sRangeType
.getLength())
1543 if ((i
== sRangeType
.getLength()) || (sRangeType
[i
] == ' '))
1545 OUString sTemp
= sBuffer
.makeStringAndClear();
1546 if (sTemp
== "repeat-column")
1547 nRangeType
|= sheet::NamedRangeFlag::COLUMN_HEADER
;
1548 else if (sTemp
== SC_REPEAT_ROW
)
1549 nRangeType
|= sheet::NamedRangeFlag::ROW_HEADER
;
1550 else if (sTemp
== SC_FILTER
)
1551 nRangeType
|= sheet::NamedRangeFlag::FILTER_CRITERIA
;
1552 else if (sTemp
== SC_PRINT_RANGE
)
1553 nRangeType
|= sheet::NamedRangeFlag::PRINT_AREA
;
1555 else if (i
< sRangeType
.getLength())
1556 sBuffer
.append(sRangeType
[i
]);
1562 void ScXMLImport::SetLabelRanges()
1566 uno::Reference
<beans::XPropertySet
> xPropertySet (GetModel(), uno::UNO_QUERY
);
1567 if (xPropertySet
.is())
1569 uno::Any aColAny
= xPropertySet
->getPropertyValue(SC_UNO_COLLABELRNG
);
1570 uno::Any aRowAny
= xPropertySet
->getPropertyValue(SC_UNO_ROWLABELRNG
);
1572 uno::Reference
< sheet::XLabelRanges
> xColRanges
;
1573 uno::Reference
< sheet::XLabelRanges
> xRowRanges
;
1575 if ( ( aColAny
>>= xColRanges
) && ( aRowAny
>>= xRowRanges
) )
1577 table::CellRangeAddress aLabelRange
;
1578 table::CellRangeAddress aDataRange
;
1580 for (const auto& rxLabelRange
: *pMyLabelRanges
)
1582 sal_Int32
nOffset1(0);
1583 sal_Int32
nOffset2(0);
1584 FormulaGrammar::AddressConvention eConv
= FormulaGrammar::CONV_OOO
;
1586 if (ScRangeStringConverter::GetRangeFromString( aLabelRange
, rxLabelRange
->sLabelRangeStr
, GetDocument(), eConv
, nOffset1
) &&
1587 ScRangeStringConverter::GetRangeFromString( aDataRange
, rxLabelRange
->sDataRangeStr
, GetDocument(), eConv
, nOffset2
))
1589 if ( rxLabelRange
->bColumnOrientation
)
1590 xColRanges
->addNew( aLabelRange
, aDataRange
);
1592 xRowRanges
->addNew( aLabelRange
, aDataRange
);
1596 pMyLabelRanges
->clear();
1604 class RangeNameInserter
1606 ScDocument
* const mpDoc
;
1607 ScRangeName
& mrRangeName
;
1610 RangeNameInserter(ScDocument
* pDoc
, ScRangeName
& rRangeName
) :
1611 mpDoc(pDoc
), mrRangeName(rRangeName
) {}
1613 void operator() (const std::unique_ptr
<ScMyNamedExpression
>& p
) const
1615 using namespace formula
;
1617 const OUString
& aType
= p
->sRangeType
;
1618 sal_uInt32 nUnoType
= ScXMLImport::GetRangeType(aType
);
1620 ScRangeData::Type nNewType
= ScRangeData::Type::Name
;
1621 if ( nUnoType
& sheet::NamedRangeFlag::FILTER_CRITERIA
) nNewType
|= ScRangeData::Type::Criteria
;
1622 if ( nUnoType
& sheet::NamedRangeFlag::PRINT_AREA
) nNewType
|= ScRangeData::Type::PrintArea
;
1623 if ( nUnoType
& sheet::NamedRangeFlag::COLUMN_HEADER
) nNewType
|= ScRangeData::Type::ColHeader
;
1624 if ( nUnoType
& sheet::NamedRangeFlag::ROW_HEADER
) nNewType
|= ScRangeData::Type::RowHeader
;
1628 // Insert a new name.
1630 sal_Int32 nOffset
= 0;
1631 bool bSuccess
= ScRangeStringConverter::GetAddressFromString(
1632 aPos
, p
->sBaseCellAddress
, mpDoc
, FormulaGrammar::CONV_OOO
, nOffset
);
1636 OUString aContent
= p
->sContent
;
1637 if (!p
->bIsExpression
)
1638 ScXMLConverter::ConvertCellRangeAddress(aContent
);
1640 ScRangeData
* pData
= new ScRangeData(
1641 mpDoc
, p
->sName
, aContent
, aPos
, nNewType
, p
->eGrammar
);
1642 mrRangeName
.insert(pData
);
1650 void ScXMLImport::SetNamedRanges()
1652 if (!m_pMyNamedExpressions
)
1658 // Insert the namedRanges
1659 ScRangeName
* pRangeNames
= pDoc
->GetRangeName();
1660 ::std::for_each(m_pMyNamedExpressions
->begin(), m_pMyNamedExpressions
->end(), RangeNameInserter(pDoc
, *pRangeNames
));
1663 void ScXMLImport::SetSheetNamedRanges()
1668 for (auto const& itr
: m_SheetNamedExpressions
)
1670 const SCTAB nTab
= itr
.first
;
1671 ScRangeName
* pRangeNames
= pDoc
->GetRangeName(nTab
);
1675 const ScMyNamedExpressions
& rNames
= *itr
.second
;
1676 ::std::for_each(rNames
.begin(), rNames
.end(), RangeNameInserter(pDoc
, *pRangeNames
));
1680 void ScXMLImport::SetStringRefSyntaxIfMissing()
1685 ScCalcConfig aCalcConfig
= pDoc
->GetCalcConfig();
1687 // Has any string ref syntax been imported?
1688 // If not, we need to take action
1689 if ( !aCalcConfig
.mbHasStringRefSyntax
)
1691 aCalcConfig
.meStringRefAddressSyntax
= formula::FormulaGrammar::CONV_A1_XL_A1
;
1692 pDoc
->SetCalcConfig(aCalcConfig
);
1696 void SAL_CALL
ScXMLImport::endDocument()
1698 ScXMLImport::MutexGuard
aGuard(*this);
1699 if (getImportFlags() & SvXMLImportFlags::CONTENT
)
1701 if (GetModel().is())
1703 mpDocImport
->finalize();
1705 uno::Reference
<document::XViewDataSupplier
> xViewDataSupplier(GetModel(), uno::UNO_QUERY
);
1706 if (xViewDataSupplier
.is())
1708 uno::Reference
<container::XIndexAccess
> xIndexAccess(xViewDataSupplier
->getViewData());
1709 if (xIndexAccess
.is() && xIndexAccess
->getCount() > 0)
1711 uno::Sequence
< beans::PropertyValue
> aSeq
;
1712 if (xIndexAccess
->getByIndex(0) >>= aSeq
)
1714 for (const auto& rProp
: std::as_const(aSeq
))
1716 OUString
sName(rProp
.Name
);
1717 if (sName
== SC_ACTIVETABLE
)
1720 if(rProp
.Value
>>= sTabName
)
1723 if (pDoc
->GetTable(sTabName
, nTab
))
1725 pDoc
->SetVisibleTab(nTab
);
1736 SetSheetNamedRanges();
1737 SetStringRefSyntaxIfMissing();
1739 // Process pivot table sources after the named ranges have been set.
1740 mpPivotSources
->process();
1742 GetProgressBarHelper()->End(); // make room for subsequent SfxProgressBars
1747 // After CompileXML, links must be completely changed to the new URLs.
1748 // Otherwise, hasExternalFile for API wouldn't work (#i116940#),
1749 // and typing a new formula would create a second link with the same "real" file name.
1750 if (pDoc
->HasExternalRefManager())
1751 pDoc
->GetExternalRefManager()->updateAbsAfterLoad();
1754 // If the stream contains cells outside of the current limits, the styles can't be re-created,
1755 // so stream copying is disabled then.
1756 if (pDoc
&& GetModel().is() && !pDoc
->HasRangeOverflow())
1758 // set "valid stream" flags after loading (before UpdateRowHeights, so changed formula results
1759 // in UpdateRowHeights can already clear the flags again)
1760 ScSheetSaveData
* pSheetData
= comphelper::getUnoTunnelImplementation
<ScModelObj
>(GetModel())->GetSheetSaveData();
1762 SCTAB nTabCount
= pDoc
->GetTableCount();
1763 for (SCTAB nTab
=0; nTab
<nTabCount
; ++nTab
)
1765 pDoc
->SetDrawPageSize(nTab
);
1766 if (!pSheetData
->IsSheetBlocked( nTab
))
1767 pDoc
->SetStreamValid( nTab
, true );
1771 // There are rows with optimal height which need to be updated
1772 if (pDoc
&& !maRecalcRowRanges
.empty())
1774 bool bLockHeight
= pDoc
->IsAdjustHeightLocked();
1777 pDoc
->UnlockAdjustHeight();
1780 ScSizeDeviceProvider
aProv(static_cast<ScDocShell
*>(pDoc
->GetDocumentShell()));
1781 ScDocRowHeightUpdater
aUpdater(*pDoc
, aProv
.GetDevice(), aProv
.GetPPTX(), aProv
.GetPPTY(), &maRecalcRowRanges
);
1786 pDoc
->LockAdjustHeight();
1790 aTables
.FixupOLEs();
1792 if (GetModel().is())
1794 uno::Reference
<document::XActionLockable
> xActionLockable(GetModel(), uno::UNO_QUERY
);
1795 if (xActionLockable
.is())
1796 xActionLockable
->removeActionLock();
1798 SvXMLImport::endDocument();
1802 pDoc
->BroadcastUno(SfxHint(SfxHintId::ScClearCache
));
1805 if(pDoc
&& bSelfImportingXMLSet
)
1806 comphelper::getUnoTunnelImplementation
<ScModelObj
>(GetModel())->AfterXMLLoading();
1810 void ScXMLImport::DisposingModel()
1812 SvXMLImport::DisposingModel();
1816 ScXMLImport::MutexGuard::MutexGuard(ScXMLImport
& rImport
) :
1819 mrImport
.LockSolarMutex();
1822 ScXMLImport::MutexGuard::~MutexGuard()
1824 mrImport
.UnlockSolarMutex();
1827 void ScXMLImport::LockSolarMutex()
1829 // #i62677# When called from DocShell/Wrapper, the SolarMutex is already locked,
1830 // so there's no need to allocate (and later delete) the SolarMutexGuard.
1831 if (!mbLockSolarMutex
)
1833 DBG_TESTSOLARMUTEX();
1837 if (nSolarMutexLocked
== 0)
1839 OSL_ENSURE(!pSolarMutexGuard
, "Solar Mutex is locked");
1840 pSolarMutexGuard
.reset(new SolarMutexGuard());
1842 ++nSolarMutexLocked
;
1845 void ScXMLImport::UnlockSolarMutex()
1847 if (nSolarMutexLocked
> 0)
1849 nSolarMutexLocked
--;
1850 if (nSolarMutexLocked
== 0)
1852 OSL_ENSURE(pSolarMutexGuard
, "Solar Mutex is always unlocked");
1853 pSolarMutexGuard
.reset();
1858 sal_Int32
ScXMLImport::GetByteOffset() const
1860 sal_Int32 nOffset
= -1;
1861 uno::Reference
<xml::sax::XLocator
> xLocator
= GetLocator();
1862 uno::Reference
<io::XSeekable
> xSeek( xLocator
, uno::UNO_QUERY
); //! should use different interface
1864 nOffset
= static_cast<sal_Int32
>(xSeek
->getPosition());
1868 void ScXMLImport::SetRangeOverflowType(ErrCode nType
)
1870 // #i31130# Overflow is stored in the document, because the ScXMLImport object
1871 // isn't available in ScXMLImportWrapper::ImportFromComponent when using the
1872 // OOo->Oasis transformation.
1875 pDoc
->SetRangeOverflowType( nType
);
1878 void ScXMLImport::ProgressBarIncrement()
1881 if (nProgressCount
> 100)
1883 GetProgressBarHelper()->Increment(nProgressCount
);
1888 void ScXMLImport::ExtractFormulaNamespaceGrammar(
1889 OUString
& rFormula
, OUString
& rFormulaNmsp
, FormulaGrammar::Grammar
& reGrammar
,
1890 const OUString
& rAttrValue
, bool bRestrictToExternalNmsp
) const
1892 // parse the attribute value, extract namespace ID, literal namespace, and formula string
1893 rFormulaNmsp
.clear();
1894 sal_uInt16 nNsId
= GetNamespaceMap().GetKeyByAttrName_( rAttrValue
, nullptr, &rFormula
, &rFormulaNmsp
, false );
1896 // check if we have an ODF formula namespace
1897 if( !bRestrictToExternalNmsp
) switch( nNsId
)
1899 case XML_NAMESPACE_OOOC
:
1900 rFormulaNmsp
.clear(); // remove namespace string for built-in grammar
1901 reGrammar
= FormulaGrammar::GRAM_PODF
;
1903 case XML_NAMESPACE_OF
:
1904 rFormulaNmsp
.clear(); // remove namespace string for built-in grammar
1905 reGrammar
= FormulaGrammar::GRAM_ODFF
;
1909 /* Find default grammar for formulas without namespace. There may be
1910 documents in the wild that stored no namespace in ODF 1.0/1.1. Use
1911 GRAM_PODF then (old style ODF 1.0/1.1 formulas). The default for ODF
1912 1.2 and later without namespace is GRAM_ODFF (OpenFormula). */
1913 FormulaGrammar::Grammar eDefaultGrammar
=
1914 (GetDocument()->GetStorageGrammar() == FormulaGrammar::GRAM_PODF
) ?
1915 FormulaGrammar::GRAM_PODF
: FormulaGrammar::GRAM_ODFF
;
1917 /* Check if we have no namespace at all. The value XML_NAMESPACE_NONE
1918 indicates that there is no colon. If the first character of the
1919 attribute value is the equality sign, the value XML_NAMESPACE_UNKNOWN
1920 indicates that there is a colon somewhere in the formula string. */
1921 if( (nNsId
== XML_NAMESPACE_NONE
) || ((nNsId
== XML_NAMESPACE_UNKNOWN
) && (rAttrValue
.toChar() == '=')) )
1923 rFormula
= rAttrValue
; // return entire string as formula
1924 reGrammar
= eDefaultGrammar
;
1928 /* Check if a namespace URL could be resolved from the attribute value.
1929 Use that namespace only, if the Calc document knows an associated
1930 external formula parser. This prevents that the range operator in
1931 conjunction with defined names is confused as namespaces prefix, e.g.
1932 in the expression 'table:A1' where 'table' is a named reference. */
1933 if( ((nNsId
& XML_NAMESPACE_UNKNOWN_FLAG
) != 0) && !rFormulaNmsp
.isEmpty() &&
1934 GetDocument()->GetFormulaParserPool().hasFormulaParser( rFormulaNmsp
) )
1936 reGrammar
= FormulaGrammar::GRAM_EXTERNAL
;
1940 /* All attempts failed (e.g. no namespace and no leading equality sign, or
1941 an invalid namespace prefix), continue with the entire attribute value. */
1942 rFormula
= rAttrValue
;
1943 rFormulaNmsp
.clear(); // remove any namespace string
1944 reGrammar
= eDefaultGrammar
;
1947 FormulaError
ScXMLImport::GetFormulaErrorConstant( const OUString
& rStr
) const
1950 return FormulaError::NONE
;
1952 return mpComp
->GetErrorConstant(rStr
);
1955 ScEditEngineDefaulter
* ScXMLImport::GetEditEngine()
1959 mpEditEngine
.reset(new ScEditEngineDefaulter(pDoc
->GetEnginePool()));
1960 mpEditEngine
->SetRefMapMode(MapMode(MapUnit::Map100thMM
));
1961 mpEditEngine
->SetEditTextObjectPool(pDoc
->GetEditPool());
1962 mpEditEngine
->SetUpdateMode(false);
1963 mpEditEngine
->EnableUndo(false);
1964 mpEditEngine
->SetControlWord(mpEditEngine
->GetControlWord() & ~EEControlBits::ALLOWBIGOBJS
);
1966 return mpEditEngine
.get();
1969 const ScXMLEditAttributeMap
& ScXMLImport::GetEditAttributeMap() const
1972 mpEditAttrMap
.reset(new ScXMLEditAttributeMap
);
1973 return *mpEditAttrMap
;
1976 void ScXMLImport::NotifyEmbeddedFontRead()
1979 pDoc
->SetEmbedFonts(true);
1982 ScMyImpDetectiveOpArray
* ScXMLImport::GetDetectiveOpArray()
1984 if (!pDetectiveOpArray
)
1985 pDetectiveOpArray
.reset(new ScMyImpDetectiveOpArray());
1986 return pDetectiveOpArray
.get();
1989 extern "C" SAL_DLLPUBLIC_EXPORT
bool TestImportFODS(SvStream
&rStream
)
1993 SfxObjectShellLock
xDocSh(new ScDocShell
);
1994 xDocSh
->DoInitNew();
1995 uno::Reference
<frame::XModel
> xModel(xDocSh
->GetModel());
1997 uno::Reference
<lang::XMultiServiceFactory
> xMultiServiceFactory(comphelper::getProcessServiceFactory());
1998 uno::Reference
<io::XInputStream
> xStream(new ::utl::OSeekableInputStreamWrapper(rStream
));
1999 uno::Reference
<uno::XInterface
> xInterface(xMultiServiceFactory
->createInstance("com.sun.star.comp.Writer.XmlFilterAdaptor"), uno::UNO_SET_THROW
);
2001 css::uno::Sequence
<OUString
> aUserData(7);
2002 aUserData
[0] = "com.sun.star.comp.filter.OdfFlatXml";
2003 aUserData
[2] = "com.sun.star.comp.Calc.XMLOasisImporter";
2004 aUserData
[3] = "com.sun.star.comp.Calc.XMLOasisExporter";
2005 aUserData
[6] = "true";
2006 uno::Sequence
<beans::PropertyValue
> aAdaptorArgs(comphelper::InitPropertySequence(
2008 { "UserData", uno::Any(aUserData
) },
2010 css::uno::Sequence
<uno::Any
> aOuterArgs(1);
2011 aOuterArgs
[0] <<= aAdaptorArgs
;
2013 uno::Reference
<lang::XInitialization
> xInit(xInterface
, uno::UNO_QUERY_THROW
);
2014 xInit
->initialize(aOuterArgs
);
2016 uno::Reference
<document::XImporter
> xImporter(xInterface
, uno::UNO_QUERY_THROW
);
2017 uno::Sequence
<beans::PropertyValue
> aArgs(comphelper::InitPropertySequence(
2019 { "InputStream", uno::Any(xStream
) },
2020 { "URL", uno::Any(OUString("private:stream")) },
2022 xImporter
->setTargetDocument(xModel
);
2024 uno::Reference
<document::XFilter
> xFilter(xInterface
, uno::UNO_QUERY_THROW
);
2025 //SetLoading hack because the document properties will be re-initted
2026 //by the xml filter and during the init, while it's considered uninitialized,
2027 //setting a property will inform the document it's modified, which attempts
2028 //to update the properties, which throws cause the properties are uninitialized
2029 xDocSh
->SetLoading(SfxLoadedFlags::NONE
);
2030 bool ret
= xFilter
->filter(aArgs
);
2031 xDocSh
->SetLoading(SfxLoadedFlags::ALL
);
2038 extern "C" SAL_DLLPUBLIC_EXPORT
bool TestImportXLSX(SvStream
&rStream
)
2042 SfxObjectShellLock
xDocSh(new ScDocShell
);
2043 xDocSh
->DoInitNew();
2044 uno::Reference
<frame::XModel
> xModel(xDocSh
->GetModel());
2046 uno::Reference
<lang::XMultiServiceFactory
> xMultiServiceFactory(comphelper::getProcessServiceFactory());
2047 uno::Reference
<io::XInputStream
> xStream(new utl::OSeekableInputStreamWrapper(rStream
));
2049 uno::Reference
<document::XFilter
> xFilter(xMultiServiceFactory
->createInstance("com.sun.star.comp.oox.xls.ExcelFilter"), uno::UNO_QUERY_THROW
);
2051 uno::Reference
<document::XImporter
> xImporter(xFilter
, uno::UNO_QUERY_THROW
);
2052 uno::Sequence
<beans::PropertyValue
> aArgs(comphelper::InitPropertySequence(
2054 { "InputStream", uno::makeAny(xStream
) },
2055 { "InputMode", uno::makeAny(true) },
2057 xImporter
->setTargetDocument(xModel
);
2059 //SetLoading hack because the document properties will be re-initted
2060 //by the xml filter and during the init, while it's considered uninitialized,
2061 //setting a property will inform the document it's modified, which attempts
2062 //to update the properties, which throws cause the properties are uninitialized
2063 xDocSh
->SetLoading(SfxLoadedFlags::NONE
);
2067 ret
= xFilter
->filter(aArgs
);
2069 catch (const css::io::IOException
&)
2072 catch (const css::lang::WrappedTargetRuntimeException
&)
2075 xDocSh
->SetLoading(SfxLoadedFlags::ALL
);
2082 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */