23 #include <com/sun/star/sheet/XArrayFormulaTokens.hpp>
24 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
25 #include <com/sun/star/table/XCell.hpp>
26 #include <com/sun/star/table/XCellRange.hpp>
27 #include <com/sun/star/util/DateTime.hpp>
28 #include <com/sun/star/util/NumberFormat.hpp>
29 #include <com/sun/star/util/XNumberFormatTypes.hpp>
30 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
32 #include <osl/diagnose.h>
36 #include <oox/token/properties.hxx>
37 #include <oox/token/tokens.hxx>
43 #include <document.hxx>
50 #include <numformat.hxx>
63 mbShowPhonetic(
false )
89 mbRef1Deleted(
false ),
90 mbRef2Deleted(
false )
102 OSL_ENSURE(
maColSpans.count( nRow ) == 0,
"CellBlockBuffer::setColSpans - multiple column spans for the same row" );
103 OSL_ENSURE( (
mnCurrRow < nRow) && (
maColSpans.empty() || (
maColSpans.rbegin()->first < nRow)),
"CellBlockBuffer::setColSpans - rows are unsorted" );
113 maCellBlocks( rHelper ),
114 mbPendingSharedFmla(
false )
136 if (!rText.isEmpty())
144 OSL_ENSURE( rxString,
"SheetDataBuffer::setStringCell - missing rich string object" );
147 if( rxString->extractPlainString( aText, pFirstPortionFont ) )
173 using namespace ::com::sun::star::util::NumberFormat;
174 sal_Int16 nStdFmt = (fSerial < 1.0) ?
TIME : (((rDateTime.Hours > 0) || (rDateTime.Minutes > 0) || (rDateTime.Seconds > 0)) ?
DATETIME : DATE);
178 Reference< XNumberFormatsSupplier > xNumFmtsSupp(
getDocument(), UNO_QUERY_THROW );
179 Reference< XNumberFormatTypes > xNumFmtTypes( xNumFmtsSupp->getNumberFormats(), UNO_QUERY_THROW );
180 sal_Int32
nIndex = xNumFmtTypes->getStandardFormat( nStdFmt,
Locale() );
192 rModel.
maCellAddr, bValue ? OUString(
"TRUE()") : OUString(
"FALSE()"));
212 css::util::DateTime aDateTime;
215 SAL_WARN(
"sc.filter",
"SheetDataBuffer::setDateCell - could not parse: " << rDateString);
253 if( !aTokenInfo.Second )
261 ScAddress aTokenAddr( aTokenInfo.First.Column, aTokenInfo.First.Row, aTokenInfo.First.Sheet );
263 if( !aTokens.hasElements() )
331 auto it = std::find_if(rMap.begin(), rMap.end(),
332 [&nFormatId, &rStyles, &pXf1](
const std::pair<FormatKeyPair, ScRangeList>& rEntry) {
333 if (rEntry.first.second != nFormatId)
335 Xf* pXf2 = rStyles.getCellXf( rEntry.first.first ).get();
336 return *pXf1 == *pXf2;
338 if (it != rMap.end())
342 it->second.insert(it->second.end(), rRangeList.
begin(), rRangeList.
end());
350 std::map< FormatKeyPair, ScRangeList > rangeStyleListMap;
359 for (
const auto& [rFormatKeyPair, rRanges] : rangeStyleListMap )
361 for (
const ScRange & rAddress : rRanges)
364 aStyleRows.
mnNumFmt.first = rFormatKeyPair.first;
365 aStyleRows.
mnNumFmt.second = rFormatKeyPair.second;
366 aStyleRows.
mnStartRow = rAddress.aStart.Row();
367 aStyleRows.
mnEndRow = rAddress.aEnd.Row();
368 for ( sal_Int32 nCol = rAddress.aStart.Col(); nCol <= rAddress.aEnd.Col(); ++nCol )
369 tmpStylesPerColumn[ nCol ].push_back( aStyleRows );
372 for(
auto& rowStyles : tmpStylesPerColumn )
376 s.erase( std::unique( s.begin(), s.end(),
386 s.erase( std::unique( s.begin(), s.end(),
391 maStylesPerColumn[ rowStyles.first ].insert_sorted_unique_vector( std::move( s ));
404 cnt += rRowRangeList.size();
413 for ( sal_Int32 nCol = 0; nCol <= nMaxCol; ++nCol )
416 for (
const auto& [nXfId, rRowRangeList] : maXfIdRowRangeList )
421 for (
const auto& rRange : rRowRangeList )
429 aStyleRows.
mnEndRow = rRange.mnLast;
437 bool bAddRange =
true;
438 for ( ; rows_it != rRowStyles.
end(); ++rows_it )
441 if ( aStyleRows.
mnStartRow < rows_it->mnStartRow )
445 rows_it = rRowStyles.
insert( aSplit ).first;
449 if ( aStyleRows.
mnEndRow <= rows_it->mnEndRow )
456 aStyleRows.
mnStartRow = rows_it->mnEndRow + 1;
459 rRowStyles.
insert( aStyleRows );
470 SCTAB nEndTabInvalidatedIters(0);
477 nStartTabInvalidatedIters = std::min(rRange.aStart.Tab(), nStartTabInvalidatedIters);
478 nEndTabInvalidatedIters = std::max(rRange.aEnd.Tab(), nEndTabInvalidatedIters);
481 for (
SCTAB nTab = nStartTabInvalidatedIters; nTab <= nEndTabInvalidatedIters; ++nTab)
498 SCCOL pendingColStart = -1;
499 SCCOL pendingColEnd = -1;
506 bool bAutoFilter =
true;
508 while ( bAutoFilter && nScRow < rDoc.
MaxRow() )
520 if ( !pDefPattern || nScRow == rDoc.
MaxRow() )
524 for (
const auto& rRowStyle : rRowStyles )
526 Xf* pXf = rStyles.
getCellXf( rRowStyle.mnNumFmt.first ).get();
529 pXf->
applyPatternToAttrList( aAttrs, rRowStyle.mnStartRow, rRowStyle.mnEndRow, rRowStyle.mnNumFmt.second );
537 aAttrs.
maAttrs.push_back(aEntry);
548 if( pendingColStart != -1 && pendingColEnd == nScCol - 1 && aAttrParam == aPendingAttrParam )
552 if( pendingColStart != -1 )
554 pendingColStart = pendingColEnd = nScCol;
555 aPendingAttrParam = std::move( aAttrParam );
558 if( pendingColStart != -1 )
584 if( mnXfId == nXfId )
586 if( maRowRange.mnLast + 1 == nRow )
591 if( maRowRange.mnFirst == nRow + 1 )
593 --maRowRange.mnFirst;
608 mnHorAlign( nHorAlign )
614 if( (mnHorAlign == nHorAlign) && (
maRange.aStart.Row() == rAddress.
Row() ) &&
625 if( rTokens.hasElements() )
641 Reference< XArrayFormulaTokens > xTokens(
getCellRange( rRange ), UNO_QUERY );
642 OSL_ENSURE( xTokens.is(),
"SheetDataBuffer::finalizeArrayFormula - missing formula token interface" );
644 xTokens->setArrayTokens( rTokens );
652 if (rModel.
maRef1.isEmpty())
675 if (rModel.
maRef2.isEmpty())
732 if (!rRangeList.
empty() &&
735 else if (!rRangeList.
empty() &&
746 pLastRange = &rRangeList.
back();
749 if (rRangeList.
size() > 1)
751 for (
size_t i = rRangeList.
size() - 1;
i != 0; --
i)
753 ScRange& rMergeRange = rRangeList[
i - 1];
776 if( (nHorAlign == XML_centerContinuous) || (nHorAlign == XML_fill) )
817 if( bMultiCol || bMultiRow )
void Set(const ScAddress &rAdr, bool bNewRelCol, bool bNewRelRow, bool bNewRelTab)
::std::map< BinAddress, ApiTokenSequence > maSharedFormulas
All table operations in the sheet.
sal_Int32 mnCurrRow
Buffered column spans, mapped by row index.
const_iterator lower_bound(const Value &x) const
ScDocumentImport & getDocImport()
constexpr TypedWhichId< SvxBoxItem > ATTR_BORDER(150)
void setDateTimeCell(const CellModel &rModel, const css::util::DateTime &rDateTime)
Inserts a date/time cell into the sheet and adjusts number format.
A 2D cell address struct for binary filters.
UnitConverter & getUnitConverter() const
Returns the measurement unit converter.
CellBlockBuffer(const WorksheetHelper &rHelper)
static void addIfNotInMyMap(const StylesBuffer &rStyles, std::map< FormatKeyPair, ScRangeList > &rMap, sal_Int32 nXfId, sal_Int32 nFormatId, const ScRangeList &rRangeList)
XfRef getCellXf(sal_Int32 nXfId) const
Returns the specified cell format object.
ArrayFormulaVector maArrayFormulas
Manages all open cell blocks.
sal_Int32 mnCellType
The address of the current cell.
XfIdRowRange()
XF identifier for the row range.
const ScAddress & getMaxApiAddress() const
Returns the biggest valid cell address in the own Calc document.
ScDocument & getScDocument()
MergedRangeVector maMergedRanges
Collected XF identifiers for cell rangelists.
RichStringRef getString(sal_Int32 nStringId) const
Returns the specified string.
css::uno::Reference< css::table::XCellRange > getCellRange(const ScRange &rRange) const
Returns the XCellRange interface for the passed cell range address.
::std::pair< sal_Int32, sal_Int32 > XfIdNumFmtKey
static bool parseDateTime(css::util::DateTime &rDateTime, std::u16string_view rString)
bool tryExpand(sal_Int32 nRow, sal_Int32 nXfId)
SC_DLLPUBLIC void ApplyAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, const SfxPoolItem &rAttr)
Accessor class to ScDocument.
ColSpanVectorMap maColSpans
StylesBuffer & getStyles() const
Returns all cell formatting objects read from the styles substream.
void putFormulaTokens(const ScAddress &rAddress, const ApiTokenSequence &rTokens)
Inserts a formula cell directly into the Calc sheet.
bool mbPendingSharedFmla
Merged cell ranges from 'center across' or 'fill' alignment.
bool mbRowTable
True = 2-dimensional data table.
SC_DLLPUBLIC ScDocumentPool * GetPool()
double calcSerialFromDateTime(const css::util::DateTime &rDateTime) const
Returns the serial value of the passed datetime, based on current nulldate.
ApiTokenSequence resolveSharedFormula(const ScAddress &rMapKey) const
Creates a formula token array representing the shared formula with the passed identifier.
std::shared_ptr< RichString > RichStringRef
sal_Int32 mnXfId
Indexes of first and last row.
const ScPatternAttr * pPattern
bool mbRef1Deleted
True = row oriented data table.
SC_DLLPUBLIC SCROW MaxRow() const
void setBooleanCell(const CellModel &rModel, bool bValue)
Inserts a boolean cell into the sheet and adjusts number format.
void setRowFormat(sal_Int32 nRow, sal_Int32 nXfId, bool bCustomFormat)
Sets default cell formatting for the specified range of rows.
void reserve(size_type amount)
void push_back(const ScRange &rRange)
void putRichString(const ScAddress &rAddress, const RichString &rString, const oox::xls::Font *pFirstPortionFont)
Inserts a rich-string cell directly into the Calc sheet.
const editeng::SvxBorderLine * GetLine(SvxBoxItemLine nLine) const
sal_Int32 mnXfId
Data type of the cell value.
std::pair< sal_Int32, sal_Int32 > FormatKeyPair
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) const
void applyPatternToAttrList(AttrList &rAttrs, SCROW nRow1, SCROW nRow2, sal_Int32 nForceScNumFmt)
void setValueCell(const CellModel &rModel, double fValue)
Inserts a value cell into the sheet.
void setMergedRange(const ScRange &rRange)
Merges the cells in the passed cell range.
SC_DLLPUBLIC const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich) const
ScAddress maSharedFmlaAddr
Maps shared formula base address to defined name token index.
void setDateCell(const CellModel &rModel, const OUString &rDateString)
Inserts an ISO 8601 date cell into the sheet.
Parameter for data table aka multiple operations.
Stores basic data about cell values and formatting.
std::vector< TableOperation > maTableOperations
All array formulas in the sheet.
CellModel()
True = show phonetic text.
void createTableOperation(const ScRange &rRange, const DataTableModel &rModel)
Sets a multiple table operation to the passed range.
std::vector< ScAttrEntry > mvData
MergedRangeVector maCenterFillRanges
Merged cell ranges.
void IncCol(SCCOL nDelta=1)
css::beans::Pair< css::table::CellAddress, sal_Bool > ApiSpecialTokenInfo
Contains the base address and type of a special token representing an array formula or a shared formu...
const css::uno::Reference< css::sheet::XSpreadsheetDocument > & getDocument() const
Returns a reference to the source/target spreadsheet document model.
std::map< sal_Int32, std::vector< ValueRange > > maXfIdRowRangeList
True = maSharedFmlaAddr and maSharedBaseAddr are valid.
std::map< XfIdNumFmtKey, ScRangeList > maXfIdRangeLists
Cached XF identifier for a range of rows.
::std::vector< ScRange >::const_iterator end() const
void setColSpans(sal_Int32 nRow, const ValueRangeSet &rColSpans)
Sets column span information for a row.
ScRefAddress aRefFormulaCell
void IncRow(SCROW nDelta=1)
SfxItemSet & GetItemSet()
const Alignment & getAlignment() const
Returns the alignment data of this style.
const_iterator end() const
CellBlockBuffer maCellBlocks
Stores cell styles by column ( in row ranges )
void setErrorCell(const CellModel &rModel, const OUString &rErrorCode)
Inserts an error cell from the passed error code into the sheet.
css::uno::Reference< css::table::XCell > getCell(const ScAddress &rAddress) const
Returns the XCell interface for the passed cell address.
ColStyles maStylesPerColumn
static void lcl_SetBorderLine(ScDocument &rDoc, const ScRange &rRange, SCTAB nScTab, SvxBoxItemLine nLine)
void setTableOpCells(const ScRange &rRange, const ScTabOpParam &rParam)
FontRef getFontFromCellXf(sal_Int32 nXfId) const
Returns the font object of the specified cell XF.
MergedRange(const ScRange &rRange)
Horizontal alignment in the range.
void invalidateBlockPositionSet(SCTAB nTab)
DataTableModel()
True = second reference cell deleted.
css::uno::Sequence< ApiToken > ApiTokenSequence
const AlignmentModel & getModel() const
Returns the alignment model structure.
static const MapType::mapped_type * getMapElement(const MapType &rMap, const typename MapType::key_type &rKey)
constexpr TypedWhichId< ScMergeFlagAttr > ATTR_MERGE_FLAG(145)
void setBlankCell(const CellModel &rModel)
Inserts a blank cell (with formatting) into the sheet.
ScAddress maSharedBaseAddr
Address of a cell containing a pending shared formula.
void setCellFormat(const CellModel &rModel)
Processes the cell formatting data of the passed cell.
void setColSpans(sal_Int32 nRow, const ValueRangeSet &rColSpans)
Sets column span information for a row.
Converter for cell addresses and cell ranges for OOXML and BIFF filters.
void setStringCell(const ScAddress &rPos, const OUString &rStr)
SCTAB getSheetIndex() const
Returns the index of the current sheet.
const T & Put(std::unique_ptr< T > xItem, sal_uInt16 nWhich=0)
void setAttrEntries(SCTAB nTab, SCCOL nColStart, SCCOL nColEnd, Attrs &&rAttrs)
Set an array of cell attributes to specified range of columns.
Represents a cell format or a cell style (called XF, extended format).
SharedStringsBuffer & getSharedStrings() const
Returns the shared strings read from the shared strings substream.
SC_DLLPUBLIC ScPatternAttr * GetDefPattern() const
bool mbRef2Deleted
True = first reference cell deleted.
void applyCellMerging(const ScRange &rRange)
Writes all cell formatting attributes to the passed cell range list.
FormulaParser & getFormulaParser() const
Returns a shared import formula parser (import filter only!).
void createArrayFormula(const ScRange &rRange, const ApiTokenSequence &rTokens)
Inserts the passed token array as array formula.
::std::vector< RowRangeStyle > TmpRowStyles
void finalizeTableOperation(const ScRange &rRange, const DataTableModel &rModel)
Inserts the passed table operation into the sheet.
const ValueRangeVector & getRanges() const
void addColXfStyleProcessRowRanges()
static bool isLatinScript(const ScPatternAttr &rPat, ScDocument &rDoc)
Check if the attribute pattern has a number format that only produces latin script output...
#define SAL_WARN(area, stream)
XfIdRowRange maXfIdRowRange
Base address of the pending shared formula.
::std::vector< ScRange >::const_iterator begin() const
OUString maRef2
First reference cell for table operations.
ScRefAddress aRefFormulaEnd
void finalizeImport()
Final processing after the sheet has been imported.
void setNumericCell(const ScAddress &rPos, double fVal)
::std::map< sal_Int32, TmpRowStyles > TmpColStyles
bool HasAutoFilter() const
void createSharedFormula(const ScAddress &rRange, const ApiTokenSequence &rTokens)
std::pair< const_iterator, bool > insert(Value &&x)
void finalizeArrayFormula(const ScRange &rRange, const ApiTokenSequence &rTokens) const
Inserts the passed array formula into the sheet.
bool mb2dTable
Second reference cell for table operations.
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
void setFormulaCell(const CellModel &rModel, const ApiTokenSequence &rTokens)
Inserts a formula cell into the sheet.
Stores data about table operations.
void set(sal_Int32 nRow, sal_Int32 nXfId)
void setStringCell(const CellModel &rModel, const OUString &rText)
Inserts a simple string cell into the sheet.
SC_DLLPUBLIC void DoMerge(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, bool bDeleteCaptions=true)
SheetDataBuffer(const WorksheetHelper &rHelper)
bool setProperty(sal_Int32 nPropId, const Type &rValue)
std::vector< Value >::const_iterator const_iterator
void setCellFormula(const ScAddress &rCellAddr, const ApiTokenSequence &rTokens)
Sets the passed formula token array into a cell.
AddressConverter & getAddressConverter() const
Returns the converter for string to cell address/range conversion.
FormulaBuffer & getFormulaBuffer() const
bool tryExpand(const ScAddress &rAddress, sal_Int32 nHorAlign)
bool m_bDetectedRangeSegmentation false
std::vector< ScAttrEntry > maAttrs
void SetLine(const editeng::SvxBorderLine *pNew, SvxBoxItemLine nLine)