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 = rD.GetDocOptions();
160  aOpt.SetIterCount( aIn.ReaduInt16() );
161  rD.SetDocOptions( aOpt );
162 }
163 
165 {
166  ScDocOptions aOpt = rD.GetDocOptions();
167  aOpt.SetCalcAsShown( aIn.ReaduInt16() == 0 );
168  rD.SetDocOptions( aOpt );
169 }
170 
172 {
173  ScDocOptions aOpt = rD.GetDocOptions();
174  aOpt.SetIterEps( aIn.ReadDouble() );
175  rD.SetDocOptions( aOpt );
176 }
177 
179 {
180  ScDocOptions aOpt = rD.GetDocOptions();
181  aOpt.SetIter( aIn.ReaduInt16() == 1 );
182  rD.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( !rD.HasTable( nScTab ), "ImportExcel8::Boundsheet - sheet exists already" );
203  rD.MakeTable( nScTab );
204  }
205 
206  if( ( nGrbit & 0x0001 ) || ( nGrbit & 0x0002 ) )
207  rD.SetVisible( nScTab, false );
208 
209  if( !rD.RenameTab( nScTab, aName ) )
210  {
211  rD.CreateValidTabName( aName );
212  rD.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() )
324  return;
325 
326  try
327  {
328  // #FIXME need to get rid of this, we can also do this from within oox
329  // via the "ooo.vba.VBAGlobals" service
330  if( ( rFilterOpt.IsLoadExcelBasicCode() ||
331  rFilterOpt.IsLoadExcelBasicStorage() ) &&
332  rFilterOpt.IsLoadExcelBasicExecutable() )
333  {
334  // see if we have the XCB stream
335  tools::SvRef<SotStorageStream> xXCB = xRootStrg->OpenSotStream( "XCB", StreamMode::STD_READ );
336  if ( xXCB.is()|| ERRCODE_NONE == xXCB->GetError() )
337  {
339  if ( wrapper.Read( *xXCB ) )
340  {
341 #ifdef DEBUG_SC_EXCEL
342  wrapper.Print( stderr );
343 #endif
344  wrapper.ImportCustomToolBar( *pShell );
345  }
346  }
347  }
348  try
349  {
350  uno::Reference< uno::XComponentContext > aCtx( ::comphelper::getProcessComponentContext() );
351  SfxMedium& rMedium = GetMedium();
352  uno::Reference< io::XInputStream > xIn = rMedium.GetInputStream();
353  oox::ole::OleStorage root( aCtx, xIn, false );
354  oox::StorageRef vbaStg = root.openSubStorage( "_VBA_PROJECT_CUR", false );
355  if ( vbaStg )
356  {
357  oox::ole::VbaProject aVbaPrj( aCtx, pShell->GetModel(), "Calc" );
358  // collect names of embedded form controls, as specified in the VBA project
359  uno::Reference< container::XNameContainer > xOleNameOverrideSink( new OleNameOverrideContainer );
360  aVbaPrj.setOleOverridesSink( xOleNameOverrideSink );
361  aVbaPrj.importVbaProject( *vbaStg );
362  GetObjectManager().SetOleNameOverrideInfo( xOleNameOverrideSink );
363  }
364  }
365  catch( uno::Exception& )
366  {
367  }
368  }
369  catch( uno::Exception& )
370  {
371  }
372 }
373 
375 {
379 }
380 
382 {
383 #if HAVE_FEATURE_SCRIPTING
384  // reading basic has been delayed until sheet objects (codenames etc.) are read
385  if( HasBasic() )
386  ReadBasic();
387 #endif
388  // #i11776# filtered ranges before outlines and hidden rows
390  pExcRoot->pAutoFilterBuffer->Apply();
391 
392  GetWebQueryBuffer().Apply(); //TODO: test if extant
395 
397 
398  // check scenarios; Attention: This increases the table count of the document!!
399  if( !rD.IsClipboard() && !maScenList.aEntries.empty() )
400  {
401  rD.UpdateChartListenerCollection(); // references in charts must be updated
402 
403  maScenList.Apply( GetRoot() );
404  }
405 
406  // read doc info (no docshell while pasting from clipboard)
407  SfxObjectShell* pShell = GetDocShell();
408  if(!pShell)
409  return;
410 
411  // BIFF5+ without storage is possible
413  if( xRootStrg.is() ) try
414  {
415  uno::Reference< document::XDocumentPropertiesSupplier > xDPS( pShell->GetModel(), uno::UNO_QUERY_THROW );
416  uno::Reference< document::XDocumentProperties > xDocProps( xDPS->getDocumentProperties(), uno::UNO_SET_THROW );
417  sfx2::LoadOlePropertySet( xDocProps, xRootStrg.get() );
418  }
419  catch( uno::Exception& )
420  {
421  }
422 
423  // #i45843# Pivot tables are now handled outside of PostDocLoad, so they are available
424  // when formula cells are calculated, for the GETPIVOTDATA function.
425 }
426 
427 // autofilter
428 
430 {
431  // The FilterMode record exists: if either the AutoFilter
432  // record exists or an Advanced Filter is saved and stored
433  // in the sheet. Thus if the FilterMode records only exists
434  // then the latter is true...
435  if( !pExcRoot->pAutoFilterBuffer ) return;
436 
438  if( pData )
439  pData->SetAutoOrAdvanced();
440 }
441 
443 {
444  if( !pExcRoot->pAutoFilterBuffer ) return;
445 
447  if( pData )
448  {
449  pData->SetAdvancedRange( nullptr );
450  pData->Activate();
451  }
452 }
453 
455 {
456  if( !pExcRoot->pAutoFilterBuffer ) return;
457 
459  if( pData )
460  pData->ReadAutoFilter(aIn, GetDoc().GetSharedStringPool());
461 }
462 
464  ExcRoot( pRoot ),
465  pCurrDBData(nullptr),
466  bActive( false ),
467  bCriteria( false ),
468  bAutoOrAdvanced(false)
469 {
470  aParam.nCol1 = rRange.aStart.Col();
471  aParam.nRow1 = rRange.aStart.Row();
472  aParam.nTab = rRange.aStart.Tab();
473  aParam.nCol2 = rRange.aEnd.Col();
474  aParam.nRow2 = rRange.aEnd.Row();
475 
476  aParam.bInplace = true;
477 
478 }
479 
480 namespace {
481 
482 OUString CreateFromDouble( double fVal )
483 {
484  return rtl::math::doubleToUString(fVal,
485  rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max,
486  ScGlobal::getLocaleDataPtr()->getNumDecimalSep()[0], true);
487 }
488 
489 }
490 
492 {
493  ScDocument& rDoc = pExcRoot->pIR->GetDoc();
494  for ( SCCOL nCol = StartCol(); nCol <= EndCol(); nCol++ )
495  {
496  ScMF nFlag = rDoc.GetAttr( nCol, StartRow(), Tab(), ATTR_MERGE_FLAG )->GetValue();
497  rDoc.ApplyAttr( nCol, StartRow(), Tab(), ScMergeFlagAttr( nFlag | ScMF::Auto) );
498  }
499 }
500 
502 {
503  if (!pCurrDBData)
504  return;
505 
506  ScRange aAdvRange;
507  bool bHasAdv = pCurrDBData->GetAdvancedQuerySource( aAdvRange );
508  if( bHasAdv )
509  pExcRoot->pIR->GetDoc().CreateQueryParam(aAdvRange, aParam);
510 
512  if( bHasAdv )
513  pCurrDBData->SetAdvancedQuerySource( &aAdvRange );
514  else
515  {
516  pCurrDBData->SetAutoFilter( true );
517  SetCellAttribs();
518  }
519 }
520 
521 static void ExcelQueryToOooQuery( OUString& aStr, ScQueryEntry& rEntry )
522 {
523  if (rEntry.eOp != SC_EQUAL && rEntry.eOp != SC_NOT_EQUAL)
524  return;
525 
526  sal_Int32 nLen = aStr.getLength();
527  sal_Unicode nStart = aStr[0];
528  sal_Unicode nEnd = aStr[ nLen-1 ];
529  if( nLen > 2 && nStart == '*' && nEnd == '*' )
530  {
531  aStr = aStr.copy( 1, nLen-2 );
532  rEntry.eOp = ( rEntry.eOp == SC_EQUAL ) ? SC_CONTAINS : SC_DOES_NOT_CONTAIN;
533  }
534  else if( nLen > 1 && nStart == '*' && nEnd != '*' )
535  {
536  aStr = aStr.copy( 1 );
537  rEntry.eOp = ( rEntry.eOp == SC_EQUAL ) ? SC_ENDS_WITH : SC_DOES_NOT_END_WITH;
538  }
539  else if( nLen > 1 && nStart != '*' && nEnd == '*' )
540  {
541  aStr = aStr.copy( 0, nLen-1 );
542  rEntry.eOp = ( rEntry.eOp == SC_EQUAL ) ? SC_BEGINS_WITH : SC_DOES_NOT_BEGIN_WITH;
543  }
544  else if( nLen == 2 && nStart == '*' && nEnd == '*' )
545  {
546  aStr = aStr.copy( 1 );
547  }
548 }
549 
551  XclImpStream& rStrm, svl::SharedStringPool& rPool )
552 {
553  sal_uInt16 nCol, nFlags;
554  nCol = rStrm.ReaduInt16();
555  nFlags = rStrm.ReaduInt16();
556 
558  bool bSimple1 = ::get_flag(nFlags, EXC_AFFLAG_SIMPLE1);
559  bool bSimple2 = ::get_flag(nFlags, EXC_AFFLAG_SIMPLE2);
560  bool bTop10 = ::get_flag(nFlags, EXC_AFFLAG_TOP10);
561  bool bTopOfTop10 = ::get_flag(nFlags, EXC_AFFLAG_TOP10TOP);
562  bool bPercent = ::get_flag(nFlags, EXC_AFFLAG_TOP10PERC);
563  sal_uInt16 nCntOfTop10 = nFlags >> 7;
564 
565  if( bTop10 )
566  {
567  ScQueryEntry& aEntry = aParam.AppendEntry();
568  ScQueryEntry::Item& rItem = aEntry.GetQueryItem();
569  aEntry.bDoQuery = true;
570  aEntry.nField = static_cast<SCCOLROW>(StartCol() + static_cast<SCCOL>(nCol));
571  aEntry.eOp = bTopOfTop10 ?
572  (bPercent ? SC_TOPPERC : SC_TOPVAL) : (bPercent ? SC_BOTPERC : SC_BOTVAL);
573  aEntry.eConnect = SC_AND;
574 
576  rItem.maString = rPool.intern(OUString::number(nCntOfTop10));
577 
578  rStrm.Ignore(20);
579  return;
580  }
581 
582  sal_uInt8 nType, nOper, nBoolErr, nVal;
583  sal_Int32 nRK;
584  double fVal;
585 
586  sal_uInt8 nStrLen[2] = { 0, 0 };
588 
589  for (size_t nE = 0; nE < 2; ++nE)
590  {
591  ScQueryEntry& rEntry = aEntries[nE];
592  ScQueryEntry::Item& rItem = rEntry.GetQueryItem();
593  bool bIgnore = false;
594 
595  nType = rStrm.ReaduInt8();
596  nOper = rStrm.ReaduInt8();
597  switch( nOper )
598  {
599  case EXC_AFOPER_LESS:
600  rEntry.eOp = SC_LESS;
601  break;
602  case EXC_AFOPER_EQUAL:
603  rEntry.eOp = SC_EQUAL;
604  break;
606  rEntry.eOp = SC_LESS_EQUAL;
607  break;
608  case EXC_AFOPER_GREATER:
609  rEntry.eOp = SC_GREATER;
610  break;
611  case EXC_AFOPER_NOTEQUAL:
612  rEntry.eOp = SC_NOT_EQUAL;
613  break;
615  rEntry.eOp = SC_GREATER_EQUAL;
616  break;
617  default:
618  rEntry.eOp = SC_EQUAL;
619  }
620 
621  switch( nType )
622  {
623  case EXC_AFTYPE_RK:
624  nRK = rStrm.ReadInt32();
625  rStrm.Ignore( 4 );
626  rItem.maString = rPool.intern(
627  CreateFromDouble(XclTools::GetDoubleFromRK(nRK)));
628  break;
629  case EXC_AFTYPE_DOUBLE:
630  fVal = rStrm.ReadDouble();
631  rItem.maString = rPool.intern(CreateFromDouble(fVal));
632  break;
633  case EXC_AFTYPE_STRING:
634  rStrm.Ignore( 4 );
635  nStrLen[ nE ] = rStrm.ReaduInt8();
636  rStrm.Ignore( 3 );
637  rItem.maString = svl::SharedString();
638  break;
639  case EXC_AFTYPE_BOOLERR:
640  nBoolErr = rStrm.ReaduInt8();
641  nVal = rStrm.ReaduInt8();
642  rStrm.Ignore( 6 );
643  rItem.maString = rPool.intern(OUString::number(nVal));
644  bIgnore = (nBoolErr != 0);
645  break;
646  case EXC_AFTYPE_EMPTY:
647  rEntry.SetQueryByEmpty();
648  break;
649  case EXC_AFTYPE_NOTEMPTY:
650  rEntry.SetQueryByNonEmpty();
651  break;
652  default:
653  rStrm.Ignore( 8 );
654  bIgnore = true;
655  }
656 
657  if (!bIgnore)
658  {
659  rEntry.bDoQuery = true;
661  rEntry.nField = static_cast<SCCOLROW>(StartCol() + static_cast<SCCOL>(nCol));
662  rEntry.eConnect = nE ? eConn : SC_AND;
663  }
664  }
665 
666  if (eConn == SC_AND)
667  {
668  for (size_t nE = 0; nE < 2; ++nE)
669  {
670  if (nStrLen[nE] && aEntries[nE].bDoQuery)
671  {
672  OUString aStr = rStrm.ReadUniString(nStrLen[nE]);
673  ExcelQueryToOooQuery(aStr, aEntries[nE]);
674  aEntries[nE].GetQueryItem().maString = rPool.intern(aStr);
675  aParam.AppendEntry() = aEntries[nE];
676  }
677  }
678  }
679  else
680  {
681  assert( eConn == SC_OR && "eConn should be SC_AND or SC_OR");
682  // Import only when both conditions are for simple equality, else
683  // import only the 1st condition due to conflict with the ordering of
684  // conditions. #i39464#.
685  //
686  // Example: Let A1 be a condition of column A, and B1 and B2
687  // conditions of column B, connected with OR. Excel performs 'A1 AND
688  // (B1 OR B2)' in this case, but Calc would do '(A1 AND B1) OR B2'
689  // instead.
690 
691  if (bSimple1 && bSimple2 && nStrLen[0] && nStrLen[1])
692  {
693  // Two simple OR'ed equal conditions. We can import this correctly.
694  ScQueryEntry& rEntry = aParam.AppendEntry();
695  rEntry.bDoQuery = true;
696  rEntry.eOp = SC_EQUAL;
697  rEntry.eConnect = SC_AND;
699  aItems.reserve(2);
700  ScQueryEntry::Item aItem1, aItem2;
701  aItem1.maString = rPool.intern(rStrm.ReadUniString(nStrLen[0]));
703  aItem2.maString = rPool.intern(rStrm.ReadUniString(nStrLen[1]));
705  aItems.push_back(aItem1);
706  aItems.push_back(aItem2);
707  rEntry.GetQueryItems().swap(aItems);
708  }
709  else if (nStrLen[0] && aEntries[0].bDoQuery)
710  {
711  // Due to conflict, we can import only the first condition.
712  OUString aStr = rStrm.ReadUniString(nStrLen[0]);
713  ExcelQueryToOooQuery(aStr, aEntries[0]);
714  aEntries[0].GetQueryItem().maString = rPool.intern(aStr);
715  aParam.AppendEntry() = aEntries[0];
716  }
717  }
718 }
719 
721 {
722  if (pRange)
723  {
724  aCriteriaRange = *pRange;
725  bCriteria = true;
726  }
727  else
728  bCriteria = false;
729 }
730 
732 {
733  aParam.nDestCol = rAddr.Col();
734  aParam.nDestRow = rAddr.Row();
735  aParam.nDestTab = rAddr.Tab();
736  aParam.bInplace = false;
737  aParam.bDestPers = true;
738 }
739 
741 {
742  // Create the ScDBData() object if the AutoFilter is activated
743  // or if we need to create the Advanced Filter.
744  if( bActive || bCriteria)
745  {
746  ScDocument& rDoc = pExcRoot->pIR->GetDoc();
748  StartCol(),StartRow(), EndCol(),EndRow() );
749  if(bCriteria)
750  {
752 
755  }
756  else
758  rDoc.SetAnonymousDBData(Tab(), std::unique_ptr<ScDBData>(pCurrDBData));
759  }
760 
761  if( bActive )
762  {
764  }
765 }
766 
768 {
769  // only if this is a saved Advanced filter
770  if( !bActive && bAutoOrAdvanced )
771  {
772  ScQueryEntry& aEntry = aParam.AppendEntry();
773  aEntry.bDoQuery = true;
774  }
775 
776  // TBD: force the automatic activation of the
777  // "Remove Filter" by setting a virtual mouse click
778  // inside the advanced range
779 }
780 
781 void XclImpAutoFilterBuffer::Insert( RootData* pRoot, const ScRange& rRange)
782 {
783  if( !GetByTab( rRange.aStart.Tab() ) )
784  maFilters.push_back( std::make_shared<XclImpAutoFilterData>( pRoot, rRange ));
785 }
786 
788 {
790  if( pData )
791  pData->SetAdvancedRange( &rRange );
792 }
793 
795 {
797  if( pData )
798  pData->SetExtractPos( rRange.aStart );
799 }
800 
802 {
803  for( const auto& rFilterPtr : maFilters )
804  rFilterPtr->Apply();
805 }
806 
808 {
809  for( const auto& rFilterPtr : maFilters )
810  {
811  if( rFilterPtr->Tab() == nTab )
812  return rFilterPtr.get();
813  }
814  return nullptr;
815 }
816 
817 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
RootData * pExcRoot
Definition: imp_op.hxx:88
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:442
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:79
ExcScenarioList maScenList
Definition: excimp8.hxx:59
const sal_uInt8 EXC_AFOPER_LESSEQUAL
Definition: excdefs.hxx:51
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:319
#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:794
SC_DLLPUBLIC bool CreateQueryParam(const ScRange &rRange, ScQueryParam &rQueryParam)
Definition: documen3.cxx:1463
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:276
void Scenman()
Definition: excimp8.cxx:218
StorageRef openSubStorage(const OUString &rStorageName, bool bCreateMissing)
SCTAB nBdshtTab
Definition: imp_op.hxx:112
std::shared_ptr< StorageBase > StorageRef
SC_DLLPUBLIC void ApplyAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, const SfxPoolItem &rAttr)
Definition: document.cxx:4757
ScfUInt32Vec maSheetOffsets
Definition: imp_op.hxx:93
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:901
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:781
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:381
sal_uInt16 sal_Unicode
void FilterMode()
Definition: excimp8.cxx:429
ScDocument & rD
Definition: imp_op.hxx:47
SC_DLLPUBLIC bool RenameTab(SCTAB nTab, const OUString &rName, bool bExternalDocument=false)
Definition: document.cxx:853
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:1921
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
static void ExcelQueryToOooQuery(OUString &aStr, ScQueryEntry &rEntry)
Definition: excimp8.cxx:521
const sal_uInt8 EXC_AFOPER_EQUAL
Definition: excdefs.hxx:50
void ImportCustomToolBar(SfxObjectShell &rDocSh)
Definition: xltoolbar.cxx:388
virtual void PostDocLoad()
Definition: impop.cxx:1232
SC_DLLPUBLIC bool HasTable(SCTAB nTab) const
Definition: document.cxx:191
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:185
SC_DLLPUBLIC const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich) const
Definition: document.cxx:4714
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:1536
void SetCalcAsShown(bool bVal)
Definition: docoptio.hxx:83
SC_DLLPUBLIC const ScDocOptions & GetDocOptions() const
Definition: documen3.cxx:1923
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:374
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:97
std::unique_ptr< ExcelToSc > pFormConv
Visible range if embedded.
Definition: imp_op.hxx:96
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:392
XclImpAddressConverter & GetAddressConverter() const
Returns the address converter.
Definition: xiroot.cxx:119
XclImpAutoFilterData(RootData *pRoot, const ScRange &rRange)
Definition: excimp8.cxx:463
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:454
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:74
RootData * pExcRoot
Definition: root.hxx:75
void SetExtractPos(const ScAddress &rAddr)
Definition: excimp8.cxx:731
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:161
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:807
std::vector< std::unique_ptr< ExcScenario > > aEntries
Definition: excscen.hxx:68
static SC_DLLPUBLIC const LocaleDataWrapper * getLocaleDataPtr()
Definition: global.cxx:1002
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:1929
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:767
SC_DLLPUBLIC void UpdateChartListenerCollection()
Definition: documen5.cxx:570
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:787
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:1177
SfxObjectShell * GetDocShell() const
Returns the object shell of the Calc document.
Definition: xlroot.cxx:281
SC_DLLPUBLIC void MakeTable(SCTAB nTab, bool _bNeedsNameCheck=true)
Definition: document.cxx:168
osl::Mutex m_aMutex
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:91
void ReadAutoFilter(XclImpStream &rStrm, svl::SharedStringPool &rPool)
Definition: excimp8.cxx:550
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:169
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:720
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:839
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