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