LibreOffice Module sc (master)  1
excimp8.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <config_features.h>
21 
22 #include <excimp8.hxx>
23 
24 #include <scitems.hxx>
26 #include <comphelper/sequence.hxx>
27 #include <unotools/fltrcfg.hxx>
28 
29 #include <sfx2/docfile.hxx>
30 #include <sfx2/objsh.hxx>
31 #include <sfx2/docinf.hxx>
32 #include <sot/storage.hxx>
33 #include <svl/sharedstringpool.hxx>
34 
35 #include <rtl/math.hxx>
36 #include <rtl/ustring.hxx>
38 
39 #include <document.hxx>
40 #include <attrib.hxx>
41 #include <dbdata.hxx>
42 #include <globalnames.hxx>
43 #include <docoptio.hxx>
44 #include <xihelper.hxx>
45 #include <xicontent.hxx>
46 #include <xilink.hxx>
47 #include <xiescher.hxx>
48 #include <xistyle.hxx>
49 #include <excdefs.hxx>
50 
51 #include <excform.hxx>
52 #include <queryentry.hxx>
53 
54 #include <com/sun/star/document/XDocumentProperties.hpp>
55 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
56 #include <com/sun/star/container/XIndexContainer.hpp>
57 #include <com/sun/star/container/XNameContainer.hpp>
58 #include <com/sun/star/frame/XModel.hpp>
59 #include <cppuhelper/implbase.hxx>
60 #include "xltoolbar.hxx"
61 #include <oox/ole/vbaproject.hxx>
62 #include <oox/ole/olestorage.hxx>
63 
64 using namespace com::sun::star;
65 using namespace ::comphelper;
66 
67 //OleNameOverrideContainer
68 
69 namespace {
70 
71 class OleNameOverrideContainer : public ::cppu::WeakImplHelper< container::XNameContainer >
72 {
73 private:
74  typedef std::unordered_map< OUString, uno::Reference< container::XIndexContainer > > NamedIndexToOleName;
75  NamedIndexToOleName IdToOleNameHash;
76  ::osl::Mutex m_aMutex;
77 public:
78  // XElementAccess
79  virtual uno::Type SAL_CALL getElementType( ) override { return cppu::UnoType<container::XIndexContainer>::get(); }
80  virtual sal_Bool SAL_CALL hasElements( ) override
81  {
82  ::osl::MutexGuard aGuard( m_aMutex );
83  return ( !IdToOleNameHash.empty() );
84  }
85  // XNameAccess
86  virtual uno::Any SAL_CALL getByName( const OUString& aName ) override
87  {
88  ::osl::MutexGuard aGuard( m_aMutex );
89  if ( !hasByName(aName) )
90  throw container::NoSuchElementException();
91  return uno::makeAny( IdToOleNameHash[ aName ] );
92  }
93  virtual uno::Sequence< OUString > SAL_CALL getElementNames( ) override
94  {
95  ::osl::MutexGuard aGuard( m_aMutex );
96  return comphelper::mapKeysToSequence( IdToOleNameHash);
97  }
98  virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override
99  {
100  ::osl::MutexGuard aGuard( m_aMutex );
101  return ( IdToOleNameHash.find( aName ) != IdToOleNameHash.end() );
102  }
103 
104  // XNameContainer
105  virtual void SAL_CALL insertByName( const OUString& aName, const uno::Any& aElement ) override
106  {
107  ::osl::MutexGuard aGuard( m_aMutex );
108  if ( hasByName( aName ) )
109  throw container::ElementExistException();
110  uno::Reference< container::XIndexContainer > xElement;
111  if ( ! ( aElement >>= xElement ) )
112  throw lang::IllegalArgumentException();
113  IdToOleNameHash[ aName ] = xElement;
114  }
115  virtual void SAL_CALL removeByName( const OUString& aName ) override
116  {
117  ::osl::MutexGuard aGuard( m_aMutex );
118  if ( IdToOleNameHash.erase( aName ) == 0 )
119  throw container::NoSuchElementException();
120  }
121  virtual void SAL_CALL replaceByName( const OUString& aName, const uno::Any& aElement ) override
122  {
123  ::osl::MutexGuard aGuard( m_aMutex );
124  if ( !hasByName( aName ) )
125  throw container::NoSuchElementException();
126  uno::Reference< container::XIndexContainer > xElement;
127  if ( ! ( aElement >>= xElement ) )
128  throw lang::IllegalArgumentException();
129  IdToOleNameHash[ aName ] = xElement;
130  }
131 };
132 
136 bool readFrtHeader( XclImpStream& rStrm, sal_uInt16 nRecordID )
137 {
138  sal_uInt16 nRt = rStrm.ReaduInt16();
139  rStrm.Ignore(10); // grbitFrt (2 bytes) and reserved (8 bytes)
140  return nRt == nRecordID;
141 }
142 
143 }
144 
146  ImportExcel( rImpData, rStrm )
147 {
148  // replace BIFF2-BIFF5 formula importer with BIFF8 formula importer
149  pFormConv.reset(new ExcelToSc8( GetRoot() ));
151 }
152 
154 {
155 }
156 
158 {
159  ScDocOptions aOpt = pD->GetDocOptions();
160  aOpt.SetIterCount( aIn.ReaduInt16() );
161  pD->SetDocOptions( aOpt );
162 }
163 
165 {
166  ScDocOptions aOpt = pD->GetDocOptions();
167  aOpt.SetCalcAsShown( aIn.ReaduInt16() == 0 );
168  pD->SetDocOptions( aOpt );
169 }
170 
172 {
173  ScDocOptions aOpt = pD->GetDocOptions();
174  aOpt.SetIterEps( aIn.ReadDouble() );
175  pD->SetDocOptions( aOpt );
176 }
177 
179 {
180  ScDocOptions aOpt = pD->GetDocOptions();
181  aOpt.SetIter( aIn.ReaduInt16() == 1 );
182  pD->SetDocOptions( aOpt );
183 }
184 
186 {
187  sal_uInt8 nLen;
188  sal_uInt16 nGrbit;
189 
191  maSheetOffsets.push_back( aIn.ReaduInt32() );
193  nGrbit = aIn.ReaduInt16();
194  nLen = aIn.ReaduInt8();
195 
196  OUString aName( aIn.ReadUniString( nLen ) );
198 
199  SCTAB nScTab = nBdshtTab;
200  if( nScTab > 0 )
201  {
202  OSL_ENSURE( !pD->HasTable( nScTab ), "ImportExcel8::Boundsheet - sheet exists already" );
203  pD->MakeTable( nScTab );
204  }
205 
206  if( ( nGrbit & 0x0001 ) || ( nGrbit & 0x0002 ) )
207  pD->SetVisible( nScTab, false );
208 
209  if( !pD->RenameTab( nScTab, aName ) )
210  {
211  pD->CreateValidTabName( aName );
212  pD->RenameTab( nScTab, aName );
213  }
214 
215  nBdshtTab++;
216 }
217 
219 {
220  sal_uInt16 nLastDispl;
221 
222  aIn.Ignore( 4 );
223  nLastDispl = aIn.ReaduInt16();
224 
225  maScenList.nLastScenario = nLastDispl;
226 }
227 
229 {
230  maScenList.aEntries.push_back( std::make_unique<ExcScenario>( aIn, *pExcRoot ) );
231 }
232 
234 {
235  XclAddress aXclPos;
236  sal_uInt16 nXF;
237  sal_uInt32 nSst;
238 
239  aIn >> aXclPos;
240  nXF = aIn.ReaduInt16();
241  nSst = aIn.ReaduInt32( );
242 
244  if( GetAddressConverter().ConvertAddress( aScPos, aXclPos, GetCurrScTab(), true ) )
245  {
246  GetXFRangeBuffer().SetXF( aScPos, nXF );
247  const XclImpString* pXclStr = GetSst().GetString(nSst);
248  if (pXclStr)
249  XclImpStringHelper::SetToDocument(GetDocImport(), aScPos, *this, *pXclStr, nXF);
250  }
251 }
252 
254 {
255  if (!readFrtHeader( aIn, 0x0867))
256  return;
257 
258  // Feature type (isf) can be EXC_ISFPROTECTION, EXC_ISFFEC2 or
259  // EXC_ISFFACTOID.
260  sal_uInt16 nFeatureType = aIn.ReaduInt16();
261  if (nFeatureType != EXC_ISFPROTECTION)
262  // We currently only support import of enhanced protection data.
263  return;
264 
265  aIn.Ignore(1); // always 1
266 
268 }
269 
271 {
272  if (!readFrtHeader( aIn, 0x0868))
273  return;
274 
275  // Feature type (isf) can be EXC_ISFPROTECTION, EXC_ISFFEC2 or
276  // EXC_ISFFACTOID.
277  sal_uInt16 nFeatureType = aIn.ReaduInt16();
278  if (nFeatureType != EXC_ISFPROTECTION)
279  // We currently only support import of enhanced protection data.
280  return;
281 
282  aIn.Ignore(5); // reserved1 (1 byte) and reserved2 (4 bytes)
283 
284  sal_uInt16 nCref = aIn.ReaduInt16(); // number of ref elements
285  aIn.Ignore(4); // size if EXC_ISFFEC2, else 0 and to be ignored
286  aIn.Ignore(2); // reserved3 (2 bytes)
287 
288  ScEnhancedProtection aProt;
289  if (nCref)
290  {
291  XclRangeList aRefs;
292  aRefs.Read( aIn, true, nCref);
293  if (!aRefs.empty())
294  {
295  aProt.maRangeList = new ScRangeList;
296  GetAddressConverter().ConvertRangeList( *aProt.maRangeList, aRefs, GetCurrScTab(), false);
297  }
298  }
299 
300  // FeatProtection structure follows in record.
301 
302  aProt.mnAreserved = aIn.ReaduInt32();
304  aProt.maTitle = aIn.ReadUniString();
305  if ((aProt.mnAreserved & 0x00000001) == 0x00000001)
306  {
307  sal_uInt32 nCbSD = aIn.ReaduInt32();
308  // TODO: could here be some sanity check applied to not allocate 4GB?
309  aProt.maSecurityDescriptor.resize( nCbSD);
310  std::size_t nRead = aIn.Read(aProt.maSecurityDescriptor.data(), nCbSD);
311  if (nRead < nCbSD)
312  aProt.maSecurityDescriptor.resize( nRead);
313  }
314 
316 }
317 
319 {
320  SfxObjectShell* pShell = GetDocShell();
322  const SvtFilterOptions& rFilterOpt = SvtFilterOptions::Get();
323  if( pShell && xRootStrg.is() ) try
324  {
325  // #FIXME need to get rid of this, we can also do this from within oox
326  // via the "ooo.vba.VBAGlobals" service
327  if( ( rFilterOpt.IsLoadExcelBasicCode() ||
328  rFilterOpt.IsLoadExcelBasicStorage() ) &&
329  rFilterOpt.IsLoadExcelBasicExecutable() )
330  {
331  // see if we have the XCB stream
332  tools::SvRef<SotStorageStream> xXCB = xRootStrg->OpenSotStream( "XCB", StreamMode::STD_READ );
333  if ( xXCB.is()|| ERRCODE_NONE == xXCB->GetError() )
334  {
336  if ( wrapper.Read( *xXCB ) )
337  {
338 #ifdef DEBUG_SC_EXCEL
339  wrapper.Print( stderr );
340 #endif
341  wrapper.ImportCustomToolBar( *pShell );
342  }
343  }
344  }
345  try
346  {
347  uno::Reference< uno::XComponentContext > aCtx( ::comphelper::getProcessComponentContext() );
348  SfxMedium& rMedium = GetMedium();
349  uno::Reference< io::XInputStream > xIn = rMedium.GetInputStream();
350  oox::ole::OleStorage root( aCtx, xIn, false );
351  oox::StorageRef vbaStg = root.openSubStorage( "_VBA_PROJECT_CUR", false );
352  if ( vbaStg )
353  {
354  oox::ole::VbaProject aVbaPrj( aCtx, pShell->GetModel(), "Calc" );
355  // collect names of embedded form controls, as specified in the VBA project
356  uno::Reference< container::XNameContainer > xOleNameOverrideSink( new OleNameOverrideContainer );
357  aVbaPrj.setOleOverridesSink( xOleNameOverrideSink );
358  aVbaPrj.importVbaProject( *vbaStg );
359  GetObjectManager().SetOleNameOverrideInfo( xOleNameOverrideSink );
360  }
361  }
362  catch( uno::Exception& )
363  {
364  }
365  }
366  catch( uno::Exception& )
367  {
368  }
369 }
370 
372 {
376 }
377 
379 {
380 #if HAVE_FEATURE_SCRIPTING
381  // reading basic has been delayed until sheet objects (codenames etc.) are read
382  if( HasBasic() )
383  ReadBasic();
384 #endif
385  // #i11776# filtered ranges before outlines and hidden rows
387  pExcRoot->pAutoFilterBuffer->Apply();
388 
389  GetWebQueryBuffer().Apply(); //TODO: test if extant
392 
394 
395  // check scenarios; Attention: This increases the table count of the document!!
396  if( !pD->IsClipboard() && !maScenList.aEntries.empty() )
397  {
398  pD->UpdateChartListenerCollection(); // references in charts must be updated
399 
400  maScenList.Apply( GetRoot() );
401  }
402 
403  // read doc info (no docshell while pasting from clipboard)
404  if( SfxObjectShell* pShell = GetDocShell() )
405  {
406  // BIFF5+ without storage is possible
408  if( xRootStrg.is() ) try
409  {
410  uno::Reference< document::XDocumentPropertiesSupplier > xDPS( pShell->GetModel(), uno::UNO_QUERY_THROW );
411  uno::Reference< document::XDocumentProperties > xDocProps( xDPS->getDocumentProperties(), uno::UNO_SET_THROW );
412  sfx2::LoadOlePropertySet( xDocProps, xRootStrg.get() );
413  }
414  catch( uno::Exception& )
415  {
416  }
417  }
418 
419  // #i45843# Pivot tables are now handled outside of PostDocLoad, so they are available
420  // when formula cells are calculated, for the GETPIVOTDATA function.
421 }
422 
423 // autofilter
424 
426 {
427  // The FilterMode record exists: if either the AutoFilter
428  // record exists or an Advanced Filter is saved and stored
429  // in the sheet. Thus if the FilterMode records only exists
430  // then the latter is true...
431  if( !pExcRoot->pAutoFilterBuffer ) return;
432 
434  if( pData )
435  pData->SetAutoOrAdvanced();
436 }
437 
439 {
440  if( !pExcRoot->pAutoFilterBuffer ) return;
441 
443  if( pData )
444  {
445  pData->SetAdvancedRange( nullptr );
446  pData->Activate();
447  }
448 }
449 
451 {
452  if( !pExcRoot->pAutoFilterBuffer ) return;
453 
455  if( pData )
456  pData->ReadAutoFilter(aIn, GetDoc().GetSharedStringPool());
457 }
458 
460  ExcRoot( pRoot ),
461  pCurrDBData(nullptr),
462  bActive( false ),
463  bCriteria( false ),
464  bAutoOrAdvanced(false)
465 {
466  aParam.nCol1 = rRange.aStart.Col();
467  aParam.nRow1 = rRange.aStart.Row();
468  aParam.nTab = rRange.aStart.Tab();
469  aParam.nCol2 = rRange.aEnd.Col();
470  aParam.nRow2 = rRange.aEnd.Row();
471 
472  aParam.bInplace = true;
473 
474 }
475 
476 namespace {
477 
478 OUString CreateFromDouble( double fVal )
479 {
480  return rtl::math::doubleToUString(fVal,
481  rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
482  ScGlobal::getLocaleDataPtr()->getNumDecimalSep()[0], true);
483 }
484 
485 }
486 
488 {
489  ScDocument& rDoc = pExcRoot->pIR->GetDoc();
490  for ( SCCOL nCol = StartCol(); nCol <= EndCol(); nCol++ )
491  {
492  ScMF nFlag = rDoc.GetAttr( nCol, StartRow(), Tab(), ATTR_MERGE_FLAG )->GetValue();
493  rDoc.ApplyAttr( nCol, StartRow(), Tab(), ScMergeFlagAttr( nFlag | ScMF::Auto) );
494  }
495 }
496 
498 {
499  if (pCurrDBData)
500  {
501  ScRange aAdvRange;
502  bool bHasAdv = pCurrDBData->GetAdvancedQuerySource( aAdvRange );
503  if( bHasAdv )
504  pExcRoot->pIR->GetDoc().CreateQueryParam(aAdvRange, aParam);
505 
507  if( bHasAdv )
508  pCurrDBData->SetAdvancedQuerySource( &aAdvRange );
509  else
510  {
511  pCurrDBData->SetAutoFilter( true );
512  SetCellAttribs();
513  }
514  }
515 }
516 
517 static void ExcelQueryToOooQuery( OUString& aStr, ScQueryEntry& rEntry )
518 {
519  if (rEntry.eOp != SC_EQUAL && rEntry.eOp != SC_NOT_EQUAL)
520  return;
521 
522  sal_Int32 nLen = aStr.getLength();
523  sal_Unicode nStart = aStr[0];
524  sal_Unicode nEnd = aStr[ nLen-1 ];
525  if( nLen > 2 && nStart == '*' && nEnd == '*' )
526  {
527  aStr = aStr.copy( 1, nLen-2 );
528  rEntry.eOp = ( rEntry.eOp == SC_EQUAL ) ? SC_CONTAINS : SC_DOES_NOT_CONTAIN;
529  }
530  else if( nLen > 1 && nStart == '*' && nEnd != '*' )
531  {
532  aStr = aStr.copy( 1 );
533  rEntry.eOp = ( rEntry.eOp == SC_EQUAL ) ? SC_ENDS_WITH : SC_DOES_NOT_END_WITH;
534  }
535  else if( nLen > 1 && nStart != '*' && nEnd == '*' )
536  {
537  aStr = aStr.copy( 0, nLen-1 );
538  rEntry.eOp = ( rEntry.eOp == SC_EQUAL ) ? SC_BEGINS_WITH : SC_DOES_NOT_BEGIN_WITH;
539  }
540  else if( nLen == 2 && nStart == '*' && nEnd == '*' )
541  {
542  aStr = aStr.copy( 1 );
543  }
544 }
545 
547  XclImpStream& rStrm, svl::SharedStringPool& rPool )
548 {
549  sal_uInt16 nCol, nFlags;
550  nCol = rStrm.ReaduInt16();
551  nFlags = rStrm.ReaduInt16();
552 
554  bool bSimple1 = ::get_flag(nFlags, EXC_AFFLAG_SIMPLE1);
555  bool bSimple2 = ::get_flag(nFlags, EXC_AFFLAG_SIMPLE2);
556  bool bTop10 = ::get_flag(nFlags, EXC_AFFLAG_TOP10);
557  bool bTopOfTop10 = ::get_flag(nFlags, EXC_AFFLAG_TOP10TOP);
558  bool bPercent = ::get_flag(nFlags, EXC_AFFLAG_TOP10PERC);
559  sal_uInt16 nCntOfTop10 = nFlags >> 7;
560 
561  if( bTop10 )
562  {
563  ScQueryEntry& aEntry = aParam.AppendEntry();
564  ScQueryEntry::Item& rItem = aEntry.GetQueryItem();
565  aEntry.bDoQuery = true;
566  aEntry.nField = static_cast<SCCOLROW>(StartCol() + static_cast<SCCOL>(nCol));
567  aEntry.eOp = bTopOfTop10 ?
568  (bPercent ? SC_TOPPERC : SC_TOPVAL) : (bPercent ? SC_BOTPERC : SC_BOTVAL);
569  aEntry.eConnect = SC_AND;
570 
572  rItem.maString = rPool.intern(OUString::number(nCntOfTop10));
573 
574  rStrm.Ignore(20);
575  return;
576  }
577 
578  sal_uInt8 nType, nOper, nBoolErr, nVal;
579  sal_Int32 nRK;
580  double fVal;
581 
582  sal_uInt8 nStrLen[2] = { 0, 0 };
584 
585  for (size_t nE = 0; nE < 2; ++nE)
586  {
587  ScQueryEntry& rEntry = aEntries[nE];
588  ScQueryEntry::Item& rItem = rEntry.GetQueryItem();
589  bool bIgnore = false;
590 
591  nType = rStrm.ReaduInt8();
592  nOper = rStrm.ReaduInt8();
593  switch( nOper )
594  {
595  case EXC_AFOPER_LESS:
596  rEntry.eOp = SC_LESS;
597  break;
598  case EXC_AFOPER_EQUAL:
599  rEntry.eOp = SC_EQUAL;
600  break;
602  rEntry.eOp = SC_LESS_EQUAL;
603  break;
604  case EXC_AFOPER_GREATER:
605  rEntry.eOp = SC_GREATER;
606  break;
607  case EXC_AFOPER_NOTEQUAL:
608  rEntry.eOp = SC_NOT_EQUAL;
609  break;
611  rEntry.eOp = SC_GREATER_EQUAL;
612  break;
613  default:
614  rEntry.eOp = SC_EQUAL;
615  }
616 
617  switch( nType )
618  {
619  case EXC_AFTYPE_RK:
620  nRK = rStrm.ReadInt32();
621  rStrm.Ignore( 4 );
622  rItem.maString = rPool.intern(
623  CreateFromDouble(XclTools::GetDoubleFromRK(nRK)));
624  break;
625  case EXC_AFTYPE_DOUBLE:
626  fVal = rStrm.ReadDouble();
627  rItem.maString = rPool.intern(CreateFromDouble(fVal));
628  break;
629  case EXC_AFTYPE_STRING:
630  rStrm.Ignore( 4 );
631  nStrLen[ nE ] = rStrm.ReaduInt8();
632  rStrm.Ignore( 3 );
633  rItem.maString = svl::SharedString();
634  break;
635  case EXC_AFTYPE_BOOLERR:
636  nBoolErr = rStrm.ReaduInt8();
637  nVal = rStrm.ReaduInt8();
638  rStrm.Ignore( 6 );
639  rItem.maString = rPool.intern(OUString::number(nVal));
640  bIgnore = (nBoolErr != 0);
641  break;
642  case EXC_AFTYPE_EMPTY:
643  rEntry.SetQueryByEmpty();
644  break;
645  case EXC_AFTYPE_NOTEMPTY:
646  rEntry.SetQueryByNonEmpty();
647  break;
648  default:
649  rStrm.Ignore( 8 );
650  bIgnore = true;
651  }
652 
653  if (!bIgnore)
654  {
655  rEntry.bDoQuery = true;
657  rEntry.nField = static_cast<SCCOLROW>(StartCol() + static_cast<SCCOL>(nCol));
658  rEntry.eConnect = nE ? eConn : SC_AND;
659  }
660  }
661 
662  if (eConn == SC_AND)
663  {
664  for (size_t nE = 0; nE < 2; ++nE)
665  {
666  if (nStrLen[nE] && aEntries[nE].bDoQuery)
667  {
668  OUString aStr = rStrm.ReadUniString(nStrLen[nE]);
669  ExcelQueryToOooQuery(aStr, aEntries[nE]);
670  aEntries[nE].GetQueryItem().maString = rPool.intern(aStr);
671  aParam.AppendEntry() = aEntries[nE];
672  }
673  }
674  }
675  else
676  {
677  assert( eConn == SC_OR && "eConn should be SC_AND or SC_OR");
678  // Import only when both conditions are for simple equality, else
679  // import only the 1st condition due to conflict with the ordering of
680  // conditions. #i39464#.
681  //
682  // Example: Let A1 be a condition of column A, and B1 and B2
683  // conditions of column B, connected with OR. Excel performs 'A1 AND
684  // (B1 OR B2)' in this case, but Calc would do '(A1 AND B1) OR B2'
685  // instead.
686 
687  if (bSimple1 && bSimple2 && nStrLen[0] && nStrLen[1])
688  {
689  // Two simple OR'ed equal conditions. We can import this correctly.
690  ScQueryEntry& rEntry = aParam.AppendEntry();
691  rEntry.bDoQuery = true;
692  rEntry.eOp = SC_EQUAL;
693  rEntry.eConnect = SC_AND;
695  aItems.reserve(2);
696  ScQueryEntry::Item aItem1, aItem2;
697  aItem1.maString = rPool.intern(rStrm.ReadUniString(nStrLen[0]));
699  aItem2.maString = rPool.intern(rStrm.ReadUniString(nStrLen[1]));
701  aItems.push_back(aItem1);
702  aItems.push_back(aItem2);
703  rEntry.GetQueryItems().swap(aItems);
704  }
705  else if (nStrLen[0] && aEntries[0].bDoQuery)
706  {
707  // Due to conflict, we can import only the first condition.
708  OUString aStr = rStrm.ReadUniString(nStrLen[0]);
709  ExcelQueryToOooQuery(aStr, aEntries[0]);
710  aEntries[0].GetQueryItem().maString = rPool.intern(aStr);
711  aParam.AppendEntry() = aEntries[0];
712  }
713  }
714 }
715 
717 {
718  if (pRange)
719  {
720  aCriteriaRange = *pRange;
721  bCriteria = true;
722  }
723  else
724  bCriteria = false;
725 }
726 
728 {
729  aParam.nDestCol = rAddr.Col();
730  aParam.nDestRow = rAddr.Row();
731  aParam.nDestTab = rAddr.Tab();
732  aParam.bInplace = false;
733  aParam.bDestPers = true;
734 }
735 
737 {
738  // Create the ScDBData() object if the AutoFilter is activated
739  // or if we need to create the Advanced Filter.
740  if( bActive || bCriteria)
741  {
742  ScDocument& rDoc = pExcRoot->pIR->GetDoc();
744  StartCol(),StartRow(), EndCol(),EndRow() );
745  if(bCriteria)
746  {
748 
751  }
752  else
754  rDoc.SetAnonymousDBData(Tab(), std::unique_ptr<ScDBData>(pCurrDBData));
755  }
756 
757  if( bActive )
758  {
760  }
761 }
762 
764 {
765  // only if this is a saved Advanced filter
766  if( !bActive && bAutoOrAdvanced )
767  {
768  ScQueryEntry& aEntry = aParam.AppendEntry();
769  aEntry.bDoQuery = true;
770  }
771 
772  // TBD: force the automatic activation of the
773  // "Remove Filter" by setting a virtual mouse click
774  // inside the advanced range
775 }
776 
777 void XclImpAutoFilterBuffer::Insert( RootData* pRoot, const ScRange& rRange)
778 {
779  if( !GetByTab( rRange.aStart.Tab() ) )
780  maFilters.push_back( std::make_shared<XclImpAutoFilterData>( pRoot, rRange ));
781 }
782 
784 {
786  if( pData )
787  pData->SetAdvancedRange( &rRange );
788 }
789 
791 {
793  if( pData )
794  pData->SetExtractPos( rRange.aStart );
795 }
796 
798 {
799  for( const auto& rFilterPtr : maFilters )
800  rFilterPtr->Apply();
801 }
802 
804 {
805  for( const auto& rFilterPtr : maFilters )
806  {
807  if( rFilterPtr->Tab() == nTab )
808  return rFilterPtr.get();
809  }
810  return nullptr;
811 }
812 
813 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
RootData * pExcRoot
Definition: imp_op.hxx:90
bool is() const
XclImpValidationManager & GetValidationManager() const
Definition: xiroot.cxx:211
void SetOleNameOverrideInfo(const css::uno::Reference< css::container::XNameContainer > &rxOverrideInfo)
Sets the container to receive overridden shape/ctrl names from the filter.
Definition: xiescher.hxx:1165
void SetQueryByEmpty()
Definition: queryentry.cxx:74
ScDocumentImport & GetDocImport()
Definition: xiroot.cxx:292
const sal_uInt8 EXC_AFOPER_GREATER
Definition: excdefs.hxx:52
ScAddress aStart
Definition: address.hxx:500
sal_Int32 ReadInt32()
Definition: xistream.cxx:666
SharedString intern(const OUString &rStr)
void AutoFilterInfo()
Definition: excimp8.cxx:438
SCROW StartRow() const
Definition: excimp8.hxx:86
ReturnType get_flagvalue(Type nBitField, Type nMask, ReturnType nSet, ReturnType nUnset)
Returns nSet, if at least one bit of nMask is set in nBitField, otherwise nUnset. ...
Definition: ftools.hxx:78
ExcScenarioList maScenList
Definition: excimp8.hxx:59
const sal_uInt8 EXC_AFOPER_LESSEQUAL
Definition: excdefs.hxx:51
osl::Mutex m_aMutex
const sal_uInt8 EXC_AFTYPE_NOTEMPTY
Definition: excdefs.hxx:45
SCROW Row() const
Definition: address.hxx:262
ScRangeListRef maRangeList
Stores global buffers and data needed for Excel import filter.
Definition: xiroot.hxx:64
std::unique_ptr< ContentProperties > pData
SC_DLLPUBLIC void SetAnonymousDBData(SCTAB nTab, std::unique_ptr< ScDBData > pDBData)
Definition: document.cxx:318
#define STR_DB_LOCAL_NONAME
Definition: globalnames.hxx:13
QueryItemsType & GetQueryItems()
Definition: queryentry.hxx:65
std::size_t Read(void *pData, std::size_t nBytes)
Reads nBytes bytes to the existing(!) buffer pData.
Definition: xistream.cxx:720
XclImpXFRangeBuffer & GetXFRangeBuffer() const
Returns the buffer of XF index ranges for a sheet.
Definition: xiroot.cxx:161
void ConvertRangeList(ScRangeList &rScRanges, const XclRangeList &rXclRanges, SCTAB nScTab, bool bWarn)
Converts the passed Excel cell range list to a Calc cell range list.
Definition: xihelper.cxx:125
bool IsLoadExcelBasicCode() const
void Feat()
Definition: excimp8.cxx:270
SCCOLROW nField
Definition: queryentry.hxx:51
const sal_uInt8 EXC_AFOPER_NOTEQUAL
Definition: excdefs.hxx:53
ScAddress aEnd
Definition: address.hxx:501
SCCOL EndCol() const
Definition: excimp8.hxx:87
bool IsLoadExcelBasicExecutable() const
const sal_uInt16 EXC_AFFLAG_TOP10TOP
Definition: excdefs.hxx:34
css::uno::Reference< css::frame::XModel > GetModel() const
const sal_uInt16 EXC_AFFLAG_SIMPLE2
Definition: excdefs.hxx:32
const sal_uInt8 EXC_AFTYPE_DOUBLE
Definition: excdefs.hxx:40
void AddExtractPos(const ScRange &rRange)
Definition: excimp8.cxx:790
SC_DLLPUBLIC bool CreateQueryParam(const ScRange &rRange, ScQueryParam &rQueryParam)
Definition: documen3.cxx:1444
XclImpObjectManager & GetObjectManager() const
Returns the drawing object manager.
Definition: xiroot.cxx:194
ScDocument & GetDoc() const
Returns reference to the destination document (import) or source document (export).
Definition: xlroot.cxx:278
void Scenman()
Definition: excimp8.cxx:218
StorageRef openSubStorage(const OUString &rStorageName, bool bCreateMissing)
SCTAB nBdshtTab
Definition: imp_op.hxx:114
std::shared_ptr< StorageBase > StorageRef
SC_DLLPUBLIC void ApplyAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, const SfxPoolItem &rAttr)
Definition: document.cxx:4759
ScfUInt32Vec maSheetOffsets
Definition: imp_op.hxx:95
const sal_uInt8 EXC_AFTYPE_STRING
Definition: excdefs.hxx:41
static void SetToDocument(ScDocumentImport &rDoc, const ScAddress &rPos, const XclImpRoot &rRoot, const XclImpString &rString, sal_uInt16 nXFIndex)
Definition: xihelper.cxx:223
SC_DLLPUBLIC void SetVisible(SCTAB nTab, bool bVisible)
Definition: document.cxx:900
const XclImpRoot & GetRoot() const
Returns this root instance - for code readability in derived classes.
Definition: xiroot.hxx:132
const XclImpString * GetString(sal_uInt32 nSstIndex) const
Returns a pointer to the string with the passed index.
Definition: xicontent.cxx:94
void Insert(RootData *pRoot, const ScRange &rRange)
Definition: excimp8.cxx:777
void Read(XclImpStream &rStrm, bool bCol16Bit=true, sal_uInt16 nCountInStream=0)
Definition: xladdress.cxx:90
const Item & GetQueryItem() const
Definition: queryentry.cxx:118
void ReadBasic()
Definition: excimp8.cxx:318
virtual void PostDocLoad() override
Definition: excimp8.cxx:378
sal_uInt16 sal_Unicode
void FilterMode()
Definition: excimp8.cxx:425
SC_DLLPUBLIC bool RenameTab(SCTAB nTab, const OUString &rName, bool bExternalDocument=false)
Definition: document.cxx:852
ImportExcel8(XclImpRootData &rImpData, SvStream &rStrm)
Definition: excimp8.cxx:145
void SetXF(const ScAddress &rScPos, sal_uInt16 nXFIndex)
Inserts a new XF index.
Definition: xistyle.cxx:1918
void Calccount()
Definition: excimp8.cxx:157
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW
Definition: types.hxx:24
XclImpSst & GetSst() const
Returns the shared string table.
Definition: xiroot.cxx:135
ScDocument * pD
Definition: imp_op.hxx:47
static void ExcelQueryToOooQuery(OUString &aStr, ScQueryEntry &rEntry)
Definition: excimp8.cxx:517
const sal_uInt8 EXC_AFOPER_EQUAL
Definition: excdefs.hxx:50
void ImportCustomToolBar(SfxObjectShell &rDocSh)
Definition: xltoolbar.cxx:388
virtual void PostDocLoad()
Definition: impop.cxx:1233
SC_DLLPUBLIC bool HasTable(SCTAB nTab) const
Definition: document.cxx:190
SCTAB Tab() const
Definition: address.hxx:271
SC_DLLPUBLIC void SetQueryParam(const ScQueryParam &rQueryParam)
Definition: dbdata.cxx:423
ErrCode LoadOlePropertySet(const uno::Reference< document::XDocumentProperties > &i_xDocProps, SotStorage *i_pStorage)
const sal_uInt16 EXC_AFFLAG_TOP10
Definition: excdefs.hxx:33
const tools::SvRef< SotStorage > & GetRootStorage() const
Returns the OLE2 root storage of the imported/exported file.
Definition: xlroot.hxx:184
SC_DLLPUBLIC const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich) const
Definition: document.cxx:4716
const sal_uInt16 EXC_ISFPROTECTION
Definition: xlconst.hxx:260
sal_uInt16 nLastScenario
Definition: excscen.hxx:67
void DisableDecryption()
Switches usage of current decryption algorithm off.
Definition: xistream.hxx:335
bool empty() const
Definition: xladdress.hxx:110
bool IsClipboard() const
Definition: document.hxx:1533
void SetCalcAsShown(bool bVal)
Definition: docoptio.hxx:83
SC_DLLPUBLIC const ScDocOptions & GetDocOptions() const
Definition: documen3.cxx:1904
std::vector< XclImpAutoFilterSharePtr > maFilters
Definition: excimp8.hxx:113
std::unique_ptr< XclImpAutoFilterBuffer > pAutoFilterBuffer
Definition: root.hxx:57
T * get() const
virtual void EndSheet() override
Definition: excimp8.cxx:371
static SvtFilterOptions & Get()
XclImpTabInfo & GetTabInfo() const
Returns the buffer that contains the sheet creation order.
Definition: xiroot.cxx:178
static double GetDoubleFromRK(sal_Int32 nRKValue)
GUID of file moniker (HLINK record).
Definition: xltools.cxx:95
SotStorageStream * OpenSotStream(const OUString &rEleName, StreamMode=StreamMode::STD_READWRITE)
std::unique_ptr< ExcelToSc > pFormConv
Visible range if embedded.
Definition: imp_op.hxx:98
void Scenario()
Definition: excimp8.cxx:228
sal_Int16 SCCOL
Definition: types.hxx:22
Definition: root.hxx:72
double ReadDouble()
Definition: xistream.cxx:702
SC_DLLPUBLIC void SetAdvancedQuerySource(const ScRange *pSource)
Definition: dbdata.cxx:432
SC_DLLPUBLIC void CreateValidTabName(OUString &rName) const
Definition: document.cxx:391
XclImpAddressConverter & GetAddressConverter() const
Returns the address converter.
Definition: xiroot.cxx:119
XclImpAutoFilterData(RootData *pRoot, const ScRange &rRange)
Definition: excimp8.cxx:459
void SetIter(bool bVal)
Definition: docoptio.hxx:61
SCTAB Tab() const
Definition: excimp8.hxx:84
A 2D cell range address list with Excel column and row indexes.
Definition: xladdress.hxx:101
unsigned char sal_Bool
void AutoFilter()
Definition: excimp8.cxx:450
bool get_flag(Type nBitField, Type nMask)
Returns true, if at least one of the bits set in nMask is set in nBitField.
Definition: ftools.hxx:73
RootData * pExcRoot
Definition: root.hxx:75
void SetExtractPos(const ScAddress &rAddr)
Definition: excimp8.cxx:727
Container for the Excel EnhancedProtection feature.
const sal_uInt8 EXC_AFTYPE_RK
Definition: excdefs.hxx:39
css::uno::Type const & get()
ScDBData * pCurrDBData
Definition: excimp8.hxx:66
A 2D cell address struct with Excel column and row indexes.
Definition: xladdress.hxx:30
void SetIterCount(sal_uInt16 nCount)
Definition: docoptio.hxx:63
sal_uInt16 ReaduInt16()
Definition: xistream.cxx:648
const sal_uInt16 EXC_AFFLAG_ANDORMASK
Definition: excdefs.hxx:30
ScQueryParam aParam
Definition: excimp8.hxx:67
void EnableDecryption(bool bEnable=true)
Switches usage of current decryption algorithm on/off.
Definition: xistream.cxx:521
svl::SharedString maString
Definition: queryentry.hxx:41
const sal_uInt8 EXC_AFOPER_LESS
Definition: excdefs.hxx:49
SCCOL Col() const
Definition: address.hxx:267
SCTAB GetCurrScTab() const
Returns the current Calc sheet index.
Definition: xlroot.hxx:160
css::uno::Reference< css::io::XInputStream > const & GetInputStream()
void Labelsst()
Definition: excimp8.cxx:233
bool HasBasic() const
Returns true, if the document contains a VB project.
Definition: xiroot.hxx:205
void Precision()
Definition: excimp8.cxx:164
XclImpAutoFilterData * GetByTab(SCTAB nTab)
Definition: excimp8.cxx:803
std::vector< std::unique_ptr< ExcScenario > > aEntries
Definition: excscen.hxx:68
static SC_DLLPUBLIC const LocaleDataWrapper * getLocaleDataPtr()
Definition: global.cxx:1009
constexpr TypedWhichId< ScMergeFlagAttr > ATTR_MERGE_FLAG(145)
OUString ReadUniString(sal_uInt16 nChars, sal_uInt8 nFlags)
Reads ext.
Definition: xistream.cxx:886
XclImpWebQueryBuffer & GetWebQueryBuffer() const
Returns the web query buffer.
Definition: xiroot.cxx:224
const sal_uInt16 EXC_AFFLAG_SIMPLE1
Definition: excdefs.hxx:31
ScMF
Definition: attrib.hxx:35
SC_DLLPUBLIC void SetDocOptions(const ScDocOptions &rOpt)
Definition: documen3.cxx:1910
void Apply()
Inserts the conditional formatting into the document.
Definition: xicontent.cxx:722
void AppendEnhancedProtection(const ScEnhancedProtection &rProt, SCTAB nTab)
Definition: xicontent.cxx:1356
void Delta()
Definition: excimp8.cxx:171
Any makeAny(Color const &value)
const sal_uInt8 EXC_AFTYPE_EMPTY
Definition: excdefs.hxx:44
#define ERRCODE_NONE
SC_DLLPUBLIC ScQueryEntry & AppendEntry()
Definition: queryparam.cxx:134
void Ignore(std::size_t nBytes)
Seeks forward inside the current record.
Definition: xistream.cxx:795
unsigned char sal_uInt8
ScRange aCriteriaRange
Definition: excimp8.hxx:68
virtual ~ImportExcel8() override
Definition: excimp8.cxx:153
sal_uInt8 ReaduInt8()
Definition: xistream.cxx:616
XclImpRoot * pIR
Definition: root.hxx:65
sal_uInt32 mnPasswordVerifier
void FeatHdr()
Definition: excimp8.cxx:253
SCROW EndRow() const
Definition: excimp8.hxx:88
::std::vector< sal_uInt8 > maSecurityDescriptor
const sal_uInt8 EXC_AFTYPE_BOOLERR
Definition: excdefs.hxx:42
Reference< XComponentContext > getProcessComponentContext()
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:401
void EnableRemoveFilter()
Definition: excimp8.cxx:763
SC_DLLPUBLIC void UpdateChartListenerCollection()
Definition: documen5.cxx:569
ScQueryConnect eConnect
Definition: queryentry.hxx:53
ExcelToSc * pFmlaConverter
Definition: root.hxx:53
const sal_uInt8 EXC_AFOPER_GREATEREQUAL
Definition: excdefs.hxx:54
void AddAdvancedRange(const ScRange &rRange)
Definition: excimp8.cxx:783
std::vector< Item > QueryItemsType
Definition: queryentry.hxx:48
ScXMLEditAttributeMap::Entry const aEntries[]
SC_DLLPUBLIC bool GetAdvancedQuerySource(ScRange &rSource) const
Definition: dbdata.cxx:443
void Iteration()
Definition: excimp8.cxx:178
XclImpCondFormatManager & GetCondFormatManager() const
Returns the conditional formatting manager.
Definition: xiroot.cxx:205
virtual void EndSheet()
Definition: impop.cxx:1178
SfxObjectShell * GetDocShell() const
Returns the object shell of the Calc document.
Definition: xlroot.cxx:283
SC_DLLPUBLIC void MakeTable(SCTAB nTab, bool _bNeedsNameCheck=true)
Definition: document.cxx:167
void Apply(const XclImpRoot &rRoot)
Definition: exctools.cxx:238
This class is used to import record oriented streams.
Definition: xistream.hxx:278
XclImpStream & aIn
Definition: imp_op.hxx:93
void ReadAutoFilter(XclImpStream &rStrm, svl::SharedStringPool &rPool)
Definition: excimp8.cxx:546
void Boundsheet()
Definition: excimp8.cxx:185
void SetAutoOrAdvanced()
Definition: excimp8.hxx:95
ScQueryOp eOp
Definition: queryentry.hxx:52
bool Read(SvStream &rS) override
Definition: xltoolbar.cxx:340
sal_uInt32 ReaduInt32()
Definition: xistream.cxx:684
XclImpSheetProtectBuffer & GetSheetProtectBuffer() const
Returns the sheet protection options of the current sheet.
Definition: xiroot.cxx:236
This class represents an unformatted or formatted string and provides importing from stream...
Definition: xistring.hxx:31
XclImpDocProtectBuffer & GetDocProtectBuffer() const
Returns the document protection options.
Definition: xiroot.cxx:242
void Apply()
Inserts all web queries into the document.
Definition: xicontent.cxx:1081
aStr
SfxMedium & GetMedium() const
Returns the medium to import from.
Definition: xlroot.hxx:168
void ReadOptions(XclImpStream &rStrm, SCTAB nTab)
Definition: xicontent.cxx:1337
Each instance of this struct represents a single filtering criteria.
Definition: queryentry.hxx:33
void SetQueryByNonEmpty()
Definition: queryentry.cxx:96
void SetAdvancedRange(const ScRange *pRange)
Definition: excimp8.cxx:716
sal_Int16 SCTAB
Definition: types.hxx:23
void SetAutoFilter(bool bSet)
Definition: dbdata.hxx:205
css::uno::Sequence< typename M::key_type > mapKeysToSequence(M const &map)
ScQueryConnect
Definition: global.hxx:842
void AppendXclTabName(const OUString &rXclTabName, SCTAB nScTab)
Appends an original Excel sheet name with corresponding Calc sheet index.
Definition: xilink.cxx:226
SCCOL StartCol() const
Definition: excimp8.hxx:85
exports com.sun.star.xml. wrapper
const sal_uInt16 EXC_AFFLAG_TOP10PERC
Definition: excdefs.hxx:35
bool IsLoadExcelBasicStorage() const
void SetIterEps(double fEps)
Definition: docoptio.hxx:65