29 #include <oox/token/namespaces.hxx>
30 #include <oox/token/tokens.hxx>
52 #include <document.hxx>
56 #include <globstr.hrc>
68 #include <osl/diagnose.h>
75 #include <officecfg/Office/Calc.hxx>
84 using ::oox::drawingml::ThemeFragmentHandler;
88 const double PROGRESS_LENGTH_GLOBALS = 0.1;
102 if( nElement == XLS_TOKEN( workbook ) )
return this;
105 case XLS_TOKEN( workbook ):
108 case XLS_TOKEN( sheets ):
109 case XLS_TOKEN( bookViews ):
110 case XLS_TOKEN( externalReferences ):
111 case XLS_TOKEN( definedNames ):
112 case XLS_TOKEN( pivotCaches ):
return this;
123 case XLS_TOKEN( sheets ):
126 case XLS_TOKEN( bookViews ):
129 case XLS_TOKEN( externalReferences ):
132 case XLS_TOKEN( definedNames ):
133 if( nElement == XLS_TOKEN( definedName ) ) {
importDefinedName( rAttribs );
return this; }
135 case XLS_TOKEN( pivotCaches ):
198 static const RecordInfo spRecInfos[] =
214 typedef std::pair<WorksheetGlobalsRef, FragmentHandlerRef> SheetFragmentHandler;
215 typedef std::vector<SheetFragmentHandler> SheetFragmentVector;
224 WorkerThread(
const std::shared_ptr<comphelper::ThreadTaskTag> & pTag,
225 WorkbookFragment& rWorkbookHandler,
227 sal_Int32 &rSheetsLeft ) :
229 mrSheetsLeft( rSheetsLeft ),
230 mrWorkbookHandler( rWorkbookHandler ),
231 mxHandler( xHandler )
235 virtual void doWork()
override
240 SAL_INFO(
"sc.filter",
"start wait on solar" );
242 SAL_INFO(
"sc.filter",
"got solar" );
244 std::unique_ptr<oox::core::FastParser> xParser(
247 SAL_INFO(
"sc.filter",
"start import" );
248 mrWorkbookHandler.importOoxFragment( mxHandler, *xParser );
249 SAL_INFO(
"sc.filter",
"end import, release solar" );
251 assert( mrSheetsLeft >= 0 );
252 if( mrSheetsLeft == 0 )
257 class ProgressBarTimer :
private Timer
261 class ProgressWrapper :
public ISegmentProgressBar
273 virtual double getPosition()
const override {
return mfPosition; }
274 virtual void setPosition(
double fPosition )
override { mfPosition = fPosition; }
276 virtual double getFreeLength()
const override {
return 0.0; }
283 mxWrapped->setPosition( mfPosition );
288 ProgressBarTimer() :
Timer(
"sc ProgressBarTimer")
292 virtual ~ProgressBarTimer()
override
298 aSegments.push_back( std::make_shared<ProgressWrapper>( xProgress ) );
299 return aSegments.back();
301 virtual void Invoke()
override
303 for(std::shared_ptr<ISegmentProgressBar> & pSegment : aSegments)
304 static_cast< ProgressWrapper *
>( pSegment.get() )->UpdateBar();
308 void importSheetFragments( WorkbookFragment& rWorkbookHandler, SheetFragmentVector& rSheets )
310 rWorkbookHandler.getDocImport().initForSheets();
316 sal_Int32 nSheetsLeft = 0;
317 ProgressBarTimer aProgressUpdater;
318 for(
auto& [rxSheetGlob, rxFragment] : rSheets )
322 pProgress->setCustomRowProgress(
323 aProgressUpdater.wrapProgress(
324 pProgress->getRowProgress() ) );
325 rSharedPool.
pushTask( std::make_unique<WorkerThread>( pTag, rWorkbookHandler, rxFragment,
350 OUString aThemeFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc(
u"theme" );
351 if( !aThemeFragmentPath.isEmpty() )
353 xGlobalSegment->setPosition( 0.25 );
356 OUString aStylesFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc(
u"styles" );
357 if( !aStylesFragmentPath.isEmpty() )
359 xGlobalSegment->setPosition( 0.5 );
362 OUString aSstFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc(
u"sharedStrings" );
363 if( !aSstFragmentPath.isEmpty() )
366 xGlobalSegment->setPosition( 0.75 );
369 OUString aConnFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc(
u"connections" );
370 if( !aConnFragmentPath.isEmpty() )
372 xGlobalSegment->setPosition( 1.0 );
379 SheetFragmentVector aSheetFragments;
380 std::vector<WorksheetHelper*> aHelpers;
383 for( sal_Int32 nWorksheet = 0; nWorksheet < nWorksheetCount; ++nWorksheet )
387 if( (nCalcSheet >= 0) && pRelation )
390 OUString aFragmentPath = getFragmentPathFromRelation( *pRelation );
391 OSL_ENSURE( !aFragmentPath.isEmpty(),
"WorkbookFragment::finalizeImport - cannot access sheet fragment" );
392 if( !aFragmentPath.isEmpty() )
413 OSL_ENSURE( eSheetType !=
WorksheetType::Empty,
"WorkbookFragment::finalizeImport - unknown sheet type" );
418 OSL_ENSURE( xSheetGlob,
"WorkbookFragment::finalizeImport - missing sheet in document" );
441 aSheetFragments.emplace_back( xSheetGlob, xFragment.get() );
442 aHelpers.push_back(xFragment.get());
459 if( !aVbaFragmentPath.isEmpty() )
473 bool bWasLocked = pModel->
isLocked();
474 pModel->setLock(
true);
477 importSheetFragments(*
this, aSheetFragments);
491 pHelper->finalizeDrawingImport();
494 for(
auto& [rxSheetGlob, rxFragment] : aSheetFragments )
506 if (!aRevHeadersPath.isEmpty())
516 pModel->setLock(bWasLocked);
531 MessageWithCheck(
weld::Window *pParent,
const OUString& rUIFile,
const OString& rDialogId)
532 : MessageDialogController(pParent, rUIFile, rDialogId,
"ask")
533 , m_xWarningOnBox(m_xBuilder->weld_check_button(
"ask"))
536 bool get_active()
const {
return m_xWarningOnBox->get_active(); }
537 void hide_ask()
const { m_xWarningOnBox->set_visible(
false); };
548 static_cast<ScRecalcOptions>(officecfg::Office::Calc::Formula::Load::OOXMLRecalcMode::get());
549 bool bHardRecalc =
false;
556 aQueryBox.set_primary_text(
ScResId(STR_QUERY_FORMULA_RECALC_ONLOAD_XLS));
557 aQueryBox.set_default_response(
RET_YES);
559 if ( officecfg::Office::Calc::Formula::Load::OOXMLRecalcMode::isReadOnly() )
560 aQueryBox.hide_ask();
562 bHardRecalc = aQueryBox.run() ==
RET_YES;
564 if (aQueryBox.get_active())
568 officecfg::Office::Calc::Formula::Load::OOXMLRecalcMode::set(sal_Int32(0), batch);
573 SC_MOD()->SetFormulaOptions(aOpt);
608 sal_Int32 nCacheId = rAttribs.
getInteger( XML_cacheId, -1 );
609 OUString aRelId = rAttribs.
getString( R_TOKEN(
id ), OUString() );
628 OUString aFragmentPath = getFragmentPathFromRelId( rExtLink.
getRelId() );
629 if( !aFragmentPath.isEmpty() )
Helper class to provide access to global workbook data.
DefinedNameRef importDefinedName(const AttributeList &rAttribs)
Imports a defined name from the passed attribute set.
static WorksheetGlobalsRef constructGlobals(const WorkbookHelper &rHelper, const ISegmentProgressBarRef &rxProgressBar, WorksheetType eSheetType, SCTAB nSheet)
const sal_Int32 BIFF12_ID_SHEETS
void readVbaModules(StorageBase &rVbaPrjStrg)
ScDocumentImport & getDocImport()
void importExternalSelf(SequenceInputStream &rStrm)
Imports the EXTERNALSELF record from the passed stream.
OUString ScResId(TranslateId aId)
Stores information about all sheets in a spreadsheet document.
static std::shared_ptr< ConfigurationChanges > create()
DefinedNameRef mxCurrName
const sal_Int32 BIFF12_ID_EXTERNALREFS
static weld::Window * GetActiveDialogParent()
void importWorkbookPr(const AttributeList &rAttribs)
Imports the workbookPr element containing global workbook settings.
const sal_Int32 BIFF12_ID_FILESHARING
OptValue< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
bool isCurrentElement(sal_Int32 nElement) const
SC_DLLPUBLIC bool IsUserInteractionEnabled() const
void finalizeImport()
Creates all defined names in the document.
#define CREATE_OFFICEDOC_RELATION_TYPE(ascii)
const sal_Int32 BIFF12_ID_BOOKVIEWS
const sal_Int32 BIFF12_ID_WORKBOOKVIEW
void importCalcPr(const AttributeList &rAttribs)
Imports the calcPr element containing workbook calculation settings.
const sal_Int32 BIFF12_ID_WORKBOOK
virtual void onCharacters(const OUString &rChars) override
OptValue< OUString > getString(sal_Int32 nAttrToken) const
std::shared_ptr< StorageBase > StorageRef
void registerPivotCacheFragment(sal_Int32 nCacheId, const OUString &rFragmentPath)
Registers a pivot cache definition fragment.
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
void waitUntilDone(const std::shared_ptr< ThreadTaskTag > &, bool bJoin=true)
OUString getWorksheetRelId(sal_Int32 nWorksheet) const
Returns the OOXML relation identifier of the specified worksheet.
WorkbookSettings & getWorkbookSettings() const
Returns the global workbook settings object.
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...
void importPivotCacheDefFragment(const OUString &rRelId, sal_Int32 nCacheId)
exports com.sun.star. sheet
void broadcastRecalcAfterImport()
Broadcast all formula cells that are marked with FormulaTokenArray::IsRecalcModeMustAfterImport() for...
WorkbookFragment & mrWorkbookHandler
ViewSettings & getViewSettings() const
Returns the workbook and sheet view settings object.
Fragment handler derived from the WorkbookHelper helper class.
virtual void finalizeImport() override
std::shared_ptr< WorksheetGlobals > WorksheetGlobalsRef
::oox::core::FilterBase & getBaseFilter() const
Returns the base filter object (base class of all filters).
PivotCacheBuffer & getPivotCaches() const
Returns the collection of pivot caches.
sal_Int16 getActiveCalcSheet() const
Returns the Calc index of the active sheet.
static IWorksheetProgress * getWorksheetInterface(const WorksheetGlobalsRef &xRef)
void SetInsertingFromOtherDoc(bool bVal)
static ThreadPool & getSharedOptimalPool()
virtual double getFreeLength() const override
const sal_Int32 BIFF12_ID_PIVOTCACHES
const sal_Int32 BIFF12_ID_FUNCTIONGROUPS
::oox::ole::VbaProject & getVbaProject() const
void finalizeWorkbookImport()
Final conversion after importing the workbook.
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
ScDocShell * getDocShell(const css::uno::Reference< css::frame::XModel > &xModel)
SC_DLLPUBLIC void InitDrawLayer(SfxObjectShell *pDocShell=nullptr)
const sal_Int32 BIFF12_ID_EXTERNALSELF
#define CREATE_OFFICEDOC_RELATION_TYPE_STRICT(ascii)
void importExternalAddin(SequenceInputStream &rStrm)
Imports the EXTERNALADDIN record from the passed stream.
void importExternalReference(const AttributeList &rAttribs)
void pushTask(std::unique_ptr< ThreadTask > pTask)
void finalizeImport()
Creates database ranges from all imported tables.
ExternalLinkBuffer & getExternalLinks() const
Returns the external links read from the external links substream.
std::shared_ptr< ISegmentProgressBar > ISegmentProgressBarRef
static OUString readString(SequenceInputStream &rStrm, bool b32BitLen=true)
Reads a BIFF12 string with leading 16-bit or 32-bit length field.
#define CREATE_MSOFFICE_RELATION_TYPE(ascii)
ScDocument & getScDocument()
sal_Int32 getCurrentElement() const
const sal_Int32 BIFF12_ID_OLESIZE
SegmentProgressBar & getProgressBar() const
Returns the filter progress bar.
virtual ISegmentProgressBarRef createSegment(double fLength) override
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext() const
std::unique_ptr< weld::CheckButton > m_xWarningOnBox
void applyTableColumns()
Applies columns names from created database range ( requires finalizeImport to have run before being ...
const sal_Int32 BIFF12_ID_PIVOTCACHE
const sal_Int32 BIFF12_ID_EXTERNALSHEETS
const sal_Int32 BIFF12_ID_EXTERNALREF
const sal_Int32 BIFF12_ID_SHEET
const sal_Int32 BIFF12_ID_EXTERNALSAME
sal_Int32 getWorksheetCount() const
Returns the number of original sheets contained in the workbook.
std::vector< ISegmentProgressBarRef > aSegments
const OUString & getRelId() const
Returns the relation identifier for the external link fragment.
rtl::Reference< FragmentHandler > mxHandler
sal_Int16 getCalcSheetIndex(sal_Int32 nWorksheet) const
Returns the Calc index of the specified worksheet.
void importExternalLinkFragment(ExternalLink &rExtLink)
void importExternalRef(SequenceInputStream &rStrm)
void recalcFormulaCells()
virtual ::oox::core::ContextHandlerRef onCreateRecordContext(sal_Int32 nRecId, SequenceInputStream &rStrm) override
void importExternalSame(SequenceInputStream &rStrm)
Imports the EXTERNALSAME record from the passed stream.
#define SAL_INFO(area, stream)
css::uno::Reference< css::io::XInputStream > openInputStream(const OUString &rStreamName) const
void importWorkbookView(const AttributeList &rAttribs)
Imports the workbookView element containing workbook view settings.
ISegmentProgressBarRef mxWrapped
void importDefinedName(const AttributeList &rAttribs)
void importFileSharing(const AttributeList &rAttribs)
Imports the fileSharing element containing write protection settings.
static std::shared_ptr< ThreadTaskTag > createThreadTaskTag()
void importExternalSheets(SequenceInputStream &rStrm)
Imports the EXTERNALSHEETS record from the passed stream.
void importSheet(const AttributeList &rAttribs)
Imports the attributes of a sheet element.
const sal_Int32 BIFF12_ID_WORKBOOKPR
TableBuffer & getTables() const
Returns the tables collection (equivalent to Calc's database ranges).
const sal_Int32 XML_ROOT_CONTEXT
const sal_Int32 BIFF12_ID_DEFINEDNAME
ThemeBuffer & getTheme() const
Returns the office theme object read from the theme substorage.
SfxObjectShell * GetDocumentShell() const
virtual const ::oox::core::RecordInfo * getRecordInfos() const override
static FastParser * createParser()
void setVbaProjectStorage(const StorageRef &rxVbaPrjStrg)
Sets the VBA project storage used to import VBA source code and forms.
WorksheetType
An enumeration for all types of sheets in a workbook.
void finalizeImport(sal_Int16 nActiveSheet)
const sal_Int32 BIFF12_ID_CALCPR
void importPivotCache(const AttributeList &rAttribs)
const sal_Int32 BIFF12_ID_EXTERNALADDIN
WorkbookFragment(const WorkbookHelper &rHelper, const OUString &rFragmentPath)
DefinedNamesBuffer & getDefinedNames() const
Returns the defined names read from the workbook globals.
FormulaBuffer & getFormulaBuffer() const
bool m_bDetectedRangeSegmentation false
void importOleSize(const AttributeList &rAttribs)
Imports the oleSize element containing the visible size of the workbook.
WorksheetBuffer & getWorksheets() const
Returns the worksheet buffer containing sheet names and properties.