22 #include <com/sun/star/container/XIndexAccess.hpp>
23 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
24 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
26 #include <osl/diagnose.h>
40 const sal_Int16 API_MAXTAB =
MAXTAB;
42 const sal_Int32 OOX_MAXCOL =
static_cast< sal_Int32
>( (1 << 14) - 1 );
43 const sal_Int32 OOX_MAXROW =
static_cast< sal_Int32
>( (1 << 20) - 1 );
44 const sal_Int16 OOX_MAXTAB =
static_cast< sal_Int16
>( (1 << 15) - 1 );
73 mbColOverflow( false ),
74 mbRowOverflow( false ),
75 mbTabOverflow( false )
81 sal_Int32& ornColumn, sal_Int32& ornRow,
82 const OUString& rString, sal_Int32 nStart, sal_Int32 nLength )
84 ornColumn = ornRow = 0;
85 if( (nStart < 0) || (nStart >= rString.getLength()) || (nLength < 2) )
88 const sal_Unicode* pcChar = rString.getStr() + nStart;
89 const sal_Unicode* pcEndChar = pcChar + ::std::min( nLength, rString.getLength() - nStart );
91 enum { STATE_COL, STATE_ROW } eState = STATE_COL;
92 while( pcChar < pcEndChar )
99 if( (
'a' <= cChar) && (cChar <=
'z') )
100 cChar = (cChar -
'a') +
'A';
101 if( (
'A' <= cChar) && (cChar <=
'Z') )
105 if( ornColumn >= 12356631 )
107 ornColumn = (ornColumn * 26) + (cChar -
'A' + 1);
109 else if( ornColumn > 0 )
121 if( (
'0' <= cChar) && (cChar <=
'9') )
124 if( ornRow >= 100000000 )
126 ornRow = (ornRow * 10) + (cChar -
'0');
138 return (ornColumn >= 0) && (ornRow >= 0);
143 ornColumn = ornRow = 0;
145 enum { STATE_COL, STATE_ROW } eState = STATE_COL;
154 if( (
'a' <= cChar) && (cChar <=
'z') )
155 cChar = (cChar -
'a') +
'A';
156 if( (
'A' <= cChar) && (cChar <=
'Z') )
160 if( ornColumn >= 12356631 )
162 ornColumn = (ornColumn * 26) + (cChar -
'A' + 1);
164 else if( ornColumn > 0 )
176 if( (
'0' <= cChar) && (cChar <=
'9') )
179 if( ornRow >= 100000000 )
181 ornRow = (ornRow * 10) + (cChar -
'0');
193 return (ornColumn >= 0) && (ornRow >= 0);
197 sal_Int32& ornStartColumn, sal_Int32& ornStartRow,
198 sal_Int32& ornEndColumn, sal_Int32& ornEndRow,
199 const OUString& rString, sal_Int32 nStart )
201 ornStartColumn = ornStartRow = ornEndColumn = ornEndRow = 0;
202 if( (nStart < 0) || (nStart >= rString.getLength()) )
205 sal_Int32 nEnd = nStart + ( rString.getLength() - nStart );
206 sal_Int32 nColonPos = rString.indexOf(
':', nStart );
207 if( (nStart < nColonPos) && (nColonPos + 1 < nEnd) )
210 parseOoxAddress2d( ornStartColumn, ornStartRow, rString, nStart, nColonPos - nStart ) &&
216 ornEndColumn = ornStartColumn;
217 ornEndRow = ornStartRow;
226 bool bValid = (0 <= nCol) && ( nCol <=
maMaxPos.
Col() );
227 if( !bValid && bTrackOverflow )
234 bool bValid = (0 <= nRow) && ( nRow <=
maMaxPos.
Row() );
235 if( !bValid && bTrackOverflow )
242 bool bValid = (0 <= nSheet) && ( nSheet <=
maMaxPos.
Tab() );
243 if( !bValid && bTrackOverflow )
257 const OUString& rString, sal_Int16 nSheet )
270 ScAddress& orAddress,
const char* pStr, sal_Int16 nSheet )
283 const OUString& rString, sal_Int16 nSheet,
bool bTrackOverflow )
292 const char* pStr, sal_Int16 nSheet,
bool bTrackOverflow )
301 const OUString& rString, sal_Int16 nSheet,
bool bTrackOverflow )
306 aAddress.
SetTab( getLimitedValue< sal_Int16, sal_Int16 >( nSheet, 0,
maMaxPos.
Tab() ) );
314 const BinAddress& rBinAddress, sal_Int16 nSheet )
322 const BinAddress& rBinAddress, sal_Int16 nSheet,
bool bTrackOverflow )
329 const BinAddress& rBinAddress, sal_Int16 nSheet,
bool bTrackOverflow )
334 aAddress.
SetTab( getLimitedValue< sal_Int16, sal_Int16 >( nSheet, 0,
maMaxPos.
Tab() ) );
335 aAddress.
SetCol( getLimitedValue< sal_Int32, sal_Int32 >( rBinAddress.
mnCol, 0, sal_Int32(
maMaxPos.
Col() ) ) );
336 aAddress.
SetRow( getLimitedValue< sal_Int32, sal_Int32 >( rBinAddress.
mnRow, 0, sal_Int32(
maMaxPos.
Row() ) ) );
375 const OUString& rString, sal_Int16 nSheet )
379 sal_Int32 aStartCol = orRange.
aStart.
Col();
380 sal_Int32 aStartRow = orRange.
aStart.
Row();
381 sal_Int32 aEndCol = orRange.
aEnd.
Col();
382 sal_Int32 aEndRow = orRange.
aEnd.
Row();
383 bool bReturnValue =
parseOoxRange2d( aStartCol, aStartRow, aEndCol, aEndRow, rString );
392 const OUString& rString, sal_Int16 nSheet,
bool bAllowOverflow,
bool bTrackOverflow )
400 const BinRange& rBinRange, sal_Int16 nSheet )
411 const BinRange& rBinRange, sal_Int16 nSheet,
bool bAllowOverflow,
bool bTrackOverflow )
425 const OUString& rString, sal_Int16 nSheet,
bool bTrackOverflow )
428 sal_Int32 nLen = rString.getLength();
430 while( (0 <= nPos) && (nPos < nLen) )
432 OUString aToken = rString.getToken( 0,
' ', nPos );
433 if( !aToken.isEmpty() &&
convertToCellRange( aRange, aToken, nSheet,
true, bTrackOverflow ) )
439 const BinRangeList& rBinRanges, sal_Int16 nSheet,
bool bTrackOverflow )
442 for(
const auto& rBinRange : rBinRanges )
449 const size_t nSize = orRanges.
size();
450 Sequence<CellRangeAddress> aRangeSequence(nSize);
451 CellRangeAddress* pApiRanges = aRangeSequence.getArray();
452 for (
size_t i = 0;
i < nSize; ++
i)
456 return aRangeSequence;
462 sal_Int16 nMaxXlsTab, sal_Int32 nMaxXlsCol, sal_Int32 nMaxXlsRow )
469 Reference< XIndexAccess > xSheetsIA(
getDocument()->getSheets(), UNO_QUERY_THROW );
470 Reference< XCellRangeAddressable > xAddressable( xSheetsIA->getByIndex( 0 ), UNO_QUERY_THROW );
471 CellRangeAddress aRange = xAddressable->getRangeAddress();
477 OSL_FAIL(
"AddressConverter::AddressConverter - cannot get sheet limits" );
static css::uno::Sequence< css::table::CellRangeAddress > toApiSequence(const ScRangeList &orRanges)
Converts the passed range list to a sequence of cell range addresses.
Helper class to provide access to global workbook data.
bool checkCellRange(const ScRange &rRange, bool bAllowOverflow, bool bTrackOverflow)
Checks the passed cell range if it fits into the spreadsheet limits.
bool checkCellAddress(const ScAddress &rAddress, bool bTrackOverflow)
Checks the passed cell address if it fits into the spreadsheet limits.
bool checkCol(sal_Int32 nCol, bool bTrackOverflow)
Checks if the passed column index is valid.
A 2D cell range address list for binary filters.
A 2D cell address struct for binary filters.
bool validateCellRange(ScRange &orRange, bool bAllowOverflow, bool bTrackOverflow)
Checks the passed cell range, may try to fit it to current sheet limits.
A 2D cell range address struct for binary filters.
ScAddress maMaxPos
Maximum valid cell address in Excel.
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 convertToCellRangeUnchecked(ScRange &orRange, const OUString &rString, sal_Int16 nSheet)
Converts the passed string to a cell range address, without checking any sheet limits.
bool mbColOverflow
Maximum valid cell address in Calc/Excel.
::oox::core::FilterBase & getBaseFilter() const
Returns the base filter object (base class of all filters).
void push_back(const ScRange &rRange)
::std::vector< BinRange > mvRanges
bool convertToCellAddress(ScAddress &orAddress, const OUString &rString, sal_Int16 nSheet, bool bTrackOverflow)
Tries to convert the passed string to a single cell address.
bool checkTab(sal_Int16 nSheet, bool bTrackOverflow)
Checks if the passed sheet index is valid.
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.
void read(SequenceInputStream &rStrm)
bool mbRowOverflow
Flag for "columns overflow".
void Set(SCCOL nCol, SCROW nRow, SCTAB nTab)
const css::uno::Reference< css::sheet::XSpreadsheetDocument > & getDocument() const
Returns a reference to the source/target spreadsheet document model.
bool checkRow(sal_Int32 nRow, bool bTrackOverflow)
Checks if the passed row index is valid.
void convertToCellRangeList(ScRangeList &orRanges, const OUString &rString, sal_Int16 nSheet, bool bTrackOverflow)
Tries to convert the passed string to a cell range list.
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.
void initializeMaxPos(sal_Int16 nMaxXlsTab, sal_Int32 nMaxXlsCol, sal_Int32 nMaxXlsRow)
bool mbTabOverflow
Flag for "rows overflow".
sal_Int64 getRemaining() const
ScAddress createValidCellAddress(const OUString &rString, sal_Int16 nSheet, bool bTrackOverflow)
Returns a valid cell address by moving it into allowed dimensions.
AddressConverter(const WorkbookHelper &rHelper)
void read(SequenceInputStream &rStrm)
void validateCellRangeList(ScRangeList &orRanges, bool bTrackOverflow)
Tries to restrict the passed cell range list to current sheet limits.
ScAddress maMaxXlsPos
Maximum valid cell address in Calc.
static void FillApiRange(css::table::CellRangeAddress &rApiRange, const ScRange &rScRange)
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.
void read(SequenceInputStream &rStrm)
bool isImportFilter() const