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