30#include <oox/token/namespaces.hxx>
31#include <oox/token/tokens.hxx>
53#include <document.hxx>
70#include <osl/diagnose.h>
77#include <officecfg/Office/Calc.hxx>
86using ::oox::drawingml::ThemeFragmentHandler;
90const double PROGRESS_LENGTH_GLOBALS = 0.1;
101 switch( getCurrentElement() )
104 if( nElement == XLS_TOKEN( workbook ) )
return this;
107 case XLS_TOKEN( workbook ):
110 case XLS_TOKEN( sheets ):
111 case XLS_TOKEN( bookViews ):
112 case XLS_TOKEN( externalReferences ):
113 case XLS_TOKEN( definedNames ):
114 case XLS_TOKEN( pivotCaches ):
return this;
125 case XLS_TOKEN( sheets ):
128 case XLS_TOKEN( bookViews ):
131 case XLS_TOKEN( externalReferences ):
134 case XLS_TOKEN( definedNames ):
135 if( nElement == XLS_TOKEN( definedName ) ) {
importDefinedName( rAttribs );
return this; }
137 case XLS_TOKEN( pivotCaches ):
146 if( isCurrentElement( XLS_TOKEN( definedName ) ) &&
mxCurrName )
152 switch( getCurrentElement() )
200 static const RecordInfo spRecInfos[] =
216typedef std::pair<WorksheetGlobalsRef, FragmentHandlerRef> SheetFragmentHandler;
217typedef std::vector<SheetFragmentHandler> SheetFragmentVector;
226 WorkerThread(
const std::shared_ptr<comphelper::ThreadTaskTag> & pTag,
227 WorkbookFragment& rWorkbookHandler,
229 sal_Int32 &rSheetsLeft ) :
237 virtual void doWork()
override
242 SAL_INFO(
"sc.filter",
"start wait on solar" );
244 SAL_INFO(
"sc.filter",
"got solar" );
246 std::unique_ptr<oox::core::FastParser> xParser(
249 SAL_INFO(
"sc.filter",
"start import" );
251 SAL_INFO(
"sc.filter",
"end import, release solar" );
259class ProgressBarTimer :
private Timer
263 class ProgressWrapper :
public ISegmentProgressBar
275 virtual double getPosition()
const override {
return mfPosition; }
276 virtual void setPosition(
double fPosition )
override {
mfPosition = fPosition; }
278 virtual double getFreeLength()
const override {
return 0.0; }
290 ProgressBarTimer() :
Timer(
"sc ProgressBarTimer")
294 virtual ~ProgressBarTimer()
override
300 aSegments.push_back( std::make_shared<ProgressWrapper>( xProgress ) );
303 virtual void Invoke()
override
305 for(std::shared_ptr<ISegmentProgressBar> & pSegment :
aSegments)
306 static_cast< ProgressWrapper *
>( pSegment.get() )->UpdateBar();
310void importSheetFragments( WorkbookFragment& rWorkbookHandler, SheetFragmentVector& rSheets )
312 rWorkbookHandler.getDocImport().initForSheets();
318 sal_Int32 nSheetsLeft = 0;
319 ProgressBarTimer aProgressUpdater;
320 for(
auto& [rxSheetGlob, rxFragment] : rSheets )
324 pProgress->setCustomRowProgress(
325 aProgressUpdater.wrapProgress(
326 pProgress->getRowProgress() ) );
327 rSharedPool.
pushTask( std::make_unique<WorkerThread>( pTag, rWorkbookHandler, rxFragment,
352 OUString aThemeFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc(
u"theme" );
355 auto pTheme = rOoxTheme.oox::drawingml::Theme::getTheme();
358 pTheme = std::make_shared<model::Theme>();
359 rOoxTheme.setTheme(pTheme);
362 if( !aThemeFragmentPath.isEmpty() )
363 importOoxFragment(
new ThemeFragmentHandler(getFilter(), aThemeFragmentPath, rOoxTheme, *pTheme));
364 xGlobalSegment->setPosition( 0.25 );
367 OUString aStylesFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc(
u"styles" );
368 if( !aStylesFragmentPath.isEmpty() )
370 xGlobalSegment->setPosition( 0.5 );
373 OUString aSstFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc(
u"sharedStrings" );
374 if( !aSstFragmentPath.isEmpty() )
377 xGlobalSegment->setPosition( 0.75 );
380 OUString aConnFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc(
u"connections" );
381 if( !aConnFragmentPath.isEmpty() )
383 xGlobalSegment->setPosition( 1.0 );
390 SheetFragmentVector aSheetFragments;
391 std::vector<WorksheetHelper*> aHelpers;
394 for( sal_Int32 nWorksheet = 0; nWorksheet < nWorksheetCount; ++nWorksheet )
398 if( (nCalcSheet >= 0) && pRelation )
401 OUString aFragmentPath = getFragmentPathFromRelation( *pRelation );
402 OSL_ENSURE( !aFragmentPath.isEmpty(),
"WorkbookFragment::finalizeImport - cannot access sheet fragment" );
403 if( !aFragmentPath.isEmpty() )
424 OSL_ENSURE( eSheetType !=
WorksheetType::Empty,
"WorkbookFragment::finalizeImport - unknown sheet type" );
429 OSL_ENSURE( xSheetGlob,
"WorkbookFragment::finalizeImport - missing sheet in document" );
452 aSheetFragments.emplace_back( xSheetGlob, xFragment.get() );
453 aHelpers.push_back(xFragment.get());
470 if( !aVbaFragmentPath.isEmpty() )
484 bool bWasLocked = pModel->
isLocked();
485 pModel->setLock(
true);
488 importSheetFragments(*
this, aSheetFragments);
490 SdrPage* pPage = pModel->GetPage(0);
491 if (pPage && pTheme && !pTheme->GetName().isEmpty())
512 pHelper->finalizeDrawingImport();
515 for(
auto& [rxSheetGlob, rxFragment] : aSheetFragments )
528 if (!aRevHeadersPath.isEmpty())
538 pModel->setLock(bWasLocked);
553 MessageWithCheck(
weld::Window *pParent,
const OUString& rUIFile,
const OUString& rDialogId)
554 : MessageDialogController(pParent, rUIFile, rDialogId,
"ask")
570 static_cast<ScRecalcOptions>(officecfg::Office::Calc::Formula::Load::OOXMLRecalcMode::get());
571 bool bHardRecalc =
false;
578 aQueryBox.set_primary_text(
ScResId(STR_QUERY_FORMULA_RECALC_ONLOAD_XLS));
579 aQueryBox.set_default_response(
RET_YES);
581 if ( officecfg::Office::Calc::Formula::Load::OOXMLRecalcMode::isReadOnly() )
582 aQueryBox.hide_ask();
584 bHardRecalc = aQueryBox.run() ==
RET_YES;
586 if (aQueryBox.get_active())
590 officecfg::Office::Calc::Formula::Load::OOXMLRecalcMode::set(sal_Int32(0), batch);
595 SC_MOD()->SetFormulaOptions(aOpt);
637 sal_Int32 nCacheId = rAttribs.
getInteger( XML_cacheId, -1 );
638 OUString aRelId = rAttribs.
getString( R_TOKEN(
id ), OUString() );
650 sal_Int32 nCacheId =
rStrm.readInt32();
657 OUString aFragmentPath = getFragmentPathFromRelId( rExtLink.
getRelId() );
658 if( !aFragmentPath.isEmpty() )
static weld::Window * GetActiveDialogParent()
void broadcastRecalcAfterImport()
Broadcast all formula cells that are marked with FormulaTokenArray::IsRecalcModeMustAfterImport() for...
SC_DLLPUBLIC void InitDrawLayer(SfxObjectShell *pDocShell=nullptr)
SC_DLLPUBLIC bool IsUserInteractionEnabled() const
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
SfxObjectShell * GetDocumentShell() const
void SetInsertingFromOtherDoc(bool bVal)
void SetTheme(std::shared_ptr< model::Theme > const &pTheme)
SdrPageProperties & getSdrPageProperties()
static std::shared_ptr< ConfigurationChanges > create()
static ThreadPool & getSharedOptimalPool()
void waitUntilDone(const std::shared_ptr< ThreadTaskTag > &, bool bJoin=true)
static std::shared_ptr< ThreadTaskTag > createThreadTaskTag()
void pushTask(std::unique_ptr< ThreadTask > pTask)
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
std::optional< OUString > getString(sal_Int32 nAttrToken) const
virtual ISegmentProgressBarRef createSegment(double fLength) override
virtual double getFreeLength() const override
::oox::ole::VbaProject & getVbaProject() const
css::uno::Reference< css::io::XInputStream > openInputStream(const OUString &rStreamName) const
static FastParser * createParser()
void readVbaModules(StorageBase &rVbaPrjStrg)
static OUString readString(SequenceInputStream &rStrm, bool b32BitLen=true)
Reads a BIFF12 string with leading 16-bit or 32-bit length field.
DefinedNameRef importDefinedName(const AttributeList &rAttribs)
Imports a defined name from the passed attribute set.
void finalizeImport()
Creates all defined names in the document.
void importExternalAddin(SequenceInputStream &rStrm)
Imports the EXTERNALADDIN record from the passed stream.
void importExternalSelf(SequenceInputStream &rStrm)
Imports the EXTERNALSELF record from the passed stream.
void importExternalSheets(SequenceInputStream &rStrm)
Imports the EXTERNALSHEETS record from the passed stream.
void importExternalSame(SequenceInputStream &rStrm)
Imports the EXTERNALSAME record from the passed stream.
const OUString & getRelId() const
Returns the relation identifier for the external link fragment.
void registerPivotCacheFragment(sal_Int32 nCacheId, const OUString &rFragmentPath)
Registers a pivot cache definition fragment.
void applyTableColumns()
Applies columns names from created database range ( requires finalizeImport to have run before being ...
void applyAutoFilters()
Applies autofilters from created database range ( requires finalizeImport to have run before being ca...
void finalizeImport()
Creates database ranges from all imported tables.
void importOleSize(const AttributeList &rAttribs)
Imports the oleSize element containing the visible size of the workbook.
void importWorkbookView(const AttributeList &rAttribs)
Imports the workbookView element containing workbook view settings.
sal_Int16 getActiveCalcSheet() const
Returns the Calc index of the active sheet.
Fragment handler derived from the WorkbookHelper helper class.
DefinedNameRef mxCurrName
void importDefinedName(const AttributeList &rAttribs)
void importPivotCache(const AttributeList &rAttribs)
virtual ::oox::core::ContextHandlerRef onCreateRecordContext(sal_Int32 nRecId, SequenceInputStream &rStrm) override
virtual void onCharacters(const OUString &rChars) override
void importExternalReference(const AttributeList &rAttribs)
virtual void finalizeImport() override
void importExternalRef(SequenceInputStream &rStrm)
virtual const ::oox::core::RecordInfo * getRecordInfos() const override
void importPivotCacheDefFragment(const OUString &rRelId, sal_Int32 nCacheId)
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
void importExternalLinkFragment(ExternalLink &rExtLink)
WorkbookFragment(const WorkbookHelper &rHelper, const OUString &rFragmentPath)
void recalcFormulaCells()
Helper class to provide access to global workbook data.
bool hasCalculatedFormulaCells() const
Returns true if any formula cell is calculated.
bool importOoxFragment(const rtl::Reference< oox::core::FragmentHandler > &rxHandler)
Imports a fragment using the passed fragment handler, which contains the full path to the fragment st...
WorksheetBuffer & getWorksheets() const
Returns the worksheet buffer containing sheet names and properties.
PivotCacheBuffer & getPivotCaches() const
Returns the collection of pivot caches.
WorkbookSettings & getWorkbookSettings() const
Returns the global workbook settings object.
FormulaBuffer & getFormulaBuffer() const
ScDocument & getScDocument()
DefinedNamesBuffer & getDefinedNames() const
Returns the defined names read from the workbook globals.
ViewSettings & getViewSettings() const
Returns the workbook and sheet view settings object.
ScDocumentImport & getDocImport()
ThemeBuffer & getTheme() const
Returns the office theme object read from the theme substorage.
void setVbaProjectStorage(const StorageRef &rxVbaPrjStrg)
Sets the VBA project storage used to import VBA source code and forms.
::oox::core::FilterBase & getBaseFilter() const
Returns the base filter object (base class of all filters).
void finalizeWorkbookImport()
Final conversion after importing the workbook.
TableBuffer & getTables() const
Returns the tables collection (equivalent to Calc's database ranges).
SegmentProgressBar & getProgressBar() const
Returns the filter progress bar.
ExternalLinkBuffer & getExternalLinks() const
Returns the external links read from the external links substream.
void importCalcPr(const AttributeList &rAttribs)
Imports the calcPr element containing workbook calculation settings.
void importFileSharing(const AttributeList &rAttribs)
Imports the fileSharing element containing write protection settings.
void importWorkbookPr(const AttributeList &rAttribs)
Imports the workbookPr element containing global workbook settings.
Stores information about all sheets in a spreadsheet document.
OUString getWorksheetRelId(sal_Int32 nWorksheet) const
Returns the OOXML relation identifier of the specified worksheet.
sal_Int32 getWorksheetCount() const
Returns the number of original sheets contained in the workbook.
sal_Int16 getCalcSheetIndex(sal_Int32 nWorksheet) const
Returns the Calc index of the specified worksheet.
void importSheet(const AttributeList &rAttribs)
Imports the attributes of a sheet element.
void finalizeImport(sal_Int16 nActiveSheet)
static WorksheetGlobalsRef constructGlobals(const WorkbookHelper &rHelper, const ISegmentProgressBarRef &rxProgressBar, WorksheetType eSheetType, SCTAB nSheet)
static IWorksheetProgress * getWorksheetInterface(const WorksheetGlobalsRef &xRef)
#define SAL_INFO(area, stream)
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
ScDocShell * getDocShell(const css::uno::Reference< css::frame::XModel > &xModel)
const sal_Int32 XML_ROOT_CONTEXT
const sal_Int32 BIFF12_ID_EXTERNALADDIN
const sal_Int32 BIFF12_ID_FUNCTIONGROUPS
const sal_Int32 BIFF12_ID_SHEET
const sal_Int32 BIFF12_ID_EXTERNALSAME
const sal_Int32 BIFF12_ID_WORKBOOKPR
const sal_Int32 BIFF12_ID_WORKBOOK
const sal_Int32 BIFF12_ID_WORKBOOKVIEW
const sal_Int32 BIFF12_ID_EXTERNALREF
const sal_Int32 BIFF12_ID_SHEETS
const sal_Int32 BIFF12_ID_OLESIZE
const sal_Int32 BIFF12_ID_PIVOTCACHE
const sal_Int32 BIFF12_ID_PIVOTCACHES
const sal_Int32 BIFF12_ID_FILESHARING
const sal_Int32 BIFF12_ID_DEFINEDNAME
const sal_Int32 BIFF12_ID_CALCPR
const sal_Int32 BIFF12_ID_EXTERNALSHEETS
const sal_Int32 BIFF12_ID_EXTERNALREFS
std::shared_ptr< WorksheetGlobals > WorksheetGlobalsRef
const sal_Int32 BIFF12_ID_EXTERNALSELF
WorksheetType
An enumeration for all types of sheets in a workbook.
@ Empty
Dialog sheet (BIFF5+).
const sal_Int32 BIFF12_ID_BOOKVIEWS
std::shared_ptr< StorageBase > StorageRef
std::shared_ptr< ISegmentProgressBar > ISegmentProgressBarRef
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
#define CREATE_OFFICEDOC_RELATION_TYPE(ascii)
#define CREATE_OFFICEDOC_RELATION_TYPE_STRICT(ascii)
#define CREATE_MSOFFICE_RELATION_TYPE(ascii)
OUString ScResId(TranslateId aId)
WorkbookFragment & mrWorkbookHandler
std::unique_ptr< weld::CheckButton > m_xWarningOnBox
std::vector< ISegmentProgressBarRef > aSegments
rtl::Reference< FragmentHandler > mxHandler
ISegmentProgressBarRef mxWrapped