22#include <com/sun/star/container/XIndexAccess.hpp>
23#include <com/sun/star/sheet/XCellRangeAddressable.hpp>
24#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
27#include <osl/diagnose.h>
41const sal_Int16 API_MAXTAB =
MAXTAB;
43const sal_Int32 OOX_MAXCOL =
static_cast< sal_Int32
>( (1 << 14) - 1 );
44const sal_Int32 OOX_MAXROW =
static_cast< sal_Int32
>( (1 << 20) - 1 );
45const sal_Int16 OOX_MAXTAB =
static_cast< sal_Int16
>( (1 << 15) - 1 );
67 mvRanges.resize( getLimitedValue< size_t, sal_Int64 >(
nCount, 0,
rStrm.getRemaining() / 16 ) );
74 mbColOverflow( false ),
75 mbRowOverflow( false ),
76 mbTabOverflow( false )
82 sal_Int32& ornColumn, sal_Int32& ornRow,
83 std::u16string_view aString, sal_Int32 nStart, sal_Int32 nLength )
85 ornColumn = ornRow = 0;
86 if( (nStart < 0) || (nStart >= sal_Int32(aString.size())) || (
nLength < 2) )
89 const sal_Unicode* pcChar = aString.data() + nStart;
90 const sal_Unicode* pcEndChar = pcChar + ::std::min(
nLength, sal_Int32(aString.size() - nStart) );
92 enum { STATE_COL, STATE_ROW } eState = STATE_COL;
93 while( pcChar < pcEndChar )
100 if( (
'a' <= cChar) && (cChar <=
'z') )
101 cChar = (cChar -
'a') +
'A';
102 if( (
'A' <= cChar) && (cChar <=
'Z') )
106 if( ornColumn >= 12356631 )
108 ornColumn = (ornColumn * 26) + (cChar -
'A' + 1);
110 else if( ornColumn > 0 )
122 if( (
'0' <= cChar) && (cChar <=
'9') )
125 if( ornRow >= 100000000 )
127 ornRow = (ornRow * 10) + (cChar -
'0');
139 return (ornColumn >= 0) && (ornRow >= 0);
144 ornColumn = ornRow = 0;
146 enum { STATE_COL, STATE_ROW } eState = STATE_COL;
148 const char* pStr =
aStr.data();
149 while (pStr !=
aStr.data() +
aStr.size())
156 if( (
'a' <= cChar) && (cChar <=
'z') )
157 cChar = (cChar -
'a') +
'A';
158 if( (
'A' <= cChar) && (cChar <=
'Z') )
162 if( ornColumn >= 12356631 )
164 ornColumn = (ornColumn * 26) + (cChar -
'A' + 1);
166 else if( ornColumn > 0 )
178 if( (
'0' <= cChar) && (cChar <=
'9') )
181 if( ornRow >= 100000000 )
183 ornRow = (ornRow * 10) + (cChar -
'0');
195 return (ornColumn >= 0) && (ornRow >= 0);
199 sal_Int32& ornStartColumn, sal_Int32& ornStartRow,
200 sal_Int32& ornEndColumn, sal_Int32& ornEndRow,
201 std::u16string_view aString, sal_Int32 nStart )
203 ornStartColumn = ornStartRow = ornEndColumn = ornEndRow = 0;
204 if( (nStart < 0) || (nStart >= sal_Int32(aString.size())) )
207 sal_Int32 nEnd = nStart + ( aString.size() - nStart );
208 size_t nColonPos = aString.find(
':', nStart );
209 if( nColonPos != std::u16string_view::npos && (nStart < sal_Int32(nColonPos)) && (sal_Int32(nColonPos + 1) < nEnd) )
212 parseOoxAddress2d( ornStartColumn, ornStartRow, aString, nStart, nColonPos - nStart ) &&
218 ornEndColumn = ornStartColumn;
219 ornEndRow = ornStartRow;
228 bool bValid = (0 <= nCol) && ( nCol <=
maMaxPos.
Col() );
229 if( !bValid && bTrackOverflow )
236 bool bValid = (0 <= nRow) && ( nRow <=
maMaxPos.
Row() );
237 if( !bValid && bTrackOverflow )
244 bool bValid = (0 <= nSheet) && ( nSheet <=
maMaxPos.
Tab() );
245 if( !bValid && bTrackOverflow )
259 const OUString& rString, sal_Int16 nSheet )
272 ScAddress& orAddress, std::string_view pStr, sal_Int16 nSheet )
285 const OUString& rString, sal_Int16 nSheet,
bool bTrackOverflow )
294 std::string_view pStr, sal_Int16 nSheet,
bool bTrackOverflow )
303 const OUString& rString, sal_Int16 nSheet,
bool bTrackOverflow )
308 aAddress.
SetTab( getLimitedValue< sal_Int16, sal_Int16 >( nSheet, 0,
maMaxPos.
Tab() ) );
316 const BinAddress& rBinAddress, sal_Int16 nSheet )
324 const BinAddress& rBinAddress, sal_Int16 nSheet,
bool bTrackOverflow )
331 const BinAddress& rBinAddress, sal_Int16 nSheet,
bool bTrackOverflow )
336 aAddress.
SetTab( getLimitedValue< sal_Int16, sal_Int16 >( nSheet, 0,
maMaxPos.
Tab() ) );
337 aAddress.
SetCol( getLimitedValue< sal_Int32, sal_Int32 >( rBinAddress.
mnCol, 0, sal_Int32(
maMaxPos.
Col() ) ) );
338 aAddress.
SetRow( getLimitedValue< sal_Int32, sal_Int32 >( rBinAddress.
mnRow, 0, sal_Int32(
maMaxPos.
Row() ) ) );
377 std::u16string_view aString, sal_Int16 nSheet )
381 sal_Int32 aStartCol = orRange.
aStart.
Col();
382 sal_Int32 aStartRow = orRange.
aStart.
Row();
383 sal_Int32 aEndCol = orRange.
aEnd.
Col();
384 sal_Int32 aEndRow = orRange.
aEnd.
Row();
385 bool bReturnValue =
parseOoxRange2d( aStartCol, aStartRow, aEndCol, aEndRow, aString );
394 std::u16string_view aString, sal_Int16 nSheet,
bool bAllowOverflow,
bool bTrackOverflow )
402 const BinRange& rBinRange, sal_Int16 nSheet )
413 const BinRange& rBinRange, sal_Int16 nSheet,
bool bAllowOverflow,
bool bTrackOverflow )
427 std::u16string_view aString, sal_Int16 nSheet,
bool bTrackOverflow )
430 size_t nLen = aString.size();
432 while(
nPos != std::u16string_view::npos && (
nPos < nLen) )
435 if( !aToken.empty() &&
convertToCellRange( aRange, aToken, nSheet,
true, bTrackOverflow ) )
441 const BinRangeList& rBinRanges, sal_Int16 nSheet,
bool bTrackOverflow )
444 for(
const auto& rBinRange : rBinRanges )
451 const size_t nSize = orRanges.
size();
452 Sequence<CellRangeAddress> aRangeSequence(nSize);
453 CellRangeAddress* pApiRanges = aRangeSequence.getArray();
454 for (
size_t i = 0;
i < nSize; ++
i)
458 return aRangeSequence;
464 sal_Int16 nMaxXlsTab, sal_Int32 nMaxXlsCol, sal_Int32 nMaxXlsRow )
471 Reference< XIndexAccess > xSheetsIA(
getDocument()->getSheets(), UNO_QUERY_THROW );
472 Reference< XCellRangeAddressable > xAddressable( xSheetsIA->getByIndex( 0 ), UNO_QUERY_THROW );
473 CellRangeAddress aRange = xAddressable->getRangeAddress();
479 OSL_FAIL(
"AddressConverter::AddressConverter - cannot get sheet limits" );
void Set(SCCOL nCol, SCROW nRow, SCTAB nTab)
void push_back(const ScRange &rRange)
static void FillApiRange(css::table::CellRangeAddress &rApiRange, const ScRange &rScRange)
bool isImportFilter() const
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.
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 parseOoxRange2d(sal_Int32 &ornStartColumn, sal_Int32 &ornStartRow, sal_Int32 &ornEndColumn, sal_Int32 &ornEndRow, std::u16string_view aString, 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.
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.
static bool parseOoxAddress2d(sal_Int32 &ornColumn, sal_Int32 &ornRow, std::u16string_view aString, sal_Int32 nStart=0, sal_Int32 nLength=SAL_MAX_INT32)
Tries to parse the passed string for a 2d cell address in A1 notation.
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.
bool convertToCellRange(ScRange &orRange, std::u16string_view aString, sal_Int16 nSheet, bool bAllowOverflow, bool bTrackOverflow)
Tries to convert the passed string to a cell range address.
static bool convertToCellRangeUnchecked(ScRange &orRange, std::u16string_view aString, sal_Int16 nSheet)
Converts the passed string to a cell range address, without checking any sheet limits.
AddressConverter(const WorkbookHelper &rHelper)
bool mbRowOverflow
Flag for "columns overflow".
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.
bool validateCellRange(ScRange &orRange, bool bAllowOverflow, bool bTrackOverflow)
Checks the passed cell range, may try to fit it to current sheet limits.
void convertToCellRangeList(ScRangeList &orRanges, std::u16string_view aString, sal_Int16 nSheet, bool bTrackOverflow)
Tries to convert the passed string to a cell range list.
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 > mvRanges
Helper class to provide access to global workbook data.
::oox::core::FilterBase & getBaseFilter() const
Returns the base filter object (base class of all filters).
const css::uno::Reference< css::sheet::XSpreadsheetDocument > & getDocument() const
Returns a reference to the source/target spreadsheet document model.
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
A 2D cell address struct for binary filters.
void read(SequenceInputStream &rStrm)
A 2D cell range address struct for binary filters.
void read(SequenceInputStream &rStrm)