Line data Source code
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 "defnamesbuffer.hxx"
21 :
22 : #include <com/sun/star/sheet/ComplexReference.hpp>
23 : #include <com/sun/star/sheet/ExternalReference.hpp>
24 : #include <com/sun/star/sheet/NamedRangeFlag.hpp>
25 : #include <com/sun/star/sheet/ReferenceFlags.hpp>
26 : #include <com/sun/star/sheet/SingleReference.hpp>
27 : #include <com/sun/star/sheet/XFormulaTokens.hpp>
28 : #include <com/sun/star/sheet/XPrintAreas.hpp>
29 : #include <rtl/ustrbuf.hxx>
30 : #include "oox/helper/attributelist.hxx"
31 : #include "oox/helper/containerhelper.hxx"
32 : #include "oox/helper/propertyset.hxx"
33 : #include "addressconverter.hxx"
34 : #include "biffinputstream.hxx"
35 : #include "externallinkbuffer.hxx"
36 : #include "formulaparser.hxx"
37 : #include "worksheetbuffer.hxx"
38 : #include "tokenarray.hxx"
39 : #include "tokenuno.hxx"
40 :
41 : namespace oox {
42 : namespace xls {
43 :
44 : // ============================================================================
45 :
46 : using namespace ::com::sun::star::sheet;
47 : using namespace ::com::sun::star::table;
48 : using namespace ::com::sun::star::uno;
49 :
50 :
51 : // ============================================================================
52 :
53 : namespace {
54 :
55 : const sal_uInt32 BIFF12_DEFNAME_HIDDEN = 0x00000001;
56 : const sal_uInt32 BIFF12_DEFNAME_FUNC = 0x00000002;
57 : const sal_uInt32 BIFF12_DEFNAME_VBNAME = 0x00000004;
58 : const sal_uInt32 BIFF12_DEFNAME_MACRO = 0x00000008;
59 : const sal_uInt32 BIFF12_DEFNAME_CALCEXP = 0x00000010;
60 : const sal_uInt32 BIFF12_DEFNAME_BUILTIN = 0x00000020;
61 : const sal_uInt32 BIFF12_DEFNAME_PUBLISHED = 0x00008000;
62 : const sal_uInt32 BIFF12_DEFNAME_WBPARAM = 0x00010000;
63 :
64 : const sal_uInt16 BIFF_DEFNAME_HIDDEN = 0x0001;
65 : const sal_uInt16 BIFF_DEFNAME_FUNC = 0x0002;
66 : const sal_uInt16 BIFF_DEFNAME_VBNAME = 0x0004;
67 : const sal_uInt16 BIFF_DEFNAME_MACRO = 0x0008;
68 : const sal_uInt16 BIFF_DEFNAME_CALCEXP = 0x0010;
69 : const sal_uInt16 BIFF_DEFNAME_BUILTIN = 0x0020;
70 : const sal_uInt16 BIFF_DEFNAME_BIG = 0x1000;
71 :
72 : const sal_uInt8 BIFF2_DEFNAME_FUNC = 0x02; /// BIFF2 function/command flag.
73 :
74 : const sal_uInt16 BIFF_DEFNAME_GLOBAL = 0; /// 0 = Globally defined name.
75 :
76 : const sal_uInt16 BIFF_REFFLAG_COL1REL = 0x0001;
77 : const sal_uInt16 BIFF_REFFLAG_ROW1REL = 0x0002;
78 : const sal_uInt16 BIFF_REFFLAG_COL2REL = 0x0004;
79 : const sal_uInt16 BIFF_REFFLAG_ROW2REL = 0x0008;
80 :
81 : // ----------------------------------------------------------------------------
82 :
83 : const sal_Char* const spcLegacyPrefix = "Excel_BuiltIn_";
84 : const sal_Char* const spcOoxPrefix = "_xlnm.";
85 :
86 : const sal_Char* const sppcBaseNames[] =
87 : {
88 : "Consolidate_Area",
89 : "Auto_Open",
90 : "Auto_Close",
91 : "Extract",
92 : "Database",
93 : "Criteria",
94 : "Print_Area",
95 : "Print_Titles",
96 : "Recorder",
97 : "Data_Form",
98 : "Auto_Activate",
99 : "Auto_Deactivate",
100 : "Sheet_Title",
101 : "_FilterDatabase"
102 : };
103 :
104 : /** Localized names for _xlnm._FilterDatabase as used in BIFF5. */
105 : const sal_Char* const sppcFilterDbNames[] =
106 : {
107 : "_FilterDatabase", // English
108 : "_FilterDatenbank" // German
109 : };
110 :
111 15 : OUString lclGetBaseName( sal_Unicode cBuiltinId )
112 : {
113 : OSL_ENSURE( cBuiltinId < STATIC_ARRAY_SIZE( sppcBaseNames ), "lclGetBaseName - unsupported built-in identifier" );
114 15 : OUStringBuffer aBuffer;
115 15 : if( cBuiltinId < STATIC_ARRAY_SIZE( sppcBaseNames ) )
116 15 : aBuffer.appendAscii( sppcBaseNames[ cBuiltinId ] );
117 : else
118 0 : aBuffer.append( static_cast< sal_Int32 >( cBuiltinId ) );
119 15 : return aBuffer.makeStringAndClear();
120 : }
121 :
122 1 : OUString lclGetPrefixedName( sal_Unicode cBuiltinId )
123 : {
124 1 : return OUStringBuffer().appendAscii( spcOoxPrefix ).append( lclGetBaseName( cBuiltinId ) ).makeStringAndClear();
125 : }
126 :
127 : /** returns the built-in name identifier from a perfixed built-in name, e.g. '_xlnm.Print_Area'. */
128 11 : sal_Unicode lclGetBuiltinIdFromPrefixedName( const OUString& rModelName )
129 : {
130 11 : OUString aPrefix = OUString::createFromAscii( spcOoxPrefix );
131 11 : sal_Int32 nPrefixLen = aPrefix.getLength();
132 11 : if( rModelName.matchIgnoreAsciiCase( aPrefix ) )
133 : {
134 14 : for( sal_Unicode cBuiltinId = 0; cBuiltinId < STATIC_ARRAY_SIZE( sppcBaseNames ); ++cBuiltinId )
135 : {
136 14 : OUString aBaseName = lclGetBaseName( cBuiltinId );
137 14 : sal_Int32 nBaseNameLen = aBaseName.getLength();
138 14 : if( (rModelName.getLength() == nPrefixLen + nBaseNameLen) && rModelName.matchIgnoreAsciiCase( aBaseName, nPrefixLen ) )
139 1 : return cBuiltinId;
140 13 : }
141 : }
142 10 : return BIFF_DEFNAME_UNKNOWN;
143 : }
144 :
145 : /** returns the built-in name identifier from a built-in base name, e.g. 'Print_Area'. */
146 0 : sal_Unicode lclGetBuiltinIdFromBaseName( const OUString& rModelName )
147 : {
148 0 : for( sal_Unicode cBuiltinId = 0; cBuiltinId < STATIC_ARRAY_SIZE( sppcBaseNames ); ++cBuiltinId )
149 0 : if( rModelName.equalsIgnoreAsciiCaseAscii( sppcBaseNames[ cBuiltinId ] ) )
150 0 : return cBuiltinId;
151 0 : return BIFF_DEFNAME_UNKNOWN;
152 : }
153 :
154 11 : OUString lclGetUpcaseModelName( const OUString& rModelName )
155 : {
156 : // TODO: i18n?
157 11 : return rModelName.toAsciiUpperCase();
158 : }
159 :
160 0 : void lclConvertRefFlags( sal_Int32& ornFlags, sal_Int32& ornAbsPos, sal_Int32& ornRelPos, sal_Int32 nBasePos, sal_Int32 nApiRelFlag, bool bRel )
161 : {
162 0 : if( getFlag( ornFlags, nApiRelFlag ) && !bRel )
163 : {
164 : // convert relative to absolute
165 0 : setFlag( ornFlags, nApiRelFlag, false );
166 0 : ornAbsPos = nBasePos + ornRelPos;
167 : }
168 0 : else if( !getFlag( ornFlags, nApiRelFlag ) && bRel )
169 : {
170 : // convert absolute to relative
171 0 : setFlag( ornFlags, nApiRelFlag, true );
172 0 : ornRelPos = ornAbsPos - nBasePos;
173 : }
174 0 : }
175 :
176 0 : void lclConvertSingleRefFlags( SingleReference& orApiRef, const CellAddress& rBaseAddr, bool bColRel, bool bRowRel )
177 : {
178 : using namespace ::com::sun::star::sheet::ReferenceFlags;
179 : lclConvertRefFlags(
180 : orApiRef.Flags, orApiRef.Column, orApiRef.RelativeColumn,
181 0 : rBaseAddr.Column, COLUMN_RELATIVE, bColRel );
182 : lclConvertRefFlags(
183 : orApiRef.Flags, orApiRef.Row, orApiRef.RelativeRow,
184 0 : rBaseAddr.Row, ROW_RELATIVE, bRowRel );
185 0 : }
186 :
187 0 : Any lclConvertReference( const Any& rRefAny, const CellAddress& rBaseAddr, sal_uInt16 nRelFlags )
188 : {
189 0 : if( rRefAny.has< SingleReference >() && !getFlag( nRelFlags, BIFF_REFFLAG_COL2REL ) && !getFlag( nRelFlags, BIFF_REFFLAG_ROW2REL ) )
190 : {
191 0 : SingleReference aApiRef;
192 0 : rRefAny >>= aApiRef;
193 0 : lclConvertSingleRefFlags( aApiRef, rBaseAddr, getFlag( nRelFlags, BIFF_REFFLAG_COL1REL ), getFlag( nRelFlags, BIFF_REFFLAG_ROW1REL ) );
194 0 : return Any( aApiRef );
195 : }
196 0 : if( rRefAny.has< ComplexReference >() )
197 : {
198 0 : ComplexReference aApiRef;
199 0 : rRefAny >>= aApiRef;
200 0 : lclConvertSingleRefFlags( aApiRef.Reference1, rBaseAddr, getFlag( nRelFlags, BIFF_REFFLAG_COL1REL ), getFlag( nRelFlags, BIFF_REFFLAG_ROW1REL ) );
201 0 : lclConvertSingleRefFlags( aApiRef.Reference2, rBaseAddr, getFlag( nRelFlags, BIFF_REFFLAG_COL2REL ), getFlag( nRelFlags, BIFF_REFFLAG_ROW2REL ) );
202 0 : return Any( aApiRef );
203 : }
204 0 : return Any();
205 : }
206 :
207 : } // namespace
208 :
209 : // ============================================================================
210 :
211 11 : DefinedNameModel::DefinedNameModel() :
212 : mnSheet( -1 ),
213 : mnFuncGroupId( -1 ),
214 : mbMacro( false ),
215 : mbFunction( false ),
216 : mbVBName( false ),
217 11 : mbHidden( false )
218 : {
219 11 : }
220 :
221 : // ============================================================================
222 :
223 11 : DefinedNameBase::DefinedNameBase( const WorkbookHelper& rHelper ) :
224 11 : WorkbookHelper( rHelper )
225 : {
226 11 : }
227 :
228 11 : const OUString& DefinedNameBase::getUpcaseModelName() const
229 : {
230 11 : if( maUpModelName.isEmpty() )
231 11 : maUpModelName = lclGetUpcaseModelName( maModel.maName );
232 11 : return maUpModelName;
233 : }
234 :
235 0 : Any DefinedNameBase::getReference( const CellAddress& rBaseAddr ) const
236 : {
237 0 : if( maRefAny.hasValue() && (maModel.maName.getLength() >= 2) && (maModel.maName[ 0 ] == '\x01') )
238 : {
239 0 : sal_Unicode cFlagsChar = getUpcaseModelName()[ 1 ];
240 0 : if( ('A' <= cFlagsChar) && (cFlagsChar <= 'P') )
241 : {
242 0 : sal_uInt16 nRelFlags = static_cast< sal_uInt16 >( cFlagsChar - 'A' );
243 0 : if( maRefAny.has< ExternalReference >() )
244 : {
245 0 : ExternalReference aApiExtRef;
246 0 : maRefAny >>= aApiExtRef;
247 0 : Any aRefAny = lclConvertReference( aApiExtRef.Reference, rBaseAddr, nRelFlags );
248 0 : if( aRefAny.hasValue() )
249 : {
250 0 : aApiExtRef.Reference <<= aRefAny;
251 0 : return Any( aApiExtRef );
252 0 : }
253 : }
254 : else
255 : {
256 0 : return lclConvertReference( maRefAny, rBaseAddr, nRelFlags );
257 : }
258 : }
259 : }
260 0 : return Any();
261 : }
262 :
263 11 : ApiTokenSequence DefinedNameBase::importOoxFormula( sal_Int16 nBaseSheet )
264 : {
265 11 : return (!maModel.maFormula.isEmpty()) ?
266 11 : getFormulaParser().importFormula( CellAddress( nBaseSheet, 0, 0 ), maModel.maFormula ) :
267 22 : getFormulaParser().convertErrorToFormula( BIFF_ERR_NAME );
268 : }
269 :
270 0 : ApiTokenSequence DefinedNameBase::importBiff12Formula( sal_Int16 nBaseSheet, SequenceInputStream& rStrm )
271 : {
272 0 : return getFormulaParser().importFormula( CellAddress( nBaseSheet, 0, 0 ), FORMULATYPE_DEFINEDNAME, rStrm );
273 : }
274 :
275 0 : ApiTokenSequence DefinedNameBase::importBiffFormula( sal_Int16 nBaseSheet, BiffInputStream& rStrm, const sal_uInt16* pnFmlaSize )
276 : {
277 0 : return (!pnFmlaSize || (*pnFmlaSize > 0)) ?
278 0 : getFormulaParser().importFormula( CellAddress( nBaseSheet, 0, 0 ), FORMULATYPE_DEFINEDNAME, rStrm, pnFmlaSize ) :
279 0 : getFormulaParser().convertErrorToFormula( BIFF_ERR_NAME );
280 : }
281 :
282 : // ============================================================================
283 :
284 11 : DefinedName::DefinedName( const WorkbookHelper& rHelper ) :
285 : DefinedNameBase( rHelper ),
286 : mpScRangeData(NULL),
287 : mnTokenIndex( -1 ),
288 : mcBuiltinId( BIFF_DEFNAME_UNKNOWN ),
289 11 : mnFmlaSize( 0 )
290 : {
291 11 : }
292 :
293 11 : void DefinedName::importDefinedName( const AttributeList& rAttribs )
294 : {
295 11 : maModel.maName = rAttribs.getXString( XML_name, OUString() );
296 11 : maModel.mnSheet = rAttribs.getInteger( XML_localSheetId, -1 );
297 11 : maModel.mnFuncGroupId = rAttribs.getInteger( XML_functionGroupId, -1 );
298 11 : maModel.mbMacro = rAttribs.getBool( XML_xlm, false );
299 11 : maModel.mbFunction = rAttribs.getBool( XML_function, false );
300 11 : maModel.mbVBName = rAttribs.getBool( XML_vbProcedure, false );
301 11 : maModel.mbHidden = rAttribs.getBool( XML_hidden, false );
302 11 : mnCalcSheet = (maModel.mnSheet >= 0) ? getWorksheets().getCalcSheetIndex( maModel.mnSheet ) : -1;
303 :
304 : /* Detect built-in state from name itself, there is no built-in flag.
305 : Built-in names are prexixed with '_xlnm.' instead. */
306 11 : mcBuiltinId = lclGetBuiltinIdFromPrefixedName( maModel.maName );
307 11 : }
308 :
309 11 : void DefinedName::setFormula( const OUString& rFormula )
310 : {
311 11 : maModel.maFormula = rFormula;
312 11 : }
313 :
314 0 : void DefinedName::importDefinedName( SequenceInputStream& rStrm )
315 : {
316 : sal_uInt32 nFlags;
317 0 : rStrm >> nFlags;
318 0 : rStrm.skip( 1 ); // keyboard shortcut
319 0 : rStrm >> maModel.mnSheet >> maModel.maName;
320 0 : mnCalcSheet = (maModel.mnSheet >= 0) ? getWorksheets().getCalcSheetIndex( maModel.mnSheet ) : -1;
321 :
322 : // macro function/command, hidden flag
323 0 : maModel.mnFuncGroupId = extractValue< sal_Int32 >( nFlags, 6, 9 );
324 0 : maModel.mbMacro = getFlag( nFlags, BIFF12_DEFNAME_MACRO );
325 0 : maModel.mbFunction = getFlag( nFlags, BIFF12_DEFNAME_FUNC );
326 0 : maModel.mbVBName = getFlag( nFlags, BIFF12_DEFNAME_VBNAME );
327 0 : maModel.mbHidden = getFlag( nFlags, BIFF12_DEFNAME_HIDDEN );
328 :
329 : // get built-in name index from name
330 0 : if( getFlag( nFlags, BIFF12_DEFNAME_BUILTIN ) )
331 0 : mcBuiltinId = lclGetBuiltinIdFromBaseName( maModel.maName );
332 :
333 : // store token array data
334 0 : sal_Int64 nRecPos = rStrm.tell();
335 0 : sal_Int32 nFmlaSize = rStrm.readInt32();
336 0 : rStrm.skip( nFmlaSize );
337 0 : sal_Int32 nAddDataSize = rStrm.readInt32();
338 0 : if( !rStrm.isEof() && (nFmlaSize > 0) && (nAddDataSize >= 0) && (rStrm.getRemaining() >= nAddDataSize) )
339 : {
340 0 : sal_Int32 nTotalSize = 8 + nFmlaSize + nAddDataSize;
341 0 : mxFormula.reset( new StreamDataSequence );
342 0 : rStrm.seek( nRecPos );
343 0 : rStrm.readData( *mxFormula, nTotalSize );
344 : }
345 0 : }
346 :
347 11 : void DefinedName::createNameObject( sal_Int32 nIndex )
348 : {
349 : // do not create names for (macro) functions or VBA procedures
350 : // #163146# do not ignore hidden names (may be regular names created by VBA scripts)
351 11 : if( /*maModel.mbHidden ||*/ maModel.mbFunction || maModel.mbVBName )
352 0 : return;
353 :
354 : // skip BIFF names without stream position (e.g. BIFF3-BIFF4 internal 3D references)
355 11 : if( (getFilterType() == FILTER_BIFF) && !mxBiffStrm.get() )
356 0 : return;
357 :
358 : // convert original name to final Calc name (TODO: filter invalid characters from model name)
359 11 : maCalcName = isBuiltinName() ? lclGetPrefixedName( mcBuiltinId ) : maModel.maName;
360 :
361 : // #163146# do not rename sheet-local names by default, this breaks VBA scripts
362 :
363 : // special flags for this name
364 11 : sal_Int32 nNameFlags = 0;
365 : using namespace ::com::sun::star::sheet::NamedRangeFlag;
366 11 : if( !isGlobalName() ) switch( mcBuiltinId )
367 : {
368 0 : case BIFF_DEFNAME_CRITERIA: nNameFlags = FILTER_CRITERIA; break;
369 0 : case BIFF_DEFNAME_PRINTAREA: nNameFlags = PRINT_AREA; break;
370 0 : case BIFF_DEFNAME_PRINTTITLES: nNameFlags = COLUMN_HEADER | ROW_HEADER; break;
371 : }
372 :
373 : // create the name and insert it into the document, maCalcName will be changed to the resulting name
374 11 : if (maModel.mnSheet >= 0)
375 5 : mpScRangeData = createLocalNamedRangeObject( maCalcName, ApiTokenSequence(), nIndex, nNameFlags, maModel.mnSheet );
376 : else
377 6 : mpScRangeData = createNamedRangeObject( maCalcName, ApiTokenSequence(), nIndex, nNameFlags );
378 11 : mnTokenIndex = nIndex;
379 : }
380 :
381 : ApiTokenSequence
382 11 : DefinedName::getTokens()
383 : {
384 : // convert and set formula of the defined name
385 11 : ApiTokenSequence aTokens;
386 11 : switch( getFilterType() )
387 : {
388 : case FILTER_OOXML:
389 : {
390 11 : if( mxFormula.get() )
391 : {
392 0 : SequenceInputStream aStrm( *mxFormula );
393 0 : aTokens = importBiff12Formula( mnCalcSheet, aStrm );
394 : }
395 : else
396 11 : aTokens = importOoxFormula( mnCalcSheet );
397 : }
398 11 : break;
399 : case FILTER_BIFF:
400 : {
401 : OSL_ENSURE( mxBiffStrm.get(), "DefinedName::convertFormula - missing BIFF stream" );
402 0 : if( mxBiffStrm.get() )
403 : {
404 0 : BiffInputStream& rStrm = mxBiffStrm->getStream();
405 0 : BiffInputStreamPosGuard aStrmGuard( rStrm );
406 0 : if( mxBiffStrm->restorePosition() )
407 0 : aTokens = importBiffFormula( mnCalcSheet, rStrm, &mnFmlaSize );
408 : }
409 : }
410 0 : break;
411 : case FILTER_UNKNOWN:
412 0 : break;
413 : }
414 11 : return aTokens;
415 : }
416 :
417 11 : void DefinedName::convertFormula()
418 : {
419 : // macro function or vba procedure
420 11 : if(!mpScRangeData)
421 11 : return;
422 :
423 : // convert and set formula of the defined name
424 11 : if ( getFilterType() == FILTER_OOXML )
425 : {
426 11 : ApiTokenSequence aTokens = getTokens();
427 22 : ScTokenArray aTokenArray;
428 11 : (void)ScTokenConversion::ConvertToTokenArray( this->getScDocument(), aTokenArray, aTokens );
429 22 : mpScRangeData->SetCode( aTokenArray );
430 : }
431 :
432 11 : ScTokenArray* pTokenArray = mpScRangeData->GetCode();
433 11 : Sequence< FormulaToken > aFTokenSeq;
434 11 : (void)ScTokenConversion::ConvertToTokenSequence( this->getScDocument(), aFTokenSeq, *pTokenArray );
435 : // set built-in names (print ranges, repeated titles, filter ranges)
436 11 : if( !isGlobalName() ) switch( mcBuiltinId )
437 : {
438 : case BIFF_DEFNAME_PRINTAREA:
439 : {
440 0 : Reference< XPrintAreas > xPrintAreas( getSheetFromDoc( mnCalcSheet ), UNO_QUERY );
441 0 : ApiCellRangeList aPrintRanges;
442 0 : getFormulaParser().extractCellRangeList( aPrintRanges, aFTokenSeq, false, mnCalcSheet );
443 0 : if( xPrintAreas.is() && !aPrintRanges.empty() )
444 0 : xPrintAreas->setPrintAreas( ContainerHelper::vectorToSequence( aPrintRanges ) );
445 : }
446 0 : break;
447 : case BIFF_DEFNAME_PRINTTITLES:
448 : {
449 0 : Reference< XPrintAreas > xPrintAreas( getSheetFromDoc( mnCalcSheet ), UNO_QUERY );
450 0 : ApiCellRangeList aTitleRanges;
451 0 : getFormulaParser().extractCellRangeList( aTitleRanges, aFTokenSeq, false, mnCalcSheet );
452 0 : if( xPrintAreas.is() && !aTitleRanges.empty() )
453 : {
454 0 : bool bHasRowTitles = false;
455 0 : bool bHasColTitles = false;
456 0 : const CellAddress& rMaxPos = getAddressConverter().getMaxAddress();
457 0 : for( ApiCellRangeList::const_iterator aIt = aTitleRanges.begin(), aEnd = aTitleRanges.end(); (aIt != aEnd) && (!bHasRowTitles || !bHasColTitles); ++aIt )
458 : {
459 0 : bool bFullRow = (aIt->StartColumn == 0) && (aIt->EndColumn >= rMaxPos.Column);
460 0 : bool bFullCol = (aIt->StartRow == 0) && (aIt->EndRow >= rMaxPos.Row);
461 0 : if( !bHasRowTitles && bFullRow && !bFullCol )
462 : {
463 0 : xPrintAreas->setTitleRows( *aIt );
464 0 : xPrintAreas->setPrintTitleRows( sal_True );
465 0 : bHasRowTitles = true;
466 : }
467 0 : else if( !bHasColTitles && bFullCol && !bFullRow )
468 : {
469 0 : xPrintAreas->setTitleColumns( *aIt );
470 0 : xPrintAreas->setPrintTitleColumns( sal_True );
471 0 : bHasColTitles = true;
472 : }
473 : }
474 0 : }
475 : }
476 0 : break;
477 11 : }
478 : }
479 :
480 1 : bool DefinedName::getAbsoluteRange( CellRangeAddress& orRange ) const
481 : {
482 1 : ScTokenArray* pTokenArray = mpScRangeData->GetCode();
483 1 : Sequence< FormulaToken > aFTokenSeq;
484 1 : ScTokenConversion::ConvertToTokenSequence( this->getScDocument(), aFTokenSeq, *pTokenArray );
485 1 : return getFormulaParser().extractCellRange( orRange, aFTokenSeq, false );
486 : }
487 :
488 : // ============================================================================
489 :
490 21 : DefinedNamesBuffer::DefinedNamesBuffer( const WorkbookHelper& rHelper ) :
491 21 : WorkbookHelper( rHelper )
492 : {
493 21 : }
494 :
495 11 : DefinedNameRef DefinedNamesBuffer::importDefinedName( const AttributeList& rAttribs )
496 : {
497 11 : DefinedNameRef xDefName = createDefinedName();
498 11 : xDefName->importDefinedName( rAttribs );
499 11 : return xDefName;
500 : }
501 :
502 0 : void DefinedNamesBuffer::importDefinedName( SequenceInputStream& rStrm )
503 : {
504 0 : createDefinedName()->importDefinedName( rStrm );
505 0 : }
506 :
507 21 : void DefinedNamesBuffer::finalizeImport()
508 : {
509 : // first insert all names without formula definition into the document, and insert them into the maps
510 21 : int index = 0;
511 32 : for( DefNameVector::iterator aIt = maDefNames.begin(), aEnd = maDefNames.end(); aIt != aEnd; ++aIt )
512 : {
513 11 : DefinedNameRef xDefName = *aIt;
514 11 : xDefName->createNameObject( ++index );
515 : // map by sheet index and original model name
516 11 : maModelNameMap[ SheetNameKey( xDefName->getLocalCalcSheet(), xDefName->getUpcaseModelName() ) ] = xDefName;
517 : // map by sheet index and built-in identifier
518 11 : if( !xDefName->isGlobalName() && xDefName->isBuiltinName() )
519 1 : maBuiltinMap[ BuiltinKey( xDefName->getLocalCalcSheet(), xDefName->getBuiltinId() ) ] = xDefName;
520 : // map by API formula token identifier
521 11 : sal_Int32 nTokenIndex = xDefName->getTokenIndex();
522 11 : if( nTokenIndex >= 0 )
523 11 : maTokenIdMap[ nTokenIndex ] = xDefName;
524 11 : }
525 :
526 : /* Now convert all name formulas, so that the formula parser can find all
527 : names in case of circular dependencies. */
528 21 : maDefNames.forEachMem( &DefinedName::convertFormula );
529 21 : }
530 :
531 0 : DefinedNameRef DefinedNamesBuffer::getByIndex( sal_Int32 nIndex ) const
532 : {
533 0 : return maDefNames.get( nIndex );
534 : }
535 :
536 0 : DefinedNameRef DefinedNamesBuffer::getByTokenIndex( sal_Int32 nIndex ) const
537 : {
538 0 : return maTokenIdMap.get( nIndex );
539 : }
540 :
541 0 : DefinedNameRef DefinedNamesBuffer::getByModelName( const OUString& rModelName, sal_Int16 nCalcSheet ) const
542 : {
543 0 : OUString aUpcaseName = lclGetUpcaseModelName( rModelName );
544 0 : DefinedNameRef xDefName = maModelNameMap.get( SheetNameKey( nCalcSheet, aUpcaseName ) );
545 : // lookup global name, if no local name exists
546 0 : if( !xDefName && (nCalcSheet >= 0) )
547 0 : xDefName = maModelNameMap.get( SheetNameKey( -1, aUpcaseName ) );
548 0 : return xDefName;
549 : }
550 :
551 43 : DefinedNameRef DefinedNamesBuffer::getByBuiltinId( sal_Unicode cBuiltinId, sal_Int16 nCalcSheet ) const
552 : {
553 43 : return maBuiltinMap.get( BuiltinKey( nCalcSheet, cBuiltinId ) );
554 : }
555 :
556 11 : DefinedNameRef DefinedNamesBuffer::createDefinedName()
557 : {
558 11 : DefinedNameRef xDefName( new DefinedName( *this ) );
559 11 : maDefNames.push_back( xDefName );
560 11 : return xDefName;
561 : }
562 :
563 : // ============================================================================
564 :
565 : } // namespace xls
566 15 : } // namespace oox
567 :
568 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|