LibreOffice Module sc (master) 1
addressconverter.hxx
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#pragma once
21
22#include <vector>
23#include <rangelst.hxx>
24#include "workbookhelper.hxx"
25#include <com/sun/star/uno/Sequence.h>
26
27namespace com::sun::star::table { struct CellRangeAddress; }
28namespace oox { class SequenceInputStream; }
29
30namespace oox {
31namespace xls {
32
35{
36 sal_Int32 mnCol;
37 sal_Int32 mnRow;
38
39 explicit BinAddress() : mnCol( 0 ), mnRow( 0 ) {}
40 explicit BinAddress( sal_Int32 nCol, sal_Int32 nRow ) : mnCol( nCol ), mnRow( nRow ) {}
41 explicit BinAddress( const ScAddress& rAddr ) : mnCol( rAddr.Col() ), mnRow( rAddr.Row() ) {}
42
43 void read( SequenceInputStream& rStrm );
44};
45
46inline bool operator<( const BinAddress& rL, const BinAddress& rR )
47{
48 return (rL.mnCol < rR.mnCol) || ((rL.mnCol == rR.mnCol) && (rL.mnRow < rR.mnRow));
49}
50
52{
53 orPos.read( rStrm );
54 return rStrm;
55}
56
59{
62
63 void read( SequenceInputStream& rStrm );
64};
65
67{
68 orRange.read( rStrm );
69 return rStrm;
70}
71
74{
75public:
76 explicit BinRangeList() : mvRanges() {}
77
78 ::std::vector< BinRange >::const_iterator begin() const { return mvRanges.begin(); }
79 ::std::vector< BinRange >::const_iterator end() const { return mvRanges.end(); }
80
81 void read( SequenceInputStream& rStrm );
82
83private:
84 ::std::vector< BinRange > mvRanges;
85};
86
88{
89 orRanges.read( rStrm );
90 return rStrm;
91}
92
95class AddressConverter final : public WorkbookHelper
96{
97public:
98 explicit AddressConverter( const WorkbookHelper& rHelper );
99
119 static bool parseOoxAddress2d(
120 sal_Int32& ornColumn, sal_Int32& ornRow,
121 const OUString& rString,
122 sal_Int32 nStart = 0,
123 sal_Int32 nLength = SAL_MAX_INT32 );
124
125 static bool parseOoxAddress2d(
126 sal_Int32& ornColumn, sal_Int32& ornRow, std::string_view pStr );
127
145 static bool parseOoxRange2d(
146 sal_Int32& ornStartColumn, sal_Int32& ornStartRow,
147 sal_Int32& ornEndColumn, sal_Int32& ornEndRow,
148 const OUString& rString,
149 sal_Int32 nStart = 0 );
150
152 const ScAddress&
153 getMaxApiAddress() const { return maMaxApiPos; }
154
157 const ScAddress&
158 getMaxXlsAddress() const { return maMaxXlsPos; }
159
162 const ScAddress&
163 getMaxAddress() const { return maMaxPos; }
164
172 bool checkCol( sal_Int32 nCol, bool bTrackOverflow );
173
181 bool checkRow( sal_Int32 nRow, bool bTrackOverflow );
182
190 bool checkTab( sal_Int16 nSheet, bool bTrackOverflow );
191
199 bool checkCellAddress(
200 const ScAddress& rAddress,
201 bool bTrackOverflow );
202
212 ScAddress& orAddress,
213 const OUString& rString,
214 sal_Int16 nSheet );
215
217 ScAddress& orAddress, std::string_view pStr, sal_Int16 nSheet );
218
229 ScAddress& orAddress,
230 const OUString& rString,
231 sal_Int16 nSheet,
232 bool bTrackOverflow );
233
235 ScAddress& rAddress,
236 std::string_view pStr, sal_Int16 nSheet, bool bTrackOverflow );
237
246 const OUString& rString,
247 sal_Int16 nSheet,
248 bool bTrackOverflow );
249
258 ScAddress& orAddress,
259 const BinAddress& rBinAddress,
260 sal_Int16 nSheet );
261
272 ScAddress& orAddress,
273 const BinAddress& rBinAddress,
274 sal_Int16 nSheet,
275 bool bTrackOverflow );
276
285 const BinAddress& rBinAddress,
286 sal_Int16 nSheet,
287 bool bTrackOverflow );
288
304 bool checkCellRange(
305 const ScRange& rRange,
306 bool bAllowOverflow, bool bTrackOverflow );
307
335 ScRange& orRange,
336 bool bAllowOverflow, bool bTrackOverflow );
337
346 static bool convertToCellRangeUnchecked(
347 ScRange& orRange,
348 const OUString& rString,
349 sal_Int16 nSheet );
350
376 ScRange& orRange,
377 const OUString& rString,
378 sal_Int16 nSheet,
379 bool bAllowOverflow, bool bTrackOverflow );
380
388 static void convertToCellRangeUnchecked(
389 ScRange& orRange,
390 const BinRange& rBinRange,
391 sal_Int16 nSheet );
392
416 ScRange& orRange,
417 const BinRange& rBinRange,
418 sal_Int16 nSheet,
419 bool bAllowOverflow, bool bTrackOverflow );
420
421
432 ScRangeList& orRanges,
433 bool bTrackOverflow );
434
450 ScRangeList& orRanges,
451 const OUString& rString,
452 sal_Int16 nSheet,
453 bool bTrackOverflow );
454
470 ScRangeList& orRanges,
471 const BinRangeList& rBinRanges,
472 sal_Int16 nSheet,
473 bool bTrackOverflow );
474
481 static css::uno::Sequence<css::table::CellRangeAddress>
482 toApiSequence(const ScRangeList& orRanges);
483
484 bool isColOverflow() const { return mbColOverflow; }
485 bool isRowOverflow() const { return mbRowOverflow; }
486 bool isTabOverflow() const { return mbTabOverflow; }
487
488private:
489 void initializeMaxPos(
490 sal_Int16 nMaxXlsTab, sal_Int32 nMaxXlsCol, sal_Int32 nMaxXlsRow );
491
492private:
499};
500
501} // namespace xls
502} // namespace oox
503
504
505/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Converter for cell addresses and cell ranges for OOXML and BIFF filters.
bool mbTabOverflow
Flag for "rows overflow".
ScAddress maMaxXlsPos
Maximum valid cell address in Calc.
bool convertToCellAddress(ScAddress &orAddress, const OUString &rString, sal_Int16 nSheet, bool bTrackOverflow)
Tries to convert the passed string to a single cell address.
bool checkCellAddress(const ScAddress &rAddress, bool bTrackOverflow)
Checks the passed cell address if it fits into the spreadsheet limits.
static bool convertToCellRangeUnchecked(ScRange &orRange, const OUString &rString, sal_Int16 nSheet)
Converts the passed string to a cell range address, without checking any sheet limits.
const ScAddress & getMaxXlsAddress() const
Returns the biggest valid cell address in the imported/exported Excel document.
bool mbColOverflow
Maximum valid cell address in Calc/Excel.
bool checkRow(sal_Int32 nRow, bool bTrackOverflow)
Checks if the passed row index is valid.
static bool parseOoxAddress2d(sal_Int32 &ornColumn, sal_Int32 &ornRow, const OUString &rString, sal_Int32 nStart=0, sal_Int32 nLength=SAL_MAX_INT32)
Tries to parse the passed string for a 2d cell address in A1 notation.
static bool parseOoxRange2d(sal_Int32 &ornStartColumn, sal_Int32 &ornStartRow, sal_Int32 &ornEndColumn, sal_Int32 &ornEndRow, const OUString &rString, sal_Int32 nStart=0)
Tries to parse the passed string for a 2d cell range in A1 notation.
bool checkCol(sal_Int32 nCol, bool bTrackOverflow)
Checks if the passed column index is valid.
bool convertToCellRange(ScRange &orRange, const OUString &rString, sal_Int16 nSheet, bool bAllowOverflow, bool bTrackOverflow)
Tries to convert the passed string to a cell range address.
ScAddress maMaxPos
Maximum valid cell address in Excel.
static css::uno::Sequence< css::table::CellRangeAddress > toApiSequence(const ScRangeList &orRanges)
Converts the passed range list to a sequence of cell range addresses.
ScAddress createValidCellAddress(const OUString &rString, sal_Int16 nSheet, bool bTrackOverflow)
Returns a valid cell address by moving it into allowed dimensions.
bool checkCellRange(const ScRange &rRange, bool bAllowOverflow, bool bTrackOverflow)
Checks the passed cell range if it fits into the spreadsheet limits.
AddressConverter(const WorkbookHelper &rHelper)
bool mbRowOverflow
Flag for "columns overflow".
const ScAddress & getMaxApiAddress() const
Returns the biggest valid cell address in the own Calc document.
bool checkTab(sal_Int16 nSheet, bool bTrackOverflow)
Checks if the passed sheet index is valid.
void initializeMaxPos(sal_Int16 nMaxXlsTab, sal_Int32 nMaxXlsCol, sal_Int32 nMaxXlsRow)
void validateCellRangeList(ScRangeList &orRanges, bool bTrackOverflow)
Tries to restrict the passed cell range list to current sheet limits.
void convertToCellRangeList(ScRangeList &orRanges, const OUString &rString, sal_Int16 nSheet, bool bTrackOverflow)
Tries to convert the passed string to a cell range list.
bool validateCellRange(ScRange &orRange, bool bAllowOverflow, bool bTrackOverflow)
Checks the passed cell range, may try to fit it to current sheet limits.
const ScAddress & getMaxAddress() const
Returns the biggest valid cell address in both Calc and the imported/exported Excel document.
static bool convertToCellAddressUnchecked(ScAddress &orAddress, const OUString &rString, sal_Int16 nSheet)
Converts the passed string to a single cell address, without checking any sheet limits.
A 2D cell range address list for binary filters.
void read(SequenceInputStream &rStrm)
::std::vector< BinRange >::const_iterator begin() const
::std::vector< BinRange > mvRanges
::std::vector< BinRange >::const_iterator end() const
Helper class to provide access to global workbook data.
void SvStream & rStrm
SequenceInputStream & operator>>(SequenceInputStream &rStrm, BinAddress &orPos)
bool operator<(const BinAddress &rL, const BinAddress &rR)
A 2D cell address struct for binary filters.
BinAddress(const ScAddress &rAddr)
void read(SequenceInputStream &rStrm)
BinAddress(sal_Int32 nCol, sal_Int32 nRow)
A 2D cell range address struct for binary filters.
void read(SequenceInputStream &rStrm)
#define SAL_MAX_INT32
sal_Int32 nLength