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 : #ifndef INCLUDED_SC_SOURCE_FILTER_INC_ADDRESSCONVERTER_HXX
21 : #define INCLUDED_SC_SOURCE_FILTER_INC_ADDRESSCONVERTER_HXX
22 :
23 : #include <vector>
24 : #include <com/sun/star/table/CellAddress.hpp>
25 : #include <com/sun/star/table/CellRangeAddress.hpp>
26 : #include "workbookhelper.hxx"
27 :
28 : namespace oox {
29 : namespace xls {
30 :
31 : class BiffInputStream;
32 :
33 : /** A vector of com.sun.star.table.CellRangeAddress elements and additional
34 : functionality. */
35 1180 : class ApiCellRangeList
36 : {
37 : public:
38 966 : inline explicit ApiCellRangeList() : mvAddresses() {}
39 :
40 0 : size_t size() const { return mvAddresses.size(); }
41 :
42 6 : bool empty() const { return mvAddresses.empty(); }
43 :
44 1 : const ::com::sun::star::table::CellRangeAddress& front() const
45 1 : { return mvAddresses.front(); }
46 :
47 0 : ::com::sun::star::table::CellRangeAddress& operator[]( size_t i )
48 0 : { return mvAddresses[ i ]; }
49 :
50 215 : ::std::vector< ::com::sun::star::table::CellRangeAddress >::const_iterator begin() const
51 215 : { return mvAddresses.begin(); }
52 72 : ::std::vector< ::com::sun::star::table::CellRangeAddress >::iterator begin()
53 72 : { return mvAddresses.begin(); }
54 :
55 354 : ::std::vector< ::com::sun::star::table::CellRangeAddress >::const_iterator end() const
56 354 : { return mvAddresses.end(); }
57 :
58 8480 : ::std::vector< ::com::sun::star::table::CellRangeAddress >::reverse_iterator rbegin()
59 8480 : { return mvAddresses.rbegin(); }
60 :
61 8480 : ::std::vector< ::com::sun::star::table::CellRangeAddress >::reverse_iterator rend()
62 8480 : { return mvAddresses.rend(); }
63 :
64 195 : void clear() { mvAddresses.clear(); }
65 :
66 0 : void erase( ::std::vector< ::com::sun::star::table::CellRangeAddress >::iterator it )
67 0 : { mvAddresses.erase( it ); }
68 :
69 1854 : void pop_back() { mvAddresses.pop_back(); }
70 :
71 2542 : void push_back( const ::com::sun::star::table::CellRangeAddress& rAddress )
72 2542 : { mvAddresses.push_back( rAddress ); }
73 :
74 : /** Returns the base address of this range list (top-left cell of first range). */
75 : ::com::sun::star::table::CellAddress
76 : getBaseAddress() const;
77 :
78 : /** Converts to a sequence. */
79 : com::sun::star::uno::Sequence< ::com::sun::star::table::CellRangeAddress >
80 : toSequence() const;
81 :
82 : private:
83 : ::std::vector< ::com::sun::star::table::CellRangeAddress > mvAddresses;
84 : };
85 :
86 : /** A 2D cell address struct for binary filters. */
87 : struct BinAddress
88 : {
89 : sal_Int32 mnCol;
90 : sal_Int32 mnRow;
91 :
92 322 : inline explicit BinAddress() : mnCol( 0 ), mnRow( 0 ) {}
93 100 : inline explicit BinAddress( sal_Int32 nCol, sal_Int32 nRow ) : mnCol( nCol ), mnRow( nRow ) {}
94 60 : inline explicit BinAddress( const ::com::sun::star::table::CellAddress& rAddr ) : mnCol( rAddr.Column ), mnRow( rAddr.Row ) {}
95 :
96 : inline void set( sal_Int32 nCol, sal_Int32 nRow ) { mnCol = nCol; mnRow = nRow; }
97 : inline void set( const ::com::sun::star::table::CellAddress& rAddr ) { mnCol = rAddr.Column; mnRow = rAddr.Row; }
98 :
99 : void read( SequenceInputStream& rStrm );
100 : void read( BiffInputStream& rStrm, bool bCol16Bit = true, bool bRow32Bit = false );
101 : };
102 :
103 : inline bool operator==( const BinAddress& rL, const BinAddress& rR )
104 : {
105 : return (rL.mnCol == rR.mnCol) && (rL.mnRow == rR.mnRow);
106 : }
107 :
108 58 : inline bool operator<( const BinAddress& rL, const BinAddress& rR )
109 : {
110 58 : return (rL.mnCol < rR.mnCol) || ((rL.mnCol == rR.mnCol) && (rL.mnRow < rR.mnRow));
111 : }
112 :
113 6 : inline SequenceInputStream& operator>>( SequenceInputStream& rStrm, BinAddress& orPos )
114 : {
115 6 : orPos.read( rStrm );
116 6 : return rStrm;
117 : }
118 :
119 0 : inline BiffInputStream& operator>>( BiffInputStream& rStrm, BinAddress& orPos )
120 : {
121 0 : orPos.read( rStrm );
122 0 : return rStrm;
123 : }
124 :
125 : /** A 2D cell range address struct for binary filters. */
126 : struct BinRange
127 : {
128 : BinAddress maFirst;
129 : BinAddress maLast;
130 :
131 9 : inline explicit BinRange() {}
132 : inline explicit BinRange( const BinAddress& rAddr ) : maFirst( rAddr ), maLast( rAddr ) {}
133 : inline explicit BinRange( const BinAddress& rFirst, const BinAddress& rLast ) : maFirst( rFirst ), maLast( rLast ) {}
134 : inline explicit BinRange( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nCol2, sal_Int32 nRow2 ) :
135 : maFirst( nCol1, nRow1 ), maLast( nCol2, nRow2 ) {}
136 : inline explicit BinRange( const ::com::sun::star::table::CellAddress& rAddr ) : maFirst( rAddr ), maLast( rAddr ) {}
137 : inline explicit BinRange( const ::com::sun::star::table::CellAddress& rFirst, const ::com::sun::star::table::CellAddress& rLast ) : maFirst( rFirst ), maLast( rLast ) {}
138 : inline explicit BinRange( const ::com::sun::star::table::CellRangeAddress& rRange ) : maFirst( rRange.StartColumn, rRange.StartRow ), maLast( rRange.EndColumn, rRange.EndRow ) {}
139 :
140 : inline void set( const BinAddress& rFirst, const BinAddress& rLast )
141 : { maFirst = rFirst; maLast = rLast; }
142 : inline void set( sal_Int32 nCol1, sal_Int32 nRow1, sal_Int32 nCol2, sal_Int32 nRow2 )
143 : { maFirst.set( nCol1, nRow1 ); maLast.set( nCol2, nRow2 ); }
144 : inline void set( const ::com::sun::star::table::CellAddress& rFirst, const ::com::sun::star::table::CellAddress& rLast )
145 : { maFirst.set( rFirst ); maLast.set( rLast ); }
146 : inline void set( const ::com::sun::star::table::CellRangeAddress& rRange )
147 : { maFirst.set( rRange.StartColumn, rRange.StartRow ); maLast.set( rRange.EndColumn, rRange.EndRow ); }
148 :
149 : inline sal_Int32 getColCount() const { return maLast.mnCol - maFirst.mnCol + 1; }
150 : inline sal_Int32 getRowCount() const { return maLast.mnRow - maFirst.mnRow + 1; }
151 :
152 : void read( SequenceInputStream& rStrm );
153 : void read( BiffInputStream& rStrm, bool bCol16Bit = true, bool bRow32Bit = false );
154 : };
155 :
156 : inline bool operator==( const BinRange& rL, const BinRange& rR )
157 : {
158 : return (rL.maFirst == rR.maFirst) && (rL.maLast == rR.maLast);
159 : }
160 :
161 : inline bool operator<( const BinRange& rL, const BinRange& rR )
162 : {
163 : return (rL.maFirst < rR.maFirst) || ((rL.maFirst == rR.maFirst) && (rL.maLast < rR.maLast));
164 : }
165 :
166 3 : inline SequenceInputStream& operator>>( SequenceInputStream& rStrm, BinRange& orRange )
167 : {
168 3 : orRange.read( rStrm );
169 3 : return rStrm;
170 : }
171 :
172 0 : inline BiffInputStream& operator>>( BiffInputStream& rStrm, BinRange& orRange )
173 : {
174 0 : orRange.read( rStrm );
175 0 : return rStrm;
176 : }
177 :
178 : /** A 2D cell range address list for binary filters. */
179 3 : class BinRangeList
180 : {
181 : public:
182 3 : inline explicit BinRangeList() : mvRanges() {}
183 :
184 3 : ::std::vector< BinRange >::const_iterator begin() const { return mvRanges.begin(); }
185 3 : ::std::vector< BinRange >::const_iterator end() const { return mvRanges.end(); }
186 :
187 : void read( SequenceInputStream& rStrm );
188 :
189 : private:
190 : ::std::vector< BinRange > mvRanges;
191 : };
192 :
193 3 : inline SequenceInputStream& operator>>( SequenceInputStream& rStrm, BinRangeList& orRanges )
194 : {
195 3 : orRanges.read( rStrm );
196 3 : return rStrm;
197 : }
198 :
199 : /** Different target types that can be encoded in a BIFF URL. */
200 : enum BiffTargetType
201 : {
202 : BIFF_TARGETTYPE_URL, /// URL, URL with sheet name, or sheet name.
203 : BIFF_TARGETTYPE_SAMESHEET, /// Target for special '!A1' syntax to refer to current sheet.
204 : BIFF_TARGETTYPE_LIBRARY, /// Library directory in application installation.
205 : BIFF_TARGETTYPE_DDE_OLE, /// DDE server/topic or OLE class/target.
206 : BIFF_TARGETTYPE_UNKNOWN /// Unknown/unsupported target type.
207 : };
208 :
209 : /** Converter for cell addresses and cell ranges for OOXML and BIFF filters.
210 : */
211 290 : class AddressConverter : public WorkbookHelper
212 : {
213 : public:
214 : explicit AddressConverter( const WorkbookHelper& rHelper );
215 :
216 : /** Tries to parse the passed string for a 2d cell address in A1 notation.
217 :
218 : This function accepts all strings that match the regular expression
219 : "[a-zA-Z]{1,6}0*[1-9][0-9]{0,8}" (without quotes), i.e. 1 to 6 letters
220 : for the column index (translated to 0-based column indexes from 0 to
221 : 321,272,405), and 1 to 9 digits for the 1-based row index (translated
222 : to 0-based row indexes from 0 to 999,999,998). The row number part may
223 : contain leading zeros, they will be ignored. It is up to the caller to
224 : handle cell addresses outside of a specific valid range (e.g. the
225 : entire spreadsheet).
226 :
227 : @param ornColumn (out-parameter) Returns the converted column index.
228 : @param ornRow (out-parameter) returns the converted row index.
229 : @param rString The string containing the cell address.
230 : @param nStart Start index of string part in rString to be parsed.
231 : @param nLength Length of string part in rString to be parsed.
232 :
233 : @return true = Parsed string was valid, returned values can be used.
234 : */
235 : static bool parseOoxAddress2d(
236 : sal_Int32& ornColumn, sal_Int32& ornRow,
237 : const OUString& rString,
238 : sal_Int32 nStart = 0,
239 : sal_Int32 nLength = SAL_MAX_INT32 );
240 :
241 : static bool parseOoxAddress2d(
242 : sal_Int32& ornColumn, sal_Int32& ornRow, const char* pStr );
243 :
244 : /** Tries to parse the passed string for a 2d cell range in A1 notation.
245 :
246 : This function accepts all strings that match the regular expression
247 : "ADDR(:ADDR)?" (without quotes), where ADDR is a cell address accepted
248 : by the parseOoxAddress2d() function of this class. It is up to the
249 : caller to handle cell ranges outside of a specific valid range (e.g.
250 : the entire spreadsheet).
251 :
252 : @param ornStartColumn (out-parameter) Returns the converted start column index.
253 : @param ornStartRow (out-parameter) returns the converted start row index.
254 : @param ornEndColumn (out-parameter) Returns the converted end column index.
255 : @param ornEndRow (out-parameter) returns the converted end row index.
256 : @param rString The string containing the cell address.
257 : @param nStart Start index of string part in rString to be parsed.
258 : @param nLength Length of string part in rString to be parsed.
259 :
260 : @return true = Parsed string was valid, returned values can be used.
261 : */
262 : static bool parseOoxRange2d(
263 : sal_Int32& ornStartColumn, sal_Int32& ornStartRow,
264 : sal_Int32& ornEndColumn, sal_Int32& ornEndRow,
265 : const OUString& rString,
266 : sal_Int32 nStart = 0,
267 : sal_Int32 nLength = SAL_MAX_INT32 );
268 :
269 : /** Returns the biggest valid cell address in the own Calc document. */
270 : inline const ::com::sun::star::table::CellAddress&
271 2503 : getMaxApiAddress() const { return maMaxApiPos; }
272 :
273 : /** Returns the biggest valid cell address in the imported/exported
274 : Excel document. */
275 : inline const ::com::sun::star::table::CellAddress&
276 828 : getMaxXlsAddress() const { return maMaxXlsPos; }
277 :
278 : /** Returns the biggest valid cell address in both Calc and the
279 : imported/exported Excel document. */
280 : inline const ::com::sun::star::table::CellAddress&
281 0 : getMaxAddress() const { return maMaxPos; }
282 :
283 : /** Returns the column overflow status. */
284 : inline bool isColOverflow() const { return mbColOverflow; }
285 : /** Returns the row overflow status. */
286 : inline bool isRowOverflow() const { return mbRowOverflow; }
287 : /** Returns the sheet overflow status. */
288 : inline bool isTabOverflow() const { return mbTabOverflow; }
289 :
290 : /** Checks if the passed column index is valid.
291 :
292 : @param nCol The column index to check.
293 : @param bTrackOverflow true = Update the internal overflow flag, if the
294 : column index is outside of the supported limits.
295 : @return true = Passed column index is valid (no index overflow).
296 : */
297 : bool checkCol( sal_Int32 nCol, bool bTrackOverflow );
298 :
299 : /** Checks if the passed row index is valid.
300 :
301 : @param nRow The row index to check.
302 : @param bTrackOverflow true = Update the internal overflow flag, if the
303 : row index is outside of the supported limits.
304 : @return true = Passed row index is valid (no index overflow).
305 : */
306 : bool checkRow( sal_Int32 nRow, bool bTrackOverflow );
307 :
308 : /** Checks if the passed sheet index is valid.
309 :
310 : @param nSheet The sheet index to check.
311 : @param bTrackOverflow true = Update the internal overflow flag, if the
312 : sheet index is outside of the supported limits.
313 : @return true = Passed sheet index is valid (no index overflow).
314 : */
315 : bool checkTab( sal_Int16 nSheet, bool bTrackOverflow );
316 :
317 : /** Checks the passed cell address if it fits into the spreadsheet limits.
318 :
319 : @param rAddress The cell address to be checked.
320 : @param bTrackOverflow true = Update the internal overflow flags, if
321 : the address is outside of the supported sheet limits.
322 : @return true = Passed address is valid (no index overflow).
323 : */
324 : bool checkCellAddress(
325 : const ::com::sun::star::table::CellAddress& rAddress,
326 : bool bTrackOverflow );
327 :
328 : /** Converts the passed string to a single cell address, without checking
329 : any sheet limits.
330 :
331 : @param orAddress (out-parameter) Returns the converted cell address.
332 : @param rString Cell address string in A1 notation.
333 : @param nSheet Sheet index to be inserted into orAddress.
334 : @return true = Cell address could be parsed from the passed string.
335 : */
336 : static bool convertToCellAddressUnchecked(
337 : ::com::sun::star::table::CellAddress& orAddress,
338 : const OUString& rString,
339 : sal_Int16 nSheet );
340 :
341 : static bool convertToCellAddressUnchecked(
342 : com::sun::star::table::CellAddress& orAddress, const char* pStr, sal_Int16 nSheet );
343 :
344 : /** Tries to convert the passed string to a single cell address.
345 :
346 : @param orAddress (out-parameter) Returns the converted cell address.
347 : @param rString Cell address string in A1 notation.
348 : @param nSheet Sheet index to be inserted into orAddress (will be checked).
349 : @param bTrackOverflow true = Update the internal overflow flags, if
350 : the address is outside of the supported sheet limits.
351 : @return true = Converted address is valid (no index overflow).
352 : */
353 : bool convertToCellAddress(
354 : ::com::sun::star::table::CellAddress& orAddress,
355 : const OUString& rString,
356 : sal_Int16 nSheet,
357 : bool bTrackOverflow );
358 :
359 : bool convertToCellAddress(
360 : com::sun::star::table::CellAddress& rAddress,
361 : const char* pStr, sal_Int16 nSheet, bool bTrackOverflow );
362 :
363 : /** Returns a valid cell address by moving it into allowed dimensions.
364 :
365 : @param rString Cell address string in A1 notation.
366 : @param nSheet Sheet index for the returned address (will be checked).
367 : @param bTrackOverflow true = Update the internal overflow flags, if
368 : the address is outside of the supported sheet limits.
369 : @return A valid API cell address struct. */
370 : ::com::sun::star::table::CellAddress
371 : createValidCellAddress(
372 : const OUString& rString,
373 : sal_Int16 nSheet,
374 : bool bTrackOverflow );
375 :
376 : /** Converts the passed address to a single cell address, without checking
377 : any sheet limits.
378 :
379 : @param orAddress (out-parameter) Returns the converted cell address.
380 : @param rBinAddress Binary cell address struct.
381 : @param nSheet Sheet index to be inserted into orAddress.
382 : */
383 : static void convertToCellAddressUnchecked(
384 : ::com::sun::star::table::CellAddress& orAddress,
385 : const BinAddress& rBinAddress,
386 : sal_Int16 nSheet );
387 :
388 : /** Tries to convert the passed address to a single cell address.
389 :
390 : @param orAddress (out-parameter) Returns the converted cell address.
391 : @param rBinAddress Binary cell address struct.
392 : @param nSheet Sheet index to be inserted into orAddress (will be checked).
393 : @param bTrackOverflow true = Update the internal overflow flags, if
394 : the address is outside of the supported sheet limits.
395 : @return true = Converted address is valid (no index overflow).
396 : */
397 : bool convertToCellAddress(
398 : ::com::sun::star::table::CellAddress& orAddress,
399 : const BinAddress& rBinAddress,
400 : sal_Int16 nSheet,
401 : bool bTrackOverflow );
402 :
403 : /** Returns a valid cell address by moving it into allowed dimensions.
404 :
405 : @param rBinAddress Binary cell address struct.
406 : @param nSheet Sheet index for the returned address (will be checked).
407 : @param bTrackOverflow true = Update the internal overflow flags, if
408 : the address is outside of the supported sheet limits.
409 : @return A valid API cell address struct. */
410 : ::com::sun::star::table::CellAddress
411 : createValidCellAddress(
412 : const BinAddress& rBinAddress,
413 : sal_Int16 nSheet,
414 : bool bTrackOverflow );
415 :
416 : /** Checks the passed cell range if it fits into the spreadsheet limits.
417 :
418 : @param rRange The cell range address to be checked.
419 : @param bAllowOverflow true = Allow ranges that start inside the
420 : supported sheet limits but may end outside of these limits.
421 : false = Do not allow ranges that overflow the supported limits.
422 : @param bTrackOverflow true = Update the internal overflow flags, if
423 : the passed range contains cells outside of the supported sheet
424 : limits.
425 : @return true = Cell range is valid. This function returns also true,
426 : if only parts of the range are outside the current sheet limits and
427 : such an overflow is allowed via parameter bAllowOverflow. Returns
428 : false, if the entire range is outside the sheet limits, or if
429 : overflow is not allowed via parameter bAllowOverflow.
430 : */
431 : bool checkCellRange(
432 : const ::com::sun::star::table::CellRangeAddress& rRange,
433 : bool bAllowOverflow, bool bTrackOverflow );
434 :
435 : /** Checks the passed cell range, may try to fit it to current sheet limits.
436 :
437 : First, this function reorders the column and row indexes so that the
438 : starting indexes are less than or equal to the end indexes. Then,
439 : depending on the parameter bAllowOverflow, the range is just checked or
440 : cropped to the current sheet limits.
441 :
442 : @param orRange (in-out-parameter) Converts the passed cell range
443 : into a valid cell range address. If the passed range contains cells
444 : outside the currently supported spreadsheet limits, it will be
445 : cropped to these limits.
446 : @param bAllowOverflow true = Allow ranges that start inside the
447 : supported sheet limits but may end outside of these limits. The
448 : cell range returned in orRange will be cropped to these limits.
449 : false = Do not allow ranges that overflow the supported limits. The
450 : function will return false when the range overflows the sheet limits.
451 : @param bTrackOverflow true = Update the internal overflow flags, if
452 : the original range contains cells outside of the supported sheet
453 : limits.
454 : @return true = Converted range address is valid. This function
455 : returns also true, if overflowing ranges are allowed via parameter
456 : bAllowOverflow and the range has been cropped, but still contains
457 : cells inside the current sheet limits. Returns false, if the entire
458 : range is outside the sheet limits or overflowing ranges are not
459 : allowed via parameter bAllowOverflow.
460 : */
461 : bool validateCellRange(
462 : ::com::sun::star::table::CellRangeAddress& orRange,
463 : bool bAllowOverflow, bool bTrackOverflow );
464 :
465 : /** Converts the passed string to a cell range address, without checking
466 : any sheet limits.
467 :
468 : @param orRange (out-parameter) Returns the converted range address.
469 : @param rString Cell range string in A1 notation.
470 : @param nSheet Sheet index to be inserted into orRange.
471 : @return true = Range address could be parsed from the passed string.
472 : */
473 : static bool convertToCellRangeUnchecked(
474 : ::com::sun::star::table::CellRangeAddress& orRange,
475 : const OUString& rString,
476 : sal_Int16 nSheet );
477 :
478 : /** Tries to convert the passed string to a cell range address.
479 :
480 : @param orRange (out-parameter) Returns the converted cell range
481 : address. If the original range in the passed string contains cells
482 : outside the currently supported spreadsheet limits, and parameter
483 : bAllowOverflow is set to true, the range will be cropped to these
484 : limits. Example: the range string "A1:ZZ100000" may be converted to
485 : the range A1:IV65536.
486 : @param rString Cell range string in A1 notation.
487 : @param nSheet Sheet index to be inserted into orRange (will be checked).
488 : @param bAllowOverflow true = Allow ranges that start inside the
489 : supported sheet limits but may end outside of these limits. The
490 : cell range returned in orRange will be cropped to these limits.
491 : false = Do not allow ranges that overflow the supported limits.
492 : @param bTrackOverflow true = Update the internal overflow flags, if
493 : the original range contains cells outside of the supported sheet
494 : limits.
495 : @return true = Converted and returned range is valid. This function
496 : returns also true, if overflowing ranges are allowed via parameter
497 : bAllowOverflow and the range has been cropped, but still contains
498 : cells inside the current sheet limits. Returns false, if the entire
499 : range is outside the sheet limits or overflowing ranges are not
500 : allowed via parameter bAllowOverflow.
501 : */
502 : bool convertToCellRange(
503 : ::com::sun::star::table::CellRangeAddress& orRange,
504 : const OUString& rString,
505 : sal_Int16 nSheet,
506 : bool bAllowOverflow, bool bTrackOverflow );
507 :
508 : /** Converts the passed range to a cell range address, without checking any
509 : sheet limits.
510 :
511 : @param orRange (out-parameter) Returns the converted range address.
512 : @param rBinRange Binary cell range struct.
513 : @param nSheet Sheet index to be inserted into orRange.
514 : */
515 : static void convertToCellRangeUnchecked(
516 : ::com::sun::star::table::CellRangeAddress& orRange,
517 : const BinRange& rBinRange,
518 : sal_Int16 nSheet );
519 :
520 : /** Tries to convert the passed range to a cell range address.
521 :
522 : @param orRange (out-parameter) Returns the converted cell range
523 : address. If the passed original range contains cells outside the
524 : currently supported spreadsheet limits, and parameter bAllowOverflow
525 : is set to true, the range will be cropped to these limits.
526 : @param rBinRange Binary cell range struct.
527 : @param nSheet Sheet index to be inserted into orRange (will be checked).
528 : @param bAllowOverflow true = Allow ranges that start inside the
529 : supported sheet limits but may end outside of these limits. The
530 : cell range returned in orRange will be cropped to these limits.
531 : false = Do not allow ranges that overflow the supported limits.
532 : @param bTrackOverflow true = Update the internal overflow flags, if
533 : the original range contains cells outside of the supported sheet
534 : limits.
535 : @return true = Converted and returned range is valid. This function
536 : returns also true, if overflowing ranges are allowed via parameter
537 : bAllowOverflow and the range has been cropped, but still contains
538 : cells inside the current sheet limits. Returns false, if the entire
539 : range is outside the sheet limits or if overflowing ranges are not
540 : allowed via parameter bAllowOverflow.
541 : */
542 : bool convertToCellRange(
543 : ::com::sun::star::table::CellRangeAddress& orRange,
544 : const BinRange& rBinRange,
545 : sal_Int16 nSheet,
546 : bool bAllowOverflow, bool bTrackOverflow );
547 :
548 : /** Tries to restrict the passed cell range list to current sheet limits.
549 :
550 : @param orRanges (in-out-parameter) Restricts the cell range addresses
551 : in the passed list to the current sheet limits and removes invalid
552 : ranges from the list.
553 : @param bTrackOverflow true = Update the internal overflow flags, if
554 : the original ranges contain cells outside of the supported sheet
555 : limits.
556 : */
557 : void validateCellRangeList(
558 : ApiCellRangeList& orRanges,
559 : bool bTrackOverflow );
560 :
561 : /** Tries to convert the passed string to a cell range list.
562 :
563 : @param orRanges (out-parameter) Returns the converted cell range
564 : addresses. If a range in the passed string contains cells outside
565 : the currently supported spreadsheet limits, it will be cropped to
566 : these limits. Example: the range string "A1:ZZ100000" may be
567 : converted to the range A1:IV65536. If a range is completely outside
568 : the limits, it will be omitted.
569 : @param rString Cell range list string in A1 notation, space separated.
570 : @param nSheet Sheet index to be inserted into orRanges (will be checked).
571 : @param bTrackOverflow true = Update the internal overflow flags, if
572 : the original ranges contain cells outside of the supported sheet
573 : limits.
574 : */
575 : void convertToCellRangeList(
576 : ApiCellRangeList& orRanges,
577 : const OUString& rString,
578 : sal_Int16 nSheet,
579 : bool bTrackOverflow );
580 :
581 : /** Tries to convert the passed range list to a cell range list.
582 :
583 : @param orRanges (out-parameter) Returns the converted cell range
584 : addresses. If a range in the passed string contains cells outside
585 : the currently supported spreadsheet limits, it will be cropped to
586 : these limits. Example: the range string "A1:ZZ100000" may be
587 : converted to the range A1:IV65536. If a range is completely outside
588 : the limits, it will be omitted.
589 : @param rBinRanges List of binary cell range objects.
590 : @param nSheet Sheet index to be inserted into orRanges (will be checked).
591 : @param bTrackOverflow true = Update the internal overflow flags, if
592 : the original ranges contain cells outside of the supported sheet
593 : limits.
594 : */
595 : void convertToCellRangeList(
596 : ApiCellRangeList& orRanges,
597 : const BinRangeList& rBinRanges,
598 : sal_Int16 nSheet,
599 : bool bTrackOverflow );
600 :
601 : private:
602 : void initializeMaxPos(
603 : sal_Int16 nMaxXlsTab, sal_Int32 nMaxXlsCol, sal_Int32 nMaxXlsRow );
604 :
605 : private:
606 : struct ControlCharacters
607 : {
608 : sal_Unicode mcThisWorkbook; /// Control character: Link to current workbook.
609 : sal_Unicode mcExternal; /// Control character: Link to external workbook/sheet.
610 : sal_Unicode mcThisSheet; /// Control character: Link to current sheet.
611 : sal_Unicode mcInternal; /// Control character: Link to internal sheet.
612 : sal_Unicode mcSameSheet; /// Control character: Link to same sheet (special '!A1' syntax).
613 :
614 : void set(
615 : sal_Unicode cThisWorkbook, sal_Unicode cExternal,
616 : sal_Unicode cThisSheet, sal_Unicode cInternal,
617 : sal_Unicode cSameSheet );
618 : };
619 :
620 : ::com::sun::star::table::CellAddress maMaxApiPos; /// Maximum valid cell address in Calc.
621 : ::com::sun::star::table::CellAddress maMaxXlsPos; /// Maximum valid cell address in Excel.
622 : ::com::sun::star::table::CellAddress maMaxPos; /// Maximum valid cell address in Calc/Excel.
623 : ControlCharacters maLinkChars; /// Control characters for external link import (BIFF).
624 : ControlCharacters maDConChars; /// Control characters for DCON* record import (BIFF).
625 : bool mbColOverflow; /// Flag for "columns overflow".
626 : bool mbRowOverflow; /// Flag for "rows overflow".
627 : bool mbTabOverflow; /// Flag for "tables overflow".
628 : };
629 :
630 : } // namespace xls
631 : } // namespace oox
632 :
633 : #endif
634 :
635 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|