LibreOffice Module sc (master)  1
xicontent.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 <com/sun/star/sheet/TableValidationVisibility.hpp>
21 #include <xicontent.hxx>
22 #include <sfx2/objsh.hxx>
23 #include <sfx2/docfile.hxx>
24 #include <tools/urlobj.hxx>
25 #include <sfx2/linkmgr.hxx>
26 #include <svl/itemset.hxx>
27 #include <scitems.hxx>
28 #include <editeng/eeitem.hxx>
29 #include <svl/intitem.hxx>
30 #include <svl/stritem.hxx>
31 #include <editeng/flditem.hxx>
32 #include <editeng/editobj.hxx>
33 #include <unotools/charclass.hxx>
34 #include <stringutil.hxx>
35 #include <cellform.hxx>
36 #include <cellvalue.hxx>
37 #include <document.hxx>
38 #include <editutil.hxx>
39 #include <validat.hxx>
40 #include <patattr.hxx>
41 #include <docpool.hxx>
42 #include <rangenam.hxx>
43 #include <arealink.hxx>
44 #include <stlsheet.hxx>
45 #include <xlcontent.hxx>
46 #include <xlformula.hxx>
47 #include <xltracer.hxx>
48 #include <xistream.hxx>
49 #include <xihelper.hxx>
50 #include <xistyle.hxx>
51 #include <xiescher.hxx>
52 #include <xiname.hxx>
53 
54 #include <excform.hxx>
55 #include <tabprotection.hxx>
56 #include <documentimport.hxx>
57 
58 #include <memory>
59 #include <utility>
60 #include <oox/helper/helper.hxx>
61 #include <sal/log.hxx>
62 
63 using ::com::sun::star::uno::Sequence;
64 using ::std::unique_ptr;
65 
66 // Shared string table ========================================================
67 
69  XclImpRoot( rRoot )
70 {
71 }
72 
74 {
75  rStrm.Ignore( 4 );
76  sal_uInt32 nStrCount = rStrm.ReaduInt32();
77  auto nBytesAvailable = rStrm.GetRecLeft();
78  if (nStrCount > nBytesAvailable)
79  {
80  SAL_WARN("sc.filter", "xls claimed to have " << nStrCount << " strings, but only " << nBytesAvailable << " bytes available, truncating");
81  nStrCount = nBytesAvailable;
82  }
83  maStrings.clear();
84  maStrings.reserve(nStrCount);
85  while( (nStrCount > 0) && rStrm.IsValid() )
86  {
87  XclImpString aString;
88  aString.Read( rStrm );
89  maStrings.push_back( aString );
90  --nStrCount;
91  }
92 }
93 
94 const XclImpString* XclImpSst::GetString( sal_uInt32 nSstIndex ) const
95 {
96  return (nSstIndex < maStrings.size()) ? &maStrings[ nSstIndex ] : nullptr;
97 }
98 
99 // Hyperlinks =================================================================
100 
101 namespace {
102 
106 void lclAppendString32( OUString& rString, XclImpStream& rStrm, sal_uInt32 nChars, bool b16Bit )
107 {
108  sal_uInt16 nReadChars = ulimit_cast< sal_uInt16 >( nChars );
109  rString += rStrm.ReadRawUniString( nReadChars, b16Bit );
110  // ignore remaining chars
111  std::size_t nIgnore = nChars - nReadChars;
112  if( b16Bit )
113  nIgnore *= 2;
114  rStrm.Ignore( nIgnore );
115 }
116 
119 void lclAppendString32( OUString& rString, XclImpStream& rStrm, bool b16Bit )
120 {
121  lclAppendString32( rString, rStrm, rStrm.ReaduInt32(), b16Bit );
122 }
123 
125 void lclIgnoreString32( XclImpStream& rStrm )
126 {
127  sal_uInt32 nChars = rStrm.ReaduInt32();
128  nChars *= 2;
129  rStrm.Ignore( nChars );
130 }
131 
135 void lclGetAbsPath( OUString& rPath, sal_uInt16 nLevel, const SfxObjectShell* pDocShell )
136 {
137  OUStringBuffer aTmpStr;
138  while( nLevel )
139  {
140  aTmpStr.append( "../" );
141  --nLevel;
142  }
143  aTmpStr.append( rPath );
144 
145  if( pDocShell )
146  {
147  bool bWasAbs = false;
148  rPath = pDocShell->GetMedium()->GetURLObject().smartRel2Abs( aTmpStr.makeStringAndClear(), bWasAbs ).GetMainURL( INetURLObject::DecodeMechanism::NONE );
149  // full path as stored in SvxURLField must be encoded
150  }
151  else
152  rPath = aTmpStr.makeStringAndClear();
153 }
154 
156 void lclInsertUrl( XclImpRoot& rRoot, const OUString& rUrl, SCCOL nScCol, SCROW nScRow, SCTAB nScTab )
157 {
158  ScDocumentImport& rDoc = rRoot.GetDocImport();
159  ScAddress aScPos( nScCol, nScRow, nScTab );
160  ScRefCellValue aCell(rDoc.getDoc(), aScPos);
161  switch( aCell.meType )
162  {
163  // #i54261# hyperlinks in string cells
164  case CELLTYPE_STRING:
165  case CELLTYPE_EDIT:
166  {
167  sal_uInt32 nNumFmt = rDoc.getDoc().GetNumberFormat(rDoc.getDoc().GetNonThreadedContext(), aScPos);
168  SvNumberFormatter* pFormatter = rDoc.getDoc().GetFormatTable();
169  const Color* pColor;
170  OUString aDisplText;
171  ScCellFormat::GetString(aCell, nNumFmt, aDisplText, &pColor, *pFormatter, rDoc.getDoc());
172  if (aDisplText.isEmpty())
173  aDisplText = rUrl;
174 
175  ScEditEngineDefaulter& rEE = rRoot.GetEditEngine();
176  SvxURLField aUrlField( rUrl, aDisplText, SvxURLFormat::AppDefault );
177 
178  if( aCell.meType == CELLTYPE_EDIT )
179  {
180  const EditTextObject* pEditObj = aCell.mpEditText;
181  rEE.SetTextCurrentDefaults( *pEditObj );
182  rEE.QuickInsertField( SvxFieldItem( aUrlField, EE_FEATURE_FIELD ), ESelection( 0, 0, EE_PARA_ALL, 0 ) );
183  }
184  else
185  {
187  rEE.QuickInsertField( SvxFieldItem( aUrlField, EE_FEATURE_FIELD ), ESelection() );
188  if( const ScPatternAttr* pPattern = rDoc.getDoc().GetPattern( aScPos.Col(), aScPos.Row(), nScTab ) )
189  {
190  SfxItemSet aItemSet( rEE.GetEmptyItemSet() );
191  pPattern->FillEditItemSet( &aItemSet );
192  rEE.QuickSetAttribs( aItemSet, ESelection( 0, 0, EE_PARA_ALL, 0 ) );
193  }
194  }
195 
196  // The cell will own the text object instance.
197  rDoc.setEditCell(aScPos, rEE.CreateTextObject());
198  }
199  break;
200 
201  default:
202  // Handle other cell types e.g. formulas ( and ? ) that have associated
203  // hyperlinks.
204  // Ideally all hyperlinks should be treated as below. For the moment,
205  // given the current absence of ods support lets just handle what we
206  // previously didn't handle the new way.
207  // Unfortunately we won't be able to preserve such hyperlinks when
208  // saving to ods. Note: when we are able to save such hyperlinks to ods
209  // we should handle *all* imported hyperlinks as below ( e.g. as cell
210  // attribute ) for better interoperability.
211  {
212  SfxStringItem aItem( ATTR_HYPERLINK, rUrl );
213  rDoc.getDoc().ApplyAttr(nScCol, nScRow, nScTab, aItem);
214  break;
215  }
216  }
217 }
218 
219 } // namespace
220 
222 {
223  XclRange aXclRange( ScAddress::UNINITIALIZED );
224  rStrm >> aXclRange;
225  // #i80006# Excel silently ignores invalid hi-byte of column index (TODO: everywhere?)
226  aXclRange.maFirst.mnCol &= 0xFF;
227  aXclRange.maLast.mnCol &= 0xFF;
228  OUString aString = ReadEmbeddedData( rStrm );
229  if ( !aString.isEmpty() )
230  rStrm.GetRoot().GetXFRangeBuffer().SetHyperlink( aXclRange, aString );
231 }
232 
234 {
235  const XclImpRoot& rRoot = rStrm.GetRoot();
236  SfxObjectShell* pDocShell = rRoot.GetDocShell();
237 
238  OSL_ENSURE_BIFF( rRoot.GetBiff() == EXC_BIFF8 );
239 
240  XclGuid aGuid;
241  rStrm >> aGuid;
242  rStrm.Ignore( 4 );
243  sal_uInt32 nFlags = rStrm.ReaduInt32();
244 
245  OSL_ENSURE( aGuid == XclTools::maGuidStdLink, "XclImpHyperlink::ReadEmbeddedData - unknown header GUID" );
246 
247  ::std::unique_ptr< OUString > xLongName; // link / file name
248  ::std::unique_ptr< OUString > xShortName; // 8.3-representation of file name
249  ::std::unique_ptr< OUString > xTextMark; // text mark
250 
251  // description (ignore)
252  if( ::get_flag( nFlags, EXC_HLINK_DESCR ) )
253  lclIgnoreString32( rStrm );
254  // target frame (ignore) !! DESCR/FRAME - is this the right order? (never seen them together)
255  if( ::get_flag( nFlags, EXC_HLINK_FRAME ) )
256  lclIgnoreString32( rStrm );
257 
258  // URL fields are zero-terminated - do not let the stream replace them
259  // in the lclAppendString32() with the '?' character.
260  rStrm.SetNulSubstChar( '\0' );
261 
262  // UNC path
263  if( ::get_flag( nFlags, EXC_HLINK_UNC ) )
264  {
265  xLongName.reset( new OUString );
266  lclAppendString32( *xLongName, rStrm, true );
267  lclGetAbsPath( *xLongName, 0, pDocShell );
268  }
269  // file link or URL
270  else if( ::get_flag( nFlags, EXC_HLINK_BODY ) )
271  {
272  rStrm >> aGuid;
273 
274  if( aGuid == XclTools::maGuidFileMoniker )
275  {
276  sal_uInt16 nLevel = rStrm.ReaduInt16(); // counter for level to climb down in path
277  xShortName.reset( new OUString );
278  lclAppendString32( *xShortName, rStrm, false );
279  rStrm.Ignore( 24 );
280 
281  sal_uInt32 nStrLen = rStrm.ReaduInt32();
282  if( nStrLen )
283  {
284  nStrLen = rStrm.ReaduInt32();
285  nStrLen /= 2; // it's byte count here...
286  rStrm.Ignore( 2 );
287  xLongName.reset( new OUString );
288  lclAppendString32( *xLongName, rStrm, nStrLen, true );
289  lclGetAbsPath( *xLongName, nLevel, pDocShell );
290  }
291  else
292  lclGetAbsPath( *xShortName, nLevel, pDocShell );
293  }
294  else if( aGuid == XclTools::maGuidUrlMoniker )
295  {
296  sal_uInt32 nStrLen = rStrm.ReaduInt32();
297  nStrLen /= 2; // it's byte count here...
298  xLongName.reset( new OUString );
299  lclAppendString32( *xLongName, rStrm, nStrLen, true );
300  if( !::get_flag( nFlags, EXC_HLINK_ABS ) )
301  lclGetAbsPath( *xLongName, 0, pDocShell );
302  }
303  else
304  {
305  OSL_FAIL( "XclImpHyperlink::ReadEmbeddedData - unknown content GUID" );
306  }
307  }
308 
309  // text mark
310  if( ::get_flag( nFlags, EXC_HLINK_MARK ) )
311  {
312  xTextMark.reset( new OUString );
313  lclAppendString32( *xTextMark, rStrm, true );
314  }
315 
316  rStrm.SetNulSubstChar(); // back to default
317 
318  OSL_ENSURE( rStrm.GetRecLeft() == 0, "XclImpHyperlink::ReadEmbeddedData - record size mismatch" );
319 
320  if (!xLongName && xShortName)
321  xLongName = std::move(xShortName);
322  else if (!xLongName && xTextMark)
323  xLongName.reset( new OUString );
324 
325  if (xLongName)
326  {
327  if (xTextMark)
328  {
329  if( xLongName->isEmpty() )
330  {
331  sal_Int32 nSepPos = xTextMark->lastIndexOf( '!' );
332  if( nSepPos > 0 )
333  {
334  // Do not attempt to blindly convert '#SheetName!A1' to
335  // '#SheetName.A1', it can be #SheetName!R1C1 as well.
336  // Hyperlink handler has to handle all, but prefer
337  // '#SheetName.A1' if possible.
338  if (nSepPos < xTextMark->getLength() - 1)
339  {
340  ScDocument& rDoc = rRoot.GetDoc();
341  ScRange aRange;
342  if ((aRange.ParseAny( xTextMark->copy( nSepPos + 1 ), rDoc, formula::FormulaGrammar::CONV_XL_R1C1)
344  xTextMark.reset( new OUString( xTextMark->replaceAt( nSepPos, 1, OUString( '.' ))));
345  }
346  }
347  }
348  xLongName.reset( new OUString( *xLongName + "#" + *xTextMark ) );
349  }
350  return( *xLongName );
351  }
352  return( OUString() );
353 }
354 
356 {
357  sal_Int32 n = rUrl.getLength();
358  if (n < 4)
359  // Needs at least 4 characters.
360  return;
361 
362  if (rUrl[0] != '#')
363  // the 1st character must be '#'.
364  return;
365 
366  OUStringBuffer aNewUrl("#");
367  OUStringBuffer aTabName;
368 
369  bool bInQuote = false;
370  bool bQuoteTabName = false;
371  for( sal_Int32 i = 1; i < n; ++i )
372  {
373  sal_Unicode c = rUrl[i];
374  if (c == '\'')
375  {
376  if (bInQuote && i+1 < n && rUrl[i+1] == '\'')
377  {
378  // Two consecutive single quotes ('') signify a single literal
379  // quite. When this occurs, the whole table name needs to be
380  // quoted.
381  bQuoteTabName = true;
382  aTabName.append(c).append(c);
383  ++i;
384  continue;
385  }
386 
387  bInQuote = !bInQuote;
388  if (!bInQuote && !aTabName.isEmpty())
389  {
390  if (bQuoteTabName)
391  aNewUrl.append("'");
392  aNewUrl.append(aTabName);
393  if (bQuoteTabName)
394  aNewUrl.append("'");
395  }
396  }
397  else if (bInQuote)
398  aTabName.append(c);
399  else
400  aNewUrl.append(c);
401  }
402 
403  if (bInQuote)
404  // It should be outside the quotes!
405  return;
406 
407  // All is good. Pass the new URL.
408  rUrl = aNewUrl.makeStringAndClear();
409 }
410 
411 void XclImpHyperlink::InsertUrl( XclImpRoot& rRoot, const XclRange& rXclRange, const OUString& rUrl )
412 {
413  OUString aUrl(rUrl);
414  ConvertToValidTabName(aUrl);
415 
416  SCTAB nScTab = rRoot.GetCurrScTab();
417  ScRange aScRange( ScAddress::UNINITIALIZED );
418  if( rRoot.GetAddressConverter().ConvertRange( aScRange, rXclRange, nScTab, nScTab, true ) )
419  {
420  SCCOL nScCol1, nScCol2;
421  SCROW nScRow1, nScRow2;
422  aScRange.GetVars( nScCol1, nScRow1, nScTab, nScCol2, nScRow2, nScTab );
423  for( SCCOL nScCol = nScCol1; nScCol <= nScCol2; ++nScCol )
424  for( SCROW nScRow = nScRow1; nScRow <= nScRow2; ++nScRow )
425  lclInsertUrl( rRoot, aUrl, nScCol, nScRow, nScTab );
426  }
427 }
428 
429 // Label ranges ===============================================================
430 
432 {
433  const XclImpRoot& rRoot = rStrm.GetRoot();
434  OSL_ENSURE_BIFF( rRoot.GetBiff() == EXC_BIFF8 );
435 
436  ScDocument& rDoc = rRoot.GetDoc();
437  SCTAB nScTab = rRoot.GetCurrScTab();
438  XclImpAddressConverter& rAddrConv = rRoot.GetAddressConverter();
439  ScRangePairListRef xLabelRangesRef;
440 
441  XclRangeList aRowXclRanges, aColXclRanges;
442  rStrm >> aRowXclRanges >> aColXclRanges;
443 
444  // row label ranges
445  ScRangeList aRowScRanges;
446  rAddrConv.ConvertRangeList( aRowScRanges, aRowXclRanges, nScTab, false );
447  xLabelRangesRef = rDoc.GetRowNameRangesRef();
448  for ( size_t i = 0, nRanges = aRowScRanges.size(); i < nRanges; ++i )
449  {
450  const ScRange & rScRange = aRowScRanges[ i ];
451  ScRange aDataRange( rScRange );
452  if( aDataRange.aEnd.Col() < rDoc.MaxCol() )
453  {
454  aDataRange.aStart.SetCol( aDataRange.aEnd.Col() + 1 );
455  aDataRange.aEnd.SetCol( rDoc.MaxCol() );
456  }
457  else if( aDataRange.aStart.Col() > 0 )
458  {
459  aDataRange.aEnd.SetCol( aDataRange.aStart.Col() - 1 );
460  aDataRange.aStart.SetCol( 0 );
461  }
462  xLabelRangesRef->Append( ScRangePair( rScRange, aDataRange ) );
463  }
464 
465  // column label ranges
466  ScRangeList aColScRanges;
467  rAddrConv.ConvertRangeList( aColScRanges, aColXclRanges, nScTab, false );
468  xLabelRangesRef = rDoc.GetColNameRangesRef();
469 
470  for ( size_t i = 0, nRanges = aColScRanges.size(); i < nRanges; ++i )
471  {
472  const ScRange & rScRange = aColScRanges[ i ];
473  ScRange aDataRange( rScRange );
474  if( aDataRange.aEnd.Row() < rDoc.MaxRow() )
475  {
476  aDataRange.aStart.SetRow( aDataRange.aEnd.Row() + 1 );
477  aDataRange.aEnd.SetRow( rDoc.MaxRow() );
478  }
479  else if( aDataRange.aStart.Row() > 0 )
480  {
481  aDataRange.aEnd.SetRow( aDataRange.aStart.Row() - 1 );
482  aDataRange.aStart.SetRow( 0 );
483  }
484  xLabelRangesRef->Append( ScRangePair( rScRange, aDataRange ) );
485  }
486 }
487 
488 // Conditional formatting =====================================================
489 
490 XclImpCondFormat::XclImpCondFormat( const XclImpRoot& rRoot, sal_uInt32 nFormatIndex ) :
491  XclImpRoot( rRoot ),
492  mnFormatIndex( nFormatIndex ),
493  mnCondCount( 0 ),
494  mnCondIndex( 0 )
495 {
496 }
497 
499 {
500 }
501 
503 {
504  OSL_ENSURE( !mnCondCount, "XclImpCondFormat::ReadCondfmt - already initialized" );
505  XclRangeList aXclRanges;
506  mnCondCount = rStrm.ReaduInt16();
507  rStrm.Ignore( 10 );
508  rStrm >> aXclRanges;
509  GetAddressConverter().ConvertRangeList( maRanges, aXclRanges, GetCurrScTab(), true );
510 }
511 
513 {
514  if( mnCondIndex >= mnCondCount )
515  {
516  OSL_FAIL( "XclImpCondFormat::ReadCF - CF without leading CONDFMT" );
517  return;
518  }
519 
520  // entire conditional format outside of valid range?
521  if( maRanges.empty() )
522  return;
523 
524  sal_uInt8 nType = rStrm.ReaduInt8();
525  sal_uInt8 nOperator = rStrm.ReaduInt8();
526  sal_uInt16 nFmlaSize1 = rStrm.ReaduInt16();
527  sal_uInt16 nFmlaSize2 = rStrm.ReaduInt16();
528  sal_uInt32 nFlags = rStrm.ReaduInt32();
529  rStrm.Ignore( 2 ); //nFlagsExtended
530 
531  // *** mode and comparison operator ***
532 
534  switch( nType )
535  {
536  case EXC_CF_TYPE_CELL:
537  {
538  switch( nOperator )
539  {
540  case EXC_CF_CMP_BETWEEN: eMode = ScConditionMode::Between; break;
542  case EXC_CF_CMP_EQUAL: eMode = ScConditionMode::Equal; break;
543  case EXC_CF_CMP_NOT_EQUAL: eMode = ScConditionMode::NotEqual; break;
544  case EXC_CF_CMP_GREATER: eMode = ScConditionMode::Greater; break;
545  case EXC_CF_CMP_LESS: eMode = ScConditionMode::Less; break;
547  case EXC_CF_CMP_LESS_EQUAL: eMode = ScConditionMode::EqLess; break;
548  default:
549  SAL_INFO(
550  "sc.filter", "unknown CF comparison " << nOperator);
551  }
552  }
553  break;
554 
555  case EXC_CF_TYPE_FMLA:
556  eMode = ScConditionMode::Direct;
557  break;
558 
559  default:
560  SAL_INFO("sc.filter", "unknown CF mode " << nType);
561  return;
562  }
563 
564  // *** create style sheet ***
565 
567  SfxItemSet& rStyleItemSet = ScfTools::MakeCellStyleSheet( GetStyleSheetPool(), aStyleName, true ).GetItemSet();
568 
569  const XclImpPalette& rPalette = GetPalette();
570 
571  // number format
572 
573  if( get_flag( nFlags, EXC_CF_BLOCK_NUMFMT ) )
574  {
575  XclImpNumFmtBuffer& rNumFmtBuffer = GetRoot().GetNumFmtBuffer();
576  bool bIFmt = get_flag( nFlags, EXC_CF_IFMT_USER );
577  sal_uInt16 nFormat = rNumFmtBuffer.ReadCFFormat( rStrm, bIFmt );
578  rNumFmtBuffer.FillToItemSet( rStyleItemSet, nFormat );
579  }
580 
581  // *** font block ***
582 
583  if( ::get_flag( nFlags, EXC_CF_BLOCK_FONT ) )
584  {
585  XclImpFont aFont( GetRoot() );
586  aFont.ReadCFFontBlock( rStrm );
587  aFont.FillToItemSet( rStyleItemSet, XclFontItemType::Cell );
588  }
589 
590  // alignment
591  if( get_flag( nFlags, EXC_CF_BLOCK_ALIGNMENT ) )
592  {
593  XclImpCellAlign aAlign;
594  sal_uInt16 nAlign(0);
595  sal_uInt16 nAlignMisc(0);
596  nAlign = rStrm.ReaduInt16();
597  nAlignMisc = rStrm.ReaduInt16();
598  aAlign.FillFromCF( nAlign, nAlignMisc );
599  aAlign.FillToItemSet( rStyleItemSet, nullptr );
600  rStrm.Ignore(4);
601  }
602 
603  // *** border block ***
604 
605  if( ::get_flag( nFlags, EXC_CF_BLOCK_BORDER ) )
606  {
607  sal_uInt16 nLineStyle(0);
608  sal_uInt32 nLineColor(0);
609  nLineStyle = rStrm.ReaduInt16();
610  nLineColor = rStrm.ReaduInt32();
611  rStrm.Ignore( 2 );
612 
613  XclImpCellBorder aBorder;
614  aBorder.FillFromCF8( nLineStyle, nLineColor, nFlags );
615  aBorder.FillToItemSet( rStyleItemSet, rPalette );
616  }
617 
618  // *** pattern block ***
619 
620  if( ::get_flag( nFlags, EXC_CF_BLOCK_AREA ) )
621  {
622  sal_uInt16 nPattern(0), nColor(0);
623  nPattern = rStrm.ReaduInt16();
624  nColor = rStrm.ReaduInt16();
625 
626  XclImpCellArea aArea;
627  aArea.FillFromCF8( nPattern, nColor, nFlags );
628  aArea.FillToItemSet( rStyleItemSet, rPalette );
629  }
630 
631  if( get_flag( nFlags, EXC_CF_BLOCK_PROTECTION ) )
632  {
633  sal_uInt16 nCellProt;
634  nCellProt = rStrm.ReaduInt16();
635  XclImpCellProt aCellProt;
636  aCellProt.FillFromXF3(nCellProt);
637  aCellProt.FillToItemSet( rStyleItemSet );
638  }
639 
640  // *** formulas ***
641 
642  const ScAddress& rPos = maRanges.front().aStart; // assured above that maRanges is not empty
643  ExcelToSc& rFmlaConv = GetOldFmlaConverter();
644 
645  ::std::unique_ptr< ScTokenArray > xTokArr1;
646  if( nFmlaSize1 > 0 )
647  {
648  std::unique_ptr<ScTokenArray> pTokArr;
649  rFmlaConv.Reset( rPos );
650  rFmlaConv.Convert( pTokArr, rStrm, nFmlaSize1, false, FT_CondFormat );
651  // formula converter owns pTokArr -> create a copy of the token array
652  if( pTokArr )
653  {
654  xTokArr1 = std::move( pTokArr );
655  GetDoc().CheckLinkFormulaNeedingCheck( *xTokArr1);
656  }
657  }
658 
659  ::std::unique_ptr< ScTokenArray > xTokArr2;
660  if( nFmlaSize2 > 0 )
661  {
662  std::unique_ptr<ScTokenArray> pTokArr;
663  rFmlaConv.Reset( rPos );
664  rFmlaConv.Convert( pTokArr, rStrm, nFmlaSize2, false, FT_CondFormat );
665  // formula converter owns pTokArr -> create a copy of the token array
666  if( pTokArr )
667  {
668  xTokArr2 = std::move( pTokArr );
669  GetDoc().CheckLinkFormulaNeedingCheck( *xTokArr2);
670  }
671  }
672 
673  // *** create the Calc conditional formatting ***
674 
675  const ScAddress aPos(rPos); //in case maRanges.Join invalidates it
676 
677  if( !mxScCondFmt )
678  {
679  mxScCondFmt.reset( new ScConditionalFormat( 0/*nKey*/, &GetDoc() ) );
680  if(maRanges.size() > 1)
681  maRanges.Join(maRanges[0], true);
682  mxScCondFmt->SetRange(maRanges);
683  }
684 
685  ScCondFormatEntry* pEntry = new ScCondFormatEntry(eMode, xTokArr1.get(), xTokArr2.get(), GetDoc(), aPos, aStyleName);
686  mxScCondFmt->AddEntry( pEntry );
687  ++mnCondIndex;
688 }
689 
691 {
692  if( mxScCondFmt )
693  {
694  ScDocument& rDoc = GetDoc();
695 
696  SCTAB nTab = maRanges.front().aStart.Tab();
697  sal_uLong nKey = rDoc.AddCondFormat( mxScCondFmt->Clone(), nTab );
698 
699  rDoc.AddCondFormatData( maRanges, nTab, nKey );
700  }
701 }
702 
704  XclImpRoot( rRoot )
705 {
706 }
707 
709 {
710  XclImpCondFormat* pFmt = new XclImpCondFormat( GetRoot(), maCondFmtList.size() );
711  pFmt->ReadCondfmt( rStrm );
712  maCondFmtList.push_back( std::unique_ptr<XclImpCondFormat>(pFmt) );
713 }
714 
716 {
717  OSL_ENSURE( !maCondFmtList.empty(), "XclImpCondFormatManager::ReadCF - CF without leading CONDFMT" );
718  if( !maCondFmtList.empty() )
719  maCondFmtList.back()->ReadCF( rStrm );
720 }
721 
723 {
724  for( auto& rxFmt : maCondFmtList )
725  rxFmt->Apply();
726  maCondFmtList.clear();
727 }
728 
729 // Data Validation ============================================================
730 
732  maRanges(rRanges), maValidData(rValidData) {}
733 
735  XclImpRoot( rRoot )
736 {
737 }
738 
740 {
741  const XclImpRoot& rRoot = rStrm.GetRoot();
742  OSL_ENSURE_BIFF( rRoot.GetBiff() == EXC_BIFF8 );
743 
744  sal_uInt32 nObjId(0);
745  rStrm.Ignore( 10 );
746  nObjId = rStrm.ReaduInt32();
747  if( nObjId != EXC_DVAL_NOOBJ )
748  {
749  OSL_ENSURE( nObjId <= 0xFFFF, "XclImpValidation::ReadDval - invalid object ID" );
750  rRoot.GetCurrSheetDrawing().SetSkipObj( static_cast< sal_uInt16 >( nObjId ) );
751  }
752 }
753 
755 {
756  const XclImpRoot& rRoot = rStrm.GetRoot();
757  OSL_ENSURE_BIFF( rRoot.GetBiff() == EXC_BIFF8 );
758 
759  ScDocument& rDoc = rRoot.GetDoc();
760  SCTAB nScTab = rRoot.GetCurrScTab();
761  ExcelToSc& rFmlaConv = rRoot.GetOldFmlaConverter();
762 
763  // flags
764  sal_uInt32 nFlags = rStrm.ReaduInt32();
765 
766  // message strings
767  /* Empty strings are single NUL characters in Excel (string length is 1).
768  -> Do not let the stream replace them with '?' characters. */
769  rStrm.SetNulSubstChar( '\0' );
770  OUString aPromptTitle( rStrm.ReadUniString() );
771  OUString aErrorTitle( rStrm.ReadUniString() );
772  OUString aPromptMessage( rStrm.ReadUniString() );
773  OUString aErrorMessage( rStrm.ReadUniString() );
774  rStrm.SetNulSubstChar(); // back to default
775 
776  // formula(s)
777  if ( rStrm.GetRecLeft() <= 8 )
778  // Not enough bytes left in the record. Bail out.
779  return;
780 
781  // first formula
782  // string list is single tStr token with NUL separators -> replace them with LF
783  rStrm.SetNulSubstChar( '\n' );
784  ::std::unique_ptr< ScTokenArray > xTokArr1;
785 
786  // We can't import the formula directly because we need the range
787  sal_uInt16 nLenFormula1 = rStrm.ReaduInt16();
788  rStrm.Ignore( 2 );
789  XclImpStreamPos aPosFormula1;
790  rStrm.StorePosition(aPosFormula1);
791  rStrm.Ignore(nLenFormula1);
792 
793  // second formula
794  ::std::unique_ptr< ScTokenArray > xTokArr2;
795 
796  sal_uInt16 nLenFormula2 = rStrm.ReaduInt16();
797  rStrm.Ignore( 2 );
798  XclImpStreamPos aPosFormula2;
799  rStrm.StorePosition(aPosFormula2);
800  rStrm.Ignore(nLenFormula2);
801 
802  // read all cell ranges
803  XclRangeList aXclRanges;
804  rStrm >> aXclRanges;
805 
806  // convert to Calc range list
807  ScRangeList aScRanges;
808  rRoot.GetAddressConverter().ConvertRangeList( aScRanges, aXclRanges, nScTab, true );
809 
810  // only continue if there are valid ranges
811  if ( aScRanges.empty() )
812  return;
813 
814  ScRange aCombinedRange = aScRanges.Combine();
815 
816  XclImpStreamPos aCurrentPos;
817  rStrm.StorePosition(aCurrentPos);
818  rStrm.RestorePosition(aPosFormula1);
819  if( nLenFormula1 > 0 )
820  {
821  std::unique_ptr<ScTokenArray> pTokArr;
822  rFmlaConv.Reset(aCombinedRange.aStart);
823  rFmlaConv.Convert( pTokArr, rStrm, nLenFormula1, false, FT_CondFormat );
824  // formula converter owns pTokArr -> create a copy of the token array
825  if( pTokArr )
826  xTokArr1 = std::move( pTokArr );
827  }
828  rStrm.SetNulSubstChar(); // back to default
829  if (nLenFormula2 > 0)
830  {
831  rStrm.RestorePosition(aPosFormula2);
832  std::unique_ptr<ScTokenArray> pTokArr;
833  rFmlaConv.Reset(aCombinedRange.aStart);
834  rFmlaConv.Convert( pTokArr, rStrm, nLenFormula2, false, FT_CondFormat );
835  // formula converter owns pTokArr -> create a copy of the token array
836  if( pTokArr )
837  xTokArr2 = std::move( pTokArr );
838  }
839 
840  rStrm.RestorePosition(aCurrentPos);
841 
842  bool bIsValid = true; // valid settings in flags field
843 
844  ScValidationMode eValMode = SC_VALID_ANY;
845  switch( nFlags & EXC_DV_MODE_MASK )
846  {
847  case EXC_DV_MODE_ANY: eValMode = SC_VALID_ANY; break;
848  case EXC_DV_MODE_WHOLE: eValMode = SC_VALID_WHOLE; break;
849  case EXC_DV_MODE_DECIMAL: eValMode = SC_VALID_DECIMAL; break;
850  case EXC_DV_MODE_LIST: eValMode = SC_VALID_LIST; break;
851  case EXC_DV_MODE_DATE: eValMode = SC_VALID_DATE; break;
852  case EXC_DV_MODE_TIME: eValMode = SC_VALID_TIME; break;
853  case EXC_DV_MODE_TEXTLEN: eValMode = SC_VALID_TEXTLEN; break;
854  case EXC_DV_MODE_CUSTOM: eValMode = SC_VALID_CUSTOM; break;
855  default: bIsValid = false;
856  }
857  rRoot.GetTracer().TraceDVType(eValMode == SC_VALID_CUSTOM);
858 
860  switch( nFlags & EXC_DV_COND_MASK )
861  {
862  case EXC_DV_COND_BETWEEN: eCondMode = ScConditionMode::Between; break;
863  case EXC_DV_COND_NOTBETWEEN:eCondMode = ScConditionMode::NotBetween; break;
864  case EXC_DV_COND_EQUAL: eCondMode = ScConditionMode::Equal; break;
865  case EXC_DV_COND_NOTEQUAL: eCondMode = ScConditionMode::NotEqual; break;
866  case EXC_DV_COND_GREATER: eCondMode = ScConditionMode::Greater; break;
867  case EXC_DV_COND_LESS: eCondMode = ScConditionMode::Less; break;
868  case EXC_DV_COND_EQGREATER: eCondMode = ScConditionMode::EqGreater; break;
869  case EXC_DV_COND_EQLESS: eCondMode = ScConditionMode::EqLess; break;
870  default: bIsValid = false;
871  }
872 
873  if ( !bIsValid )
874  // No valid validation found. Bail out.
875  return;
876 
877  // The default value for comparison is _BETWEEN. However, custom
878  // rules are a formula, and thus the comparator should be ignored
879  // and only a true or false from the formula is evaluated. In Calc,
880  // formulas use comparison SC_COND_DIRECT.
881  if( eValMode == SC_VALID_CUSTOM )
882  {
883  eCondMode = ScConditionMode::Direct;
884  }
885 
886  // first range for base address for relative references
887  const ScRange& rScRange = aScRanges.front(); // aScRanges is not empty
888 
889  // process string list of a list validity (convert to list of string tokens)
890  if( xTokArr1 && (eValMode == SC_VALID_LIST) && ::get_flag( nFlags, EXC_DV_STRINGLIST ) )
891  XclTokenArrayHelper::ConvertStringToList(*xTokArr1, rDoc.GetSharedStringPool(), '\n');
892 
893  maDVItems.push_back(
894  std::make_unique<DVItem>(aScRanges, ScValidationData(eValMode, eCondMode, xTokArr1.get(), xTokArr2.get(), rDoc, rScRange.aStart)));
895  DVItem& rItem = *maDVItems.back();
896 
898  rItem.maValidData.SetListType( ::get_flagvalue( nFlags, EXC_DV_SUPPRESSDROPDOWN, css::sheet::TableValidationVisibility::INVISIBLE, css::sheet::TableValidationVisibility::UNSORTED ) );
899 
900  // *** prompt box ***
901  if( !aPromptTitle.isEmpty() || !aPromptMessage.isEmpty() )
902  {
903  // set any text stored in the record
904  rItem.maValidData.SetInput( aPromptTitle, aPromptMessage );
905  if( !::get_flag( nFlags, EXC_DV_SHOWPROMPT ) )
906  rItem.maValidData.ResetInput();
907  }
908 
909  // *** error box ***
910  ScValidErrorStyle eErrStyle = SC_VALERR_STOP;
911  switch( nFlags & EXC_DV_ERROR_MASK )
912  {
913  case EXC_DV_ERROR_WARNING: eErrStyle = SC_VALERR_WARNING; break;
914  case EXC_DV_ERROR_INFO: eErrStyle = SC_VALERR_INFO; break;
915  }
916  // set texts and error style
917  rItem.maValidData.SetError( aErrorTitle, aErrorMessage, eErrStyle );
918  if( !::get_flag( nFlags, EXC_DV_SHOWERROR ) )
919  rItem.maValidData.ResetError();
920 }
921 
923 {
924  ScDocument& rDoc = GetRoot().GetDoc();
925  for (const auto& rxDVItem : maDVItems)
926  {
927  DVItem& rItem = *rxDVItem;
928  // set the handle ID
930  ScPatternAttr aPattern( rDoc.GetPool() );
931  aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALIDDATA, nHandle ) );
932 
933  // apply all ranges
934  for ( size_t i = 0, nRanges = rItem.maRanges.size(); i < nRanges; ++i )
935  {
936  const ScRange & rScRange = rItem.maRanges[ i ];
937  rDoc.ApplyPatternAreaTab( rScRange.aStart.Col(), rScRange.aStart.Row(),
938  rScRange.aEnd.Col(), rScRange.aEnd.Row(), rScRange.aStart.Tab(), aPattern );
939  }
940  }
941  maDVItems.clear();
942 }
943 
944 // Web queries ================================================================
945 
947  maDestRange( rDestRange ),
948  meMode( xlWQUnknown ),
949  mnRefresh( 0 )
950 {
951 }
952 
954 {
955  sal_uInt16 nFlags = rStrm.ReaduInt16();
956  sal_uInt16 nType = ::extract_value< sal_uInt16 >( nFlags, 0, 3 );
957  if( !((nType == EXC_PQRYTYPE_WEBQUERY) && ::get_flag( nFlags, EXC_PQRY_WEBQUERY )) )
958  return;
959 
960  if( ::get_flag( nFlags, EXC_PQRY_TABLES ) )
961  {
964  }
965  else
966  {
969  }
970 }
971 
973 {
974  maURL = rStrm.ReadUniString();
975 }
976 
978 {
979  rStrm.Ignore( 10 );
980  sal_uInt16 nFlags = rStrm.ReaduInt16();
981  rStrm.Ignore( 10 );
982  mnRefresh = rStrm.ReaduInt16();
983 
984  if( ::get_flag( nFlags, EXC_WQSETT_SPECTABLES ) && (meMode == xlWQAllTables) )
986 }
987 
989 {
990  if( meMode != xlWQSpecTables )
991  return;
992 
993  rStrm.Ignore( 4 );
994  OUString aTables( rStrm.ReadUniString() );
995 
996  const sal_Unicode cSep = ';';
997  const OUString aQuotedPairs( "\"\"" );
998  maTables.clear();
999  for ( sal_Int32 nStringIx {aTables.isEmpty() ? -1 : 0}; nStringIx>=0; )
1000  {
1001  OUString aToken( ScStringUtil::GetQuotedToken( aTables, 0, aQuotedPairs, ',', nStringIx ) );
1002  sal_Int32 nTabNum = CharClass::isAsciiNumeric( aToken ) ? aToken.toInt32() : 0;
1003  if( nTabNum > 0 )
1004  maTables = ScGlobal::addToken( maTables, ScfTools::GetNameFromHTMLIndex( static_cast< sal_uInt32 >( nTabNum ) ), cSep );
1005  else
1006  {
1007  ScGlobal::EraseQuotes( aToken, '"', false );
1008  if( !aToken.isEmpty() )
1010  }
1011  }
1012 }
1013 
1014 void XclImpWebQuery::Apply( ScDocument& rDoc, const OUString& rFilterName )
1015 {
1016  if( !maURL.isEmpty() && (meMode != xlWQUnknown) && rDoc.GetDocumentShell() )
1017  {
1019  maURL, rFilterName, EMPTY_OUSTRING, maTables, maDestRange, mnRefresh * 60UL );
1021  maURL, &rFilterName, &maTables );
1022  }
1023 }
1024 
1026  XclImpRoot( rRoot )
1027 {
1028 }
1029 
1031 {
1032  if( GetBiff() == EXC_BIFF8 )
1033  {
1034  rStrm.Ignore( 10 );
1035  OUString aXclName( rStrm.ReadUniString() );
1036 
1037  // #i64794# Excel replaces spaces with underscores
1038  aXclName = aXclName.replaceAll( " ", "_" );
1039 
1040  // find the defined name used in Calc
1041  if( const XclImpName* pName = GetNameManager().FindName( aXclName, GetCurrScTab() ) )
1042  {
1043  if( const ScRangeData* pRangeData = pName->GetScRangeData() )
1044  {
1045  ScRange aRange;
1046  if( pRangeData->IsReference( aRange ) )
1047  maWQList.emplace_back( aRange );
1048  }
1049  }
1050  }
1051  else
1052  {
1053  DBG_ERROR_BIFF();
1054  }
1055 }
1056 
1058 {
1059  if (!maWQList.empty())
1060  maWQList.back().ReadParamqry( rStrm );
1061 }
1062 
1064 {
1065  if (!maWQList.empty())
1066  maWQList.back().ReadWqstring( rStrm );
1067 }
1068 
1070 {
1071  if (!maWQList.empty())
1072  maWQList.back().ReadWqsettings( rStrm );
1073 }
1074 
1076 {
1077  if (!maWQList.empty())
1078  maWQList.back().ReadWqtables( rStrm );
1079 }
1080 
1082 {
1083  ScDocument& rDoc = GetDoc();
1084  for( auto& rQuery : maWQList )
1085  rQuery.Apply( rDoc, EXC_WEBQRY_FILTER );
1086 }
1087 
1088 // Decryption =================================================================
1089 
1090 namespace {
1091 
1092 XclImpDecrypterRef lclReadFilepass5( XclImpStream& rStrm )
1093 {
1094  XclImpDecrypterRef xDecr;
1095  OSL_ENSURE( rStrm.GetRecLeft() == 4, "lclReadFilepass5 - wrong record size" );
1096  if( rStrm.GetRecLeft() == 4 )
1097  {
1098  sal_uInt16 nKey(0), nHash(0);
1099  nKey = rStrm.ReaduInt16();
1100  nHash = rStrm.ReaduInt16();
1101  xDecr = std::make_shared<XclImpBiff5Decrypter>( nKey, nHash );
1102  }
1103  return xDecr;
1104 }
1105 
1106 XclImpDecrypterRef lclReadFilepass8_Standard( XclImpStream& rStrm )
1107 {
1108  XclImpDecrypterRef xDecr;
1109  OSL_ENSURE( rStrm.GetRecLeft() == 48, "lclReadFilepass8 - wrong record size" );
1110  if( rStrm.GetRecLeft() == 48 )
1111  {
1112  std::vector<sal_uInt8> aSalt(16);
1113  std::vector<sal_uInt8> aVerifier(16);
1114  std::vector<sal_uInt8> aVerifierHash(16);
1115  rStrm.Read(aSalt.data(), 16);
1116  rStrm.Read(aVerifier.data(), 16);
1117  rStrm.Read(aVerifierHash.data(), 16);
1118  xDecr = std::make_shared<XclImpBiff8StdDecrypter>(aSalt, aVerifier, aVerifierHash);
1119  }
1120  return xDecr;
1121 }
1122 
1123 XclImpDecrypterRef lclReadFilepass8_Strong(XclImpStream& rStream)
1124 {
1125  //It is possible there are other variants in existence but these
1126  //are the defaults I get with Excel 2013
1127  XclImpDecrypterRef xDecr;
1128 
1130 
1131  info.header.flags = rStream.ReaduInt32();
1133  return xDecr;
1134 
1135  sal_uInt32 nHeaderSize = rStream.ReaduInt32();
1136  sal_uInt32 actualHeaderSize = sizeof(info.header);
1137 
1138  if( nHeaderSize < actualHeaderSize )
1139  return xDecr;
1140 
1141  info.header.flags = rStream.ReaduInt32();
1142  info.header.sizeExtra = rStream.ReaduInt32();
1143  info.header.algId = rStream.ReaduInt32();
1144  info.header.algIdHash = rStream.ReaduInt32();
1145  info.header.keyBits = rStream.ReaduInt32();
1146  info.header.providedType = rStream.ReaduInt32();
1147  info.header.reserved1 = rStream.ReaduInt32();
1148  info.header.reserved2 = rStream.ReaduInt32();
1149 
1150  rStream.Ignore(nHeaderSize - actualHeaderSize);
1151 
1152  info.verifier.saltSize = rStream.ReaduInt32();
1154  return xDecr;
1155  rStream.Read(&info.verifier.salt, sizeof(info.verifier.salt));
1156  rStream.Read(&info.verifier.encryptedVerifier, sizeof(info.verifier.encryptedVerifier));
1157 
1159  if (info.verifier.encryptedVerifierHashSize != RTL_DIGEST_LENGTH_SHA1)
1160  return xDecr;
1162 
1163  // check flags and algorithm IDs, required are AES128 and SHA-1
1165  return xDecr;
1166 
1168  return xDecr;
1169 
1171  return xDecr;
1172 
1173  // hash algorithm ID 0 defaults to SHA-1 too
1174  if (info.header.algIdHash != 0 && info.header.algIdHash != msfilter::ENCRYPT_HASH_SHA1)
1175  return xDecr;
1176 
1177  xDecr = std::make_shared<XclImpBiff8CryptoAPIDecrypter>(
1178  std::vector<sal_uInt8>(info.verifier.salt,
1179  info.verifier.salt + SAL_N_ELEMENTS(info.verifier.salt)),
1180  std::vector<sal_uInt8>(info.verifier.encryptedVerifier,
1182  std::vector<sal_uInt8>(info.verifier.encryptedVerifierHash,
1184 
1185  return xDecr;
1186 }
1187 
1188 XclImpDecrypterRef lclReadFilepass8( XclImpStream& rStrm )
1189 {
1190  XclImpDecrypterRef xDecr;
1191 
1192  sal_uInt16 nMode = rStrm.ReaduInt16();
1193  switch( nMode )
1194  {
1195  case EXC_FILEPASS_BIFF5:
1196  xDecr = lclReadFilepass5( rStrm );
1197  break;
1198 
1199  case EXC_FILEPASS_BIFF8:
1200  {
1201  sal_uInt32 nVersion = rStrm.ReaduInt32();
1202  if (nVersion == msfilter::VERSION_INFO_1997_FORMAT)
1203  {
1204  //A Version structure where Version.vMajor MUST be 0x0001,
1205  //and Version.vMinor MUST be 0x0001.
1206  xDecr = lclReadFilepass8_Standard(rStrm);
1207  }
1208  else if (nVersion == msfilter::VERSION_INFO_2007_FORMAT ||
1210  {
1211  //Version.vMajor MUST be 0x0002, 0x0003 or 0x0004 and
1212  //Version.vMinor MUST be 0x0002.
1213  xDecr = lclReadFilepass8_Strong(rStrm);
1214  }
1215  else
1216  OSL_FAIL("lclReadFilepass8 - unknown BIFF8 encryption sub mode");
1217  }
1218  break;
1219 
1220  default:
1221  OSL_FAIL( "lclReadFilepass8 - unknown encryption mode" );
1222  }
1223 
1224  return xDecr;
1225 }
1226 
1227 } // namespace
1228 
1230 {
1231  XclImpDecrypterRef xDecr;
1232  rStrm.DisableDecryption();
1233 
1234  // read the FILEPASS record and create a new decrypter object
1235  switch( rStrm.GetRoot().GetBiff() )
1236  {
1237  case EXC_BIFF2:
1238  case EXC_BIFF3:
1239  case EXC_BIFF4:
1240  case EXC_BIFF5: xDecr = lclReadFilepass5( rStrm ); break;
1241  case EXC_BIFF8: xDecr = lclReadFilepass8( rStrm ); break;
1242  default: DBG_ERROR_BIFF();
1243  };
1244 
1245  // set decrypter at import stream
1246  rStrm.SetDecrypter( xDecr );
1247 
1248  // request and verify a password (decrypter implements IDocPasswordVerifier)
1249  if( xDecr )
1250  rStrm.GetRoot().RequestEncryptionData( *xDecr );
1251 
1252  // return error code (success, wrong password, etc.)
1253  return xDecr ? xDecr->GetError() : EXC_ENCR_ERROR_UNSUPP_CRYPT;
1254 }
1255 
1256 // Document protection ========================================================
1257 
1259  XclImpRoot( rRoot ),
1260  mnPassHash(0x0000),
1261  mbDocProtect(false),
1262  mbWinProtect(false)
1263 {
1264 }
1265 
1267 {
1268  mbDocProtect = rStrm.ReaduInt16() != 0;
1269 }
1270 
1272 {
1273  mbWinProtect = rStrm.ReaduInt16() != 0;
1274 }
1275 
1277 {
1278  rStrm.EnableDecryption();
1279  mnPassHash = rStrm.ReaduInt16();
1280 }
1281 
1283 {
1284  if (!mbDocProtect && !mbWinProtect)
1285  // Excel requires either the structure or windows protection is set.
1286  // If neither is set then the document is not protected at all.
1287  return;
1288 
1289  unique_ptr<ScDocProtection> pProtect(new ScDocProtection);
1290  pProtect->setProtected(true);
1291 
1292  if (mnPassHash)
1293  {
1294  // 16-bit password hash.
1295  Sequence<sal_Int8> aPass{sal_Int8(mnPassHash >> 8), sal_Int8(mnPassHash & 0xFF)};
1296  pProtect->setPasswordHash(aPass, PASSHASH_XL);
1297  }
1298 
1299  // document protection options
1300  pProtect->setOption(ScDocProtection::STRUCTURE, mbDocProtect);
1301  pProtect->setOption(ScDocProtection::WINDOWS, mbWinProtect);
1302 
1303  GetDoc().SetDocProtection(pProtect.get());
1304 }
1305 
1306 // Sheet Protection ===========================================================
1307 
1309  mbProtected(false),
1310  mnPasswordHash(0x0000),
1311  mnOptions(0x4400)
1312 {
1313 }
1314 
1316  mbProtected(r.mbProtected),
1317  mnPasswordHash(r.mnPasswordHash),
1318  mnOptions(r.mnOptions)
1319 {
1320 }
1321 
1323  XclImpRoot( rRoot )
1324 {
1325 }
1326 
1328 {
1329  if ( rStrm.ReaduInt16() )
1330  {
1331  Sheet* pSheet = GetSheetItem(nTab);
1332  if (pSheet)
1333  pSheet->mbProtected = true;
1334  }
1335 }
1336 
1338 {
1339  // The flag size specifies the size of bytes that follows that stores
1340  // feature data. If -1 it depends on the feature type imported earlier.
1341  // For enhanced protection data, the size is always 4. For the most xls
1342  // documents out there this value is almost always -1.
1343  sal_Int32 nFlagSize = rStrm.ReadInt32();
1344  if (nFlagSize != -1)
1345  return;
1346 
1347  // There are actually 4 bytes to read, but the upper 2 bytes currently
1348  // don't store any bits.
1349  sal_uInt16 nOptions = rStrm.ReaduInt16();
1350 
1351  Sheet* pSheet = GetSheetItem(nTab);
1352  if (pSheet)
1353  pSheet->mnOptions = nOptions;
1354 }
1355 
1357 {
1358  Sheet* pSheet = GetSheetItem(nTab);
1359  if (pSheet)
1360  pSheet->maEnhancedProtections.push_back( rProt);
1361 }
1362 
1364 {
1365  sal_uInt16 nHash = rStrm.ReaduInt16();
1366  Sheet* pSheet = GetSheetItem(nTab);
1367  if (pSheet)
1368  pSheet->mnPasswordHash = nHash;
1369 }
1370 
1372 {
1373  for (const auto& [rTab, rSheet] : maProtectedSheets)
1374  {
1375  if (!rSheet.mbProtected)
1376  // This sheet is (for whatever reason) not protected.
1377  continue;
1378 
1379  unique_ptr<ScTableProtection> pProtect(new ScTableProtection);
1380  pProtect->setProtected(true);
1381 
1382  // 16-bit hash password
1383  const sal_uInt16 nHash = rSheet.mnPasswordHash;
1384  if (nHash)
1385  {
1386  Sequence<sal_Int8> aPass{sal_Int8(nHash >> 8), sal_Int8(nHash & 0xFF)};
1387  pProtect->setPasswordHash(aPass, PASSHASH_XL);
1388  }
1389 
1390  // sheet protection options
1391  const sal_uInt16 nOptions = rSheet.mnOptions;
1392  pProtect->setOption( ScTableProtection::OBJECTS, (nOptions & 0x0001) );
1393  pProtect->setOption( ScTableProtection::SCENARIOS, (nOptions & 0x0002) );
1394  pProtect->setOption( ScTableProtection::FORMAT_CELLS, (nOptions & 0x0004) );
1395  pProtect->setOption( ScTableProtection::FORMAT_COLUMNS, (nOptions & 0x0008) );
1396  pProtect->setOption( ScTableProtection::FORMAT_ROWS, (nOptions & 0x0010) );
1397  pProtect->setOption( ScTableProtection::INSERT_COLUMNS, (nOptions & 0x0020) );
1398  pProtect->setOption( ScTableProtection::INSERT_ROWS, (nOptions & 0x0040) );
1399  pProtect->setOption( ScTableProtection::INSERT_HYPERLINKS, (nOptions & 0x0080) );
1400  pProtect->setOption( ScTableProtection::DELETE_COLUMNS, (nOptions & 0x0100) );
1401  pProtect->setOption( ScTableProtection::DELETE_ROWS, (nOptions & 0x0200) );
1402  pProtect->setOption( ScTableProtection::SELECT_LOCKED_CELLS, (nOptions & 0x0400) );
1403  pProtect->setOption( ScTableProtection::SORT, (nOptions & 0x0800) );
1404  pProtect->setOption( ScTableProtection::AUTOFILTER, (nOptions & 0x1000) );
1405  pProtect->setOption( ScTableProtection::PIVOT_TABLES, (nOptions & 0x2000) );
1406  pProtect->setOption( ScTableProtection::SELECT_UNLOCKED_CELLS, (nOptions & 0x4000) );
1407 
1408  // Enhanced protection containing editable ranges and permissions.
1409  pProtect->setEnhancedProtection( rSheet.maEnhancedProtections);
1410 
1411  // all done. now commit.
1412  GetDoc().SetTabProtection(rTab, pProtect.get());
1413  }
1414 }
1415 
1417 {
1418  ProtectedSheetMap::iterator itr = maProtectedSheets.find(nTab);
1419  if (itr == maProtectedSheets.end())
1420  {
1421  // new sheet
1422  if ( !maProtectedSheets.emplace( nTab, Sheet() ).second )
1423  return nullptr;
1424 
1425  itr = maProtectedSheets.find(nTab);
1426  }
1427 
1428  return &itr->second;
1429 }
1430 
1431 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XclImpWebQueryBuffer(const XclImpRoot &rRoot)
Definition: xicontent.cxx:1025
const sal_uInt32 EXC_DV_COND_NOTBETWEEN
Definition: xlcontent.hxx:126
SC_DLLPUBLIC ScRefFlags ParseAny(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1)
Definition: address.cxx:1766
sal_uInt8 encryptedVerifierHash[comphelper::SHA1_HASH_LENGTH]
void ReadDV(XclImpStream &rStrm)
Reads a DV record and inserts validation data into the document.
Definition: xicontent.cxx:754
static const XclGuid maGuidUrlMoniker
GUID of StdLink (HLINK record).
Definition: xltools.hxx:94
const sal_uInt16 EXC_WQSETT_SPECTABLES
All tables or entire document.
Definition: xlcontent.hxx:176
const sal_uInt32 EXC_DV_MODE_DECIMAL
Definition: xlcontent.hxx:116
void SetNulSubstChar(sal_Unicode cNulSubst= '?')
Sets a replacement character for NUL characters.
Definition: xistream.hxx:431
void ReadParamqry(XclImpStream &rStrm)
Reads a PARAMQRY record and sets data to the web query.
Definition: xicontent.cxx:953
#define DBG_ERROR_BIFF()
Definition: xltools.hxx:31
const sal_uInt32 EXC_DVAL_NOOBJ
Definition: xlcontent.hxx:99
const sal_uInt32 ENCRYPTINFO_CRYPTOAPI
ScDocumentImport & GetDocImport()
Definition: xiroot.cxx:292
void FillFromCF(sal_uInt16 nAlign, sal_uInt16 nMiscAttrib)
Fills this struct with CF record data.
Definition: xistyle.cxx:799
const sal_uInt8 EXC_CF_CMP_LESS
Definition: xlcontent.hxx:67
ScAddress aStart
Definition: address.hxx:500
sal_Int32 ReadInt32()
Definition: xistream.cxx:666
const sal_uInt32 EXC_DV_COND_EQGREATER
Definition: xlcontent.hxx:131
const sal_uInt32 EXC_DV_COND_GREATER
Definition: xlcontent.hxx:129
void ReadWqstring(XclImpStream &rStrm)
Reads a WQSTRING record and sets URL.
Definition: xicontent.cxx:972
void ReadCFFontBlock(XclImpStream &rStrm)
Reads the font block from a CF (conditional format) record.
Definition: xistyle.cxx:279
#define EMPTY_OUSTRING
Definition: global.hxx:214
XclImpNumFmtBuffer & GetNumFmtBuffer() const
Returns the number format buffer.
Definition: xiroot.cxx:151
void ReadProtect(XclImpStream &rStrm, SCTAB nTab)
Definition: xicontent.cxx:1327
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
void ReadQsi(XclImpStream &rStrm)
Reads the QSI record and creates a new web query in the buffer.
Definition: xicontent.cxx:1030
SCROW Row() const
Definition: address.hxx:262
static const XclGuid maGuidFileMoniker
GUID of URL moniker (HLINK record).
Definition: xltools.hxx:95
Stores all data of an Excel font and provides import of FONT records.
Definition: xistyle.hxx:71
Extends the XclCellBorder struct for import.
Definition: xistyle.hxx:287
EncryptionVerifierRC4 verifier
SC_DLLPUBLIC void SetTabProtection(SCTAB nTab, const ScTableProtection *pProtect)
Definition: documen3.cxx:1907
const sal_uInt32 EXC_HLINK_BODY
Definition: xlcontent.hxx:144
const SfxItemSet & GetEmptyItemSet() const
const sal_uInt32 ENCRYPTINFO_AES
signed char sal_Int8
void SetDecrypter(XclImpDecrypterRef const &xDecrypter)
Enables decryption of record contents for the rest of the stream.
Definition: xistream.cxx:506
sheet protection state container
void QuickInsertField(const SvxFieldItem &rFld, const ESelection &rSel)
ScValidErrorStyle
Definition: validat.hxx:51
const sal_uInt32 EXC_HLINK_ABS
Contains file link or URL.
Definition: xlcontent.hxx:145
sal_uIntPtr sal_uLong
void FillToItemSet(SfxItemSet &rItemSet, bool bSkipPoolDefs=false) const
Inserts items representing this protection style into the item set.
Definition: xistyle.cxx:757
XclImpWebQueryMode meMode
Destination range.
Definition: xicontent.hxx:225
const sal_uInt8 EXC_CF_CMP_EQUAL
Definition: xlcontent.hxx:64
const sal_uInt32 VERSION_INFO_2007_FORMAT
const sal_uInt32 EXC_DV_MODE_TIME
Definition: xlcontent.hxx:119
sal_Int64 n
void ReadCondfmt(XclImpStream &rStrm)
Reads a CONDFMT record and starts a new conditional format to be filled from CF records.
Definition: xicontent.cxx:708
bool IsValid() const
Returns record reading state: false = record overread.
Definition: xistream.hxx:352
OUString maTables
Source document URL.
Definition: xicontent.hxx:223
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 Read(XclImpStream &rStrm, XclStrFlags nFlags=XclStrFlags::NONE)
Reads a complete string from the passed stream.
Definition: xistring.cxx:41
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
std::vector< std::unique_ptr< DVItem > > maDVItems
Definition: xicontent.hxx:189
const SfxItemSet & GetItemSet() const
XclImpCondFormat(const XclImpRoot &rRoot, sal_uInt32 nFormatIndex)
Definition: xicontent.cxx:490
const sal_uInt8 EXC_CF_CMP_BETWEEN
Definition: xlcontent.hxx:62
SC_DLLPUBLIC void GetNumberFormat(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt32 &rFormat) const
Definition: document.cxx:3641
const sal_uInt32 EXC_DV_SHOWERROR
Definition: xlcontent.hxx:110
sal_uInt8 salt[SALT_LENGTH]
ScRange Combine() const
Definition: rangelst.cxx:1114
SC_DLLPUBLIC sal_uLong AddCondFormat(std::unique_ptr< ScConditionalFormat > pNew, SCTAB nTab)
Definition: documen4.cxx:705
ScAddress aEnd
Definition: address.hxx:501
void ReadCondfmt(XclImpStream &rStrm)
Reads a CONDFMT record and initializes this conditional format.
Definition: xicontent.cxx:502
const sal_uInt32 EXC_DV_STRINGLIST
Definition: xlcontent.hxx:106
Extends the XclCellArea struct for import.
Definition: xistyle.hxx:325
sal_uInt16 mnCondCount
Index of this conditional format in list.
Definition: xicontent.hxx:143
const sal_uInt32 EXC_DV_COND_NOTEQUAL
Definition: xlcontent.hxx:128
void TraceDVType(bool bType)
Definition: xltracer.cxx:143
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:104
XclAddress maFirst
Definition: xladdress.hxx:60
const sal_uInt8 EXC_CF_CMP_LESS_EQUAL
Definition: xlcontent.hxx:69
void Append(const ScRangePair &rRangePair)
Definition: rangelst.hxx:135
ScDocument & GetDoc() const
Returns reference to the destination document (import) or source document (export).
Definition: xlroot.cxx:276
const sal_uInt32 EXC_DV_COND_LESS
Definition: xlcontent.hxx:130
SC_DLLPUBLIC void ApplyAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, const SfxPoolItem &rAttr)
Definition: document.cxx:4757
Accessor class to ScDocument.
const sal_uInt32 EXC_DV_COND_EQLESS
Definition: xlcontent.hxx:132
void FillToItemSet(SfxItemSet &rItemSet, XclFontItemType eType, bool bSkipPoolDefs=false) const
Fills all font properties to the item set.
Definition: xistyle.cxx:313
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
const sal_uInt32 VERSION_INFO_1997_FORMAT
const sal_uInt32 ENCRYPT_ALGO_RC4
void setEditCell(const ScAddress &rPos, std::unique_ptr< EditTextObject > pEditText)
const sal_uInt32 EXC_DV_COND_BETWEEN
Definition: xlcontent.hxx:125
const sal_uInt16 EXC_PQRYTYPE_WEBQUERY
Source type: ODBC.
Definition: xlcontent.hxx:161
XclImpDocProtectBuffer(const XclImpRoot &rRoot)
Definition: xicontent.cxx:1258
XclImpWebQueryList maWQList
Definition: xicontent.hxx:250
SC_DLLPUBLIC ScDocumentPool * GetPool()
Definition: document.cxx:6061
void SetListType(sal_Int16 nListType)
Definition: validat.hxx:118
sal_uInt16 sal_Unicode
Provides functions to convert Excel cell addresses to Calc cell addresses.
Definition: xihelper.hxx:42
const sal_uInt32 EXC_DV_MODE_DATE
Definition: xlcontent.hxx:118
void ReadWinProtect(XclImpStream &rStrm)
document windows properties protection flag
Definition: xicontent.cxx:1271
SC_DLLPUBLIC void CheckLinkFormulaNeedingCheck(const ScTokenArray &rCode)
Check token array and set link check if ocDde/ocWebservice is contained.
Definition: documen8.cxx:1152
static SC_DLLPUBLIC void EraseQuotes(OUString &rString, sal_Unicode cQuote, bool bUnescapeEmbedded=true)
Erases the character cQuote from rString, if it exists at beginning AND end.
Definition: global.cxx:684
const sal_uInt32 EXC_DV_MODE_CUSTOM
Definition: xlcontent.hxx:121
XclImpPalette & GetPalette() const
Returns the color buffer.
Definition: xiroot.cxx:141
DVItem(const ScRangeList &rRanges, const ScValidationData &rValidData)
Definition: xicontent.cxx:731
static const OUString & GetHTMLTablesName()
Returns the built-in range name for all HTML tables.
Definition: ftools.cxx:287
XclImpSheetProtectBuffer(const XclImpRoot &rRoot)
Definition: xicontent.cxx:1322
MS Excel 4.0.
Definition: xlconst.hxx:35
static const XclGuid maGuidStdLink
Definition: xltools.hxx:93
ReturnType ulimit_cast(Type nValue, ReturnType nMax)
Returns the value, if it is not greater than nMax, otherwise nMax.
Definition: ftools.hxx:51
void FillToItemSet(SfxItemSet &rItemSet, const XclImpPalette &rPalette, bool bSkipPoolDefs=false) const
Inserts a box item representing this border style into the item set.
Definition: xistyle.cxx:977
ScStyleSheetPool & GetStyleSheetPool() const
Returns the style sheet pool of the Calc document.
Definition: xlroot.cxx:297
const sal_uInt8 EXC_CF_TYPE_CELL
Definition: xlcontent.hxx:58
void ReadWqtables(XclImpStream &rStrm)
Reads a WEBQRYTABLES record and sets source range list.
Definition: xicontent.cxx:988
void StorePosition(XclImpStreamPos &rPos)
Stores current stream position into rPos.
Definition: xistream.cxx:961
sal_uInt32 mnFormatIndex
Calc conditional format.
Definition: xicontent.hxx:142
void SetHyperlink(const XclRange &rXclRange, const OUString &rUrl)
Inserts a range of hyperlink cells.
Definition: xistyle.cxx:1968
XclImpSst(const XclImpRoot &rRoot)
Definition: xicontent.cxx:68
ExcelToSc & GetOldFmlaConverter() const
Returns the old formula converter.
Definition: xiroot.cxx:129
void SetInput(const OUString &rTitle, const OUString &rMsg)
Definition: validat.cxx:160
Extends the XclCellProt struct for import.
Definition: xistyle.hxx:251
ScConditionMode
Definition: conditio.hxx:61
Mode eMode
SCTAB Tab() const
Definition: address.hxx:271
void SetRow(SCROW nRowP)
Definition: address.hxx:275
sal_uInt16 mnCondIndex
Number of conditions to be inserted.
Definition: xicontent.hxx:144
const sal_uInt32 EXC_CF_BLOCK_AREA
Border block present?
Definition: xlcontent.hxx:85
EncryptionStandardHeader header
sal_uInt16 ReadCFFormat(XclImpStream &rStrm, bool bIFmt)
Read NumFmt from conditional format record.
Definition: xistyle.cxx:677
void ReadWqtables(XclImpStream &rStrm)
Reads a WEBQRYTABLES record and sets source range list to the current web query.
Definition: xicontent.cxx:1075
static OUString GetNameFromHTMLIndex(sal_uInt32 nIndex)
Returns the built-in range name for an HTML table, specified by table index.
Definition: ftools.cxx:306
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:4735
void SetCol(SCCOL nColP)
Definition: address.hxx:279
ScRangeList maRanges
Definition: xicontent.hxx:140
ColorMode meMode
ScValidationMode
Definition: validat.hxx:39
sal_Int32 nHandle
void ReadWqsettings(XclImpStream &rStrm)
Reads a WEBQRYSETTINGS record and sets refresh rate to the current web query.
Definition: xicontent.cxx:1069
bool getFlag(Type nBitField, Type nMask)
const sal_uInt16 EXC_FILEPASS_BIFF5
Definition: xlcontent.hxx:40
Sheet * GetSheetItem(SCTAB nTab)
Definition: xicontent.cxx:1416
const sal_uInt16 EXC_PQRY_WEBQUERY
ODBC connection.
Definition: xlcontent.hxx:163
Extends the XclCellAlign struct for import.
Definition: xistyle.hxx:265
void DisableDecryption()
Switches usage of current decryption algorithm off.
Definition: xistream.hxx:335
void InsertFileLink(sfx2::SvBaseLink &, SvBaseLinkObjectType nFileType, const OUString &rFileNm, const OUString *pFilterNm=nullptr, const OUString *pRange=nullptr)
bool empty() const
Definition: rangelst.hxx:89
#define SAL_N_ELEMENTS(arr)
const sal_uInt32 EXC_DV_MODE_LIST
Definition: xlcontent.hxx:117
const sal_uInt32 EXC_CF_BLOCK_BORDER
Alignment block present?
Definition: xlcontent.hxx:84
const sal_uInt32 SALT_LENGTH
constexpr TypedWhichId< SfxUInt32Item > ATTR_VALIDDATA(153)
const sal_uInt32 ENCRYPTINFO_EXTERNAL
const sal_uInt32 EXC_CF_BLOCK_PROTECTION
Pattern block present?
Definition: xlcontent.hxx:86
void ReadPasswordHash(XclImpStream &rStrm)
Definition: xicontent.cxx:1276
const sal_uInt32 ENCRYPT_HASH_SHA1
sal_uInt16 char * pName
Definition: callform.cxx:58
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:438
void FillToItemSet(SfxItemSet &rItemSet, const XclImpPalette &rPalette, bool bSkipPoolDefs=false) const
Inserts a brush item representing this area style into the item set.
Definition: xistyle.cxx:1073
static const ErrCode & ReadFilepass(XclImpStream &rStrm)
Reads the FILEPASS record, queries a password and sets decryption algorithm.
Definition: xicontent.cxx:1229
void FillFromCF8(sal_uInt16 nLineStyle, sal_uInt32 nLineColor, sal_uInt32 nFlags)
Fills this struct with BIFF8 CF (conditional format) record data.
Definition: xistyle.cxx:913
MS Excel 5.0, MS Excel 7.0 (95)
Definition: xlconst.hxx:36
const sal_uInt8 EXC_CF_CMP_GREATER_EQUAL
Definition: xlcontent.hxx:68
OUString ReadRawUniString(sal_uInt16 nChars, bool b16Bit)
Reads nChars characters and returns the string.
Definition: xistream.cxx:832
void SetTextCurrentDefaults(const EditTextObject &rTextObject)
SetText and apply defaults already set.
Definition: editutil.cxx:559
XclImpStringVec maStrings
Definition: xicontent.hxx:70
const sal_uInt16 EXC_PQRY_TABLES
Web query.
Definition: xlcontent.hxx:164
int i
void FillToItemSet(SfxItemSet &rItemSet, const XclImpFont *pFont, bool bSkipPoolDefs=false) const
Inserts items representing this alignment style into the item set.
Definition: xistyle.cxx:810
std::shared_ptr< XclImpDecrypter > XclImpDecrypterRef
Definition: xistream.hxx:41
sal_Int16 SCCOL
Definition: types.hxx:22
const sal_uInt32 EXC_DV_ERROR_WARNING
Definition: xlcontent.hxx:137
const sal_uInt32 EXC_CF_BLOCK_NUMFMT
Default flags.
Definition: xlcontent.hxx:81
XclImpValidationManager(const XclImpRoot &rRoot)
Definition: xicontent.cxx:734
ProtectedSheetMap maProtectedSheets
Definition: xicontent.hxx:328
const sal_uInt32 EXC_DV_MODE_TEXTLEN
Definition: xlcontent.hxx:120
const sal_uInt32 EXC_CF_BLOCK_FONT
Font block present?
Definition: xlcontent.hxx:82
XclImpAddressConverter & GetAddressConverter() const
Returns the address converter.
Definition: xiroot.cxx:119
const sal_uInt32 EXC_CF_IFMT_USER
Protection block present?
Definition: xlcontent.hxx:87
A 2D cell range address list with Excel column and row indexes.
Definition: xladdress.hxx:101
std::unique_ptr< EditTextObject > CreateTextObject()
size_t size() const
Definition: rangelst.hxx:90
void ReadSst(XclImpStream &rStrm)
Reads the entire SST record.
Definition: xicontent.cxx:73
Stores all user defined number formats occurred in the file.
Definition: xistyle.hxx:205
static const OUString & GetHTMLDocName()
Returns the built-in range name for an HTML document.
Definition: ftools.cxx:281
sal_uInt16 mnRefresh
Current mode of the web query.
Definition: xicontent.hxx:226
const sal_uInt32 EXC_HLINK_MARK
Description.
Definition: xlcontent.hxx:147
ScCondFmtPtr mxScCondFmt
Destination cell ranges.
Definition: xicontent.hxx:141
const sal_uInt32 EXC_DV_IGNOREBLANK
Definition: xlcontent.hxx:107
void SetSkipObj(sal_uInt16 nObjId)
Sets the object with the passed identification to be skipped on import.
Definition: xiescher.cxx:4047
css::uno::Sequence< css::beans::NamedValue > RequestEncryptionData(::comphelper::IDocPasswordVerifier &rVerifier) const
Requests and verifies a password from the medium or the user.
Definition: xlroot.cxx:239
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
XclImpCondFormatManager(const XclImpRoot &rRoot)
Definition: xicontent.cxx:703
MS Excel 3.0.
Definition: xlconst.hxx:34
SC_DLLPUBLIC void ApplyPatternAreaTab(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, const ScPatternAttr &rAttr)
Definition: document.cxx:4786
static void ReadDval(XclImpStream &rStrm)
Reads a DVAL record and sets marks the dropdown arrow control to be ignored.
Definition: xicontent.cxx:739
void SetIgnoreBlank(bool bSet)
Definition: conditio.cxx:415
Container for the Excel EnhancedProtection feature.
void ReadCF(XclImpStream &rStrm)
Reads a CF record and inserts the formatting data to the current conditional format.
Definition: xicontent.cxx:715
sal_uInt16 mnCol
Definition: xladdress.hxx:32
void ReadWqstring(XclImpStream &rStrm)
Reads a WQSTRING record and sets URL to the current web query.
Definition: xicontent.cxx:1063
const sal_uInt8 EXC_CF_TYPE_FMLA
Definition: xlcontent.hxx:59
void GetVars(SCCOL &nCol1, SCROW &nRow1, SCTAB &nTab1, SCCOL &nCol2, SCROW &nRow2, SCTAB &nTab2) const
Definition: address.hxx:693
const sal_uInt32 EXC_DV_COND_MASK
Definition: xlcontent.hxx:124
XclImpNameManager & GetNameManager() const
Returns the buffer that contains internal defined names.
Definition: xiroot.cxx:183
const sal_uInt8 EXC_CF_CMP_GREATER
Definition: xlcontent.hxx:66
sal_Int16 nVersion
sal_uInt16 ReaduInt16()
Definition: xistream.cxx:648
void ReadDocProtect(XclImpStream &rStrm)
document structure protection flag
Definition: xicontent.cxx:1266
void EnableDecryption(bool bEnable=true)
Switches usage of current decryption algorithm on/off.
Definition: xistream.cxx:521
const sal_uInt16 EXC_FILEPASS_BIFF8
Definition: xlcontent.hxx:41
XclImpWebQuery(const ScRange &rDestRange)
Definition: xicontent.cxx:946
::std::vector< ScEnhancedProtection > maEnhancedProtections
Definition: xicontent.hxx:318
SCCOL Col() const
Definition: address.hxx:267
XclTracer & GetTracer() const
Returns the filter tracer.
Definition: xlroot.cxx:424
virtual ConvErr Convert(std::unique_ptr< ScTokenArray > &, XclImpStream &rStrm, std::size_t nFormulaLen, bool bAllowArrays, const FORMULA_TYPE eFT=FT_CellFormula) override
Definition: excform.cxx:206
SCTAB GetCurrScTab() const
Returns the current Calc sheet index.
Definition: xlroot.hxx:160
const sal_uInt32 EXC_DV_SUPPRESSDROPDOWN
Definition: xlcontent.hxx:108
ScRange maDestRange
List of source range names.
Definition: xicontent.hxx:224
std::vector< std::unique_ptr< XclImpCondFormat > > maCondFmtList
Definition: xicontent.hxx:163
void FillToItemSet(SfxItemSet &rItemSet, sal_uInt16 nXclNumFmt, bool bSkipPoolDefs=false) const
Fills an Excel number format to the passed item set.
Definition: xistyle.cxx:727
XclImpSheetDrawing & GetCurrSheetDrawing() const
Returns the drawing container of the current sheet.
Definition: xiroot.cxx:199
const sal_uInt32 EXC_DV_COND_EQUAL
Definition: xlcontent.hxx:127
const XclImpRoot & GetRoot() const
Returns the filter root data.
Definition: xistream.hxx:294
const sal_uInt32 EXC_HLINK_FRAME
Text mark.
Definition: xlcontent.hxx:148
std::size_t GetRecLeft()
Returns remaining data size of the whole record without record headers.
Definition: xistream.cxx:581
SC_DLLPUBLIC sal_uLong AddValidationEntry(const ScValidationData &rNew)
Definition: documen4.cxx:716
This struct stores a GUID (class ID) and supports reading, writing and comparison.
Definition: xltools.hxx:57
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_Int32 SCROW
Definition: types.hxx:18
OUString ReadUniString(sal_uInt16 nChars, sal_uInt8 nFlags)
Reads ext.
Definition: xistream.cxx:886
void ReadPasswordHash(XclImpStream &rStrm, SCTAB nTab)
Definition: xicontent.cxx:1363
ScEditEngineDefaulter & GetEditEngine() const
Returns the edit engine for import/export of rich strings etc.
Definition: xlroot.cxx:356
static OUString GetNameFromHTMLName(const OUString &rTabName)
Returns the built-in range name for an HTML table, specified by table name.
Definition: ftools.cxx:313
void ResetInput()
Definition: validat.cxx:150
const sal_uInt32 EXC_DV_ERROR_MASK
Definition: xlcontent.hxx:135
sal_uInt8 encryptedVerifier[ENCRYPTED_VERIFIER_LENGTH]
void Apply()
Inserts the conditional formatting into the document.
Definition: xicontent.cxx:722
void AppendEnhancedProtection(const ScEnhancedProtection &rProt, SCTAB nTab)
Definition: xicontent.cxx:1356
#define OSL_ENSURE_BIFF(c)
Definition: xltools.hxx:32
void FillFromCF8(sal_uInt16 nPattern, sal_uInt16 nColor, sal_uInt32 nFlags)
Fills this struct with BIFF8 CF (conditional format) record data.
Definition: xistyle.cxx:1052
SvBaseLink * pLink
void Join(const ScRange &, bool bIsInList=false)
Definition: rangelst.cxx:166
void Ignore(std::size_t nBytes)
Seeks forward inside the current record.
Definition: xistream.cxx:795
static SC_DLLPUBLIC OUString addToken(const OUString &rTokenList, const OUString &rToken, sal_Unicode cSep, sal_Int32 nSepCount=1, bool bForceSep=false)
Adds the string rToken to rTokenList, using a list separator character.
Definition: global.cxx:656
unsigned char sal_uInt8
virtual ~XclImpCondFormat() override
Definition: xicontent.cxx:498
sal_uInt8 ReaduInt8()
Definition: xistream.cxx:616
#define SAL_INFO(area, stream)
void SetError(const OUString &rTitle, const OUString &rMsg, ScValidErrorStyle eStyle)
Definition: validat.cxx:167
static OUString SC_DLLPUBLIC GetQuotedToken(const OUString &rIn, sal_Int32 nToken, const OUString &rQuotedPairs, sal_Unicode cTok, sal_Int32 &rIndex)
Definition: stringutil.cxx:349
virtual SC_DLLPUBLIC SfxItemSet & GetItemSet() override
Definition: stlsheet.cxx:126
void ReadCF(XclImpStream &rStrm)
Reads a CF record and adds a new condition and the formatting attributes.
Definition: xicontent.cxx:512
void ReadWqsettings(XclImpStream &rStrm)
Reads a WEBQRYSETTINGS record and sets refresh rate.
Definition: xicontent.cxx:977
This class represents an Excel stream position.
Definition: xistream.hxx:202
const INetURLObject & GetURLObject() const
void QuickSetAttribs(const SfxItemSet &rSet, const ESelection &rSel)
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:401
OUString maURL
Definition: xicontent.hxx:222
XclBiff GetBiff() const
Returns the current BIFF version of the importer/exporter.
Definition: xlroot.hxx:140
const sal_uInt8 EXC_CF_CMP_NOT_BETWEEN
Definition: xlcontent.hxx:63
double getLength(const B2DPolygon &rCandidate)
bool ConvertRange(ScRange &rScRange, const XclRange &rXclRange, SCTAB nScTab1, SCTAB nScTab2, bool bWarn)
Converts the passed Excel cell range to a Calc cell range.
Definition: xihelper.cxx:101
static bool isAsciiNumeric(const OUString &rStr)
const sal_uInt8 EXC_CF_CMP_NOT_EQUAL
Definition: xlcontent.hxx:65
constexpr TypedWhichId< SfxStringItem > ATTR_HYPERLINK(155)
Stores the default colors for the current BIFF version and the contents of a PALETTE record...
Definition: xistyle.hxx:45
void Apply(ScDocument &rDoc, const OUString &rFilterName)
Inserts the web query into the document.
Definition: xicontent.cxx:1014
ScInterpreterContext & GetNonThreadedContext() const
Definition: document.hxx:612
static void ConvertStringToList(ScTokenArray &rScTokArr, svl::SharedStringPool &rSPool, sal_Unicode cStringSep)
Tries to convert a formula that consists of a single string token to a list of strings.
Definition: xlformula.cxx:902
const sal_uInt32 VERSION_INFO_2007_FORMAT_SP2
ScRange & front()
Definition: rangelst.hxx:93
const sal_uInt32 EXC_DV_MODE_MASK
Definition: xlcontent.hxx:113
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1058
SC_DLLPUBLIC void SetDocProtection(const ScDocProtection *pProtect)
Definition: documen3.cxx:1871
#define SAL_WARN(area, stream)
#define EXC_WEBQRY_FILTER
UNC path.
Definition: xlcontent.hxx:153
static void GetString(const ScRefCellValue &rCell, sal_uInt32 nFormat, OUString &rString, const Color **ppColor, SvNumberFormatter &rFormatter, const ScDocument &rDoc, bool bNullVals=true, bool bFormula=false, bool bUseStarFormat=false)
Definition: cellform.cxx:33
SfxObjectShell * GetDocShell() const
Returns the object shell of the Calc document.
Definition: xlroot.cxx:281
MS Excel 2.1.
Definition: xlconst.hxx:33
This class is used to import record oriented streams.
Definition: xistream.hxx:278
const sal_uInt32 EXC_DV_MODE_ANY
Definition: xlcontent.hxx:114
const sal_uInt32 EXC_HLINK_DESCR
Absolute path.
Definition: xlcontent.hxx:146
Represents a conditional format with condition formulas, and formatting attributes.
Definition: xicontent.hxx:123
static ScStyleSheet & MakeCellStyleSheet(ScStyleSheetPool &rPool, const OUString &rStyleName, bool bForceName)
Creates and returns a cell style sheet and inserts it into the pool.
Definition: ftools.cxx:253
INetURLObject smartRel2Abs(OUString const &rTheRelURIRef, bool &rWasAbsolute, bool bIgnoreFragment=false, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, bool bRelativeNonURIs=false, FSysStyle eStyle=FSysStyle::Detect) const
const ErrCode EXC_ENCR_ERROR_UNSUPP_CRYPT
Definition: xlstream.hxx:33
const sal_uInt32 EXC_HLINK_UNC
Target frame.
Definition: xlcontent.hxx:149
static OUString GetCondFormatStyleName(SCTAB nScTab, sal_Int32 nFormat, sal_uInt16 nCondition)
Returns the style name for a single condition of a conditional formatting.
Definition: xltools.cxx:663
SC_DLLPUBLIC sfx2::LinkManager * GetLinkManager()
Definition: documen2.cxx:215
const sal_uInt32 EXC_DV_ERROR_INFO
Definition: xlcontent.hxx:138
Access to global data from other classes.
Definition: xiroot.hxx:126
sal_uInt32 ReaduInt32()
Definition: xistream.cxx:684
void Apply()
Inserts this conditional format into the document.
Definition: xicontent.cxx:690
This class represents an unformatted or formatted string and provides importing from stream...
Definition: xistring.hxx:31
void Apply()
Inserts all web queries into the document.
Definition: xicontent.cxx:1081
const sal_uInt32 EXC_CF_BLOCK_ALIGNMENT
Font block present?
Definition: xlcontent.hxx:83
Represents a defined name.
Definition: xiname.hxx:34
void ReadParamqry(XclImpStream &rStrm)
Reads a PARAMQRY record and sets data to the current web query.
Definition: xicontent.cxx:1057
void ReadOptions(XclImpStream &rStrm, SCTAB nTab)
Definition: xicontent.cxx:1337
void FillFromXF3(sal_uInt16 nProt)
Fills this struct with BIFF3-BIFF8 XF record data.
Definition: xistyle.cxx:751
void ResetError()
Definition: validat.cxx:155
const sal_uInt32 EXC_DV_MODE_WHOLE
Definition: xlcontent.hxx:115
void RestorePosition(const XclImpStreamPos &rPos)
Restores stream position contained in rPos.
Definition: xistream.cxx:966
A 2D cell range address struct with Excel column and row indexes.
Definition: xladdress.hxx:58
sal_Int16 SCTAB
Definition: types.hxx:23
const sal_uInt32 EXC_DV_SHOWPROMPT
Definition: xlcontent.hxx:109
SC_DLLPUBLIC void AddCondFormatData(const ScRangeList &rRange, SCTAB nTab, sal_uInt32 nIndex)
Definition: document.cxx:4807
static void ReadLabelranges(XclImpStream &rStrm)
Reads a LABELRANGES record and inserts the label ranges into the document.
Definition: xicontent.cxx:431
ScDocument & getDoc()
SfxMedium * GetMedium() const