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 )
96 mbPendingSharedFmla( false )
113 if (!rText.isEmpty())
121 OSL_ENSURE( rxString,
"SheetDataBuffer::setStringCell - missing rich string object" );
124 if( rxString->extractPlainString( aText, pFirstPortionFont ) )
150 using namespace ::com::sun::star::util::NumberFormat;
151 sal_Int16 nStdFmt = (fSerial < 1.0) ?
TIME : (((rDateTime.Hours > 0) || (rDateTime.Minutes > 0) || (rDateTime.Seconds > 0)) ?
DATETIME : DATE);
155 Reference< XNumberFormatsSupplier > xNumFmtsSupp(
getDocument(), UNO_QUERY_THROW );
156 Reference< XNumberFormatTypes > xNumFmtTypes( xNumFmtsSupp->getNumberFormats(), UNO_QUERY_THROW );
157 sal_Int32
nIndex = xNumFmtTypes->getStandardFormat( nStdFmt,
Locale() );
169 rModel.
maCellAddr, bValue ? OUString(
"TRUE()") : OUString(
"FALSE()"));
189 css::util::DateTime aDateTime;
192 SAL_WARN(
"sc.filter",
"SheetDataBuffer::setDateCell - could not parse: " << rDateString);
223 if( rTokens.hasElements() &&
getFormulaParser().extractSpecialTokenInfo( aTokenInfo, rTokens ) )
230 if( !aTokenInfo.Second )
238 ScAddress aTokenAddr( aTokenInfo.First.Column, aTokenInfo.First.Row, aTokenInfo.First.Sheet );
240 if( !aTokens.hasElements() )
308 auto it = std::find_if(rMap.begin(), rMap.end(),
309 [&nFormatId, &rStyles, &pXf1](
const std::pair<FormatKeyPair, ScRangeList>& rEntry) {
310 if (rEntry.first.second != nFormatId)
312 Xf* pXf2 = rStyles.getCellXf( rEntry.first.first ).get();
313 return *pXf1 == *pXf2;
315 if (it != rMap.end())
319 it->second.insert(it->second.end(), rRangeList.
begin(), rRangeList.
end());
327 std::map< FormatKeyPair, ScRangeList > rangeStyleListMap;
336 for (
const auto& [rFormatKeyPair, rRanges] : rangeStyleListMap )
338 for (
const ScRange & rAddress : rRanges)
341 aStyleRows.
mnNumFmt.first = rFormatKeyPair.first;
342 aStyleRows.
mnNumFmt.second = rFormatKeyPair.second;
343 aStyleRows.
mnStartRow = rAddress.aStart.Row();
344 aStyleRows.
mnEndRow = rAddress.aEnd.Row();
345 for ( sal_Int32 nCol = rAddress.aStart.Col(); nCol <= rAddress.aEnd.Col(); ++nCol )
346 tmpStylesPerColumn[ nCol ].push_back( aStyleRows );
349 for(
auto& rowStyles : tmpStylesPerColumn )
353 s.erase( std::unique( s.begin(), s.end(),
357 { return !StyleRowRangeComp()(lhs,rhs) && !StyleRowRangeComp()(rhs,lhs); } ),
363 s.erase( std::unique( s.begin(), s.end(),
365 { return !StyleRowRangeComp()(lhs,rhs) && !StyleRowRangeComp()(rhs,lhs); } ),
368 maStylesPerColumn[ rowStyles.first ].insert_sorted_unique_vector( std::move( s ));
381 cnt += rRowRangeList.size();
390 for ( sal_Int32 nCol = 0; nCol <= nMaxCol; ++nCol )
398 for (
const auto& rRange : rRowRangeList )
406 aStyleRows.
mnEndRow = rRange.mnLast;
414 bool bAddRange =
true;
415 for ( ; rows_it != rRowStyles.
end(); ++rows_it )
418 if ( aStyleRows.
mnStartRow < rows_it->mnStartRow )
422 rows_it = rRowStyles.
insert( aSplit ).first;
426 if ( aStyleRows.
mnEndRow <= rows_it->mnEndRow )
433 aStyleRows.
mnStartRow = rows_it->mnEndRow + 1;
436 rRowStyles.
insert( aStyleRows );
447 SCTAB nEndTabInvalidatedIters(0);
454 nStartTabInvalidatedIters = std::min(rRange.aStart.Tab(), nStartTabInvalidatedIters);
455 nEndTabInvalidatedIters = std::max(rRange.aEnd.Tab(), nEndTabInvalidatedIters);
458 for (
SCTAB nTab = nStartTabInvalidatedIters; nTab <= nEndTabInvalidatedIters; ++nTab)
475 SCCOL pendingColStart = -1;
476 SCCOL pendingColEnd = -1;
483 bool bAutoFilter =
true;
485 while ( bAutoFilter && nScRow < rDoc.
MaxRow() )
497 if ( !pDefPattern || nScRow == rDoc.
MaxRow() )
501 for (
const auto& rRowStyle : rRowStyles )
503 Xf* pXf = rStyles.
getCellXf( rRowStyle.mnNumFmt.first ).get();
506 pXf->
applyPatternToAttrList( aAttrs, rRowStyle.mnStartRow, rRowStyle.mnEndRow, rRowStyle.mnNumFmt.second );
514 aAttrs.
maAttrs.push_back(aEntry);
525 if( pendingColStart != -1 && pendingColEnd == nScCol - 1 && aAttrParam == aPendingAttrParam )
529 if( pendingColStart != -1 )
531 pendingColStart = pendingColEnd = nScCol;
532 aPendingAttrParam = std::move( aAttrParam );
535 if( pendingColStart != -1 )
561 if( mnXfId == nXfId )
563 if( maRowRange.mnLast + 1 == nRow )
568 if( maRowRange.mnFirst == nRow + 1 )
570 --maRowRange.mnFirst;
585 mnHorAlign( nHorAlign )
591 if( (mnHorAlign == nHorAlign) && (
maRange.aStart.Row() == rAddress.
Row() ) &&
602 if( rTokens.hasElements() )
618 Reference< XArrayFormulaTokens > xTokens(
getCellRange( rRange ), UNO_QUERY );
619 OSL_ENSURE( xTokens.is(),
"SheetDataBuffer::finalizeArrayFormula - missing formula token interface" );
621 xTokens->setArrayTokens( rTokens );
629 if (rModel.
maRef1.isEmpty())
652 if (rModel.
maRef2.isEmpty())
709 if (!rRangeList.
empty() &&
712 else if (!rRangeList.
empty() &&
723 pLastRange = &rRangeList.
back();
726 if (rRangeList.
size() > 1)
728 for (
size_t i = rRangeList.
size() - 1;
i != 0; --
i)
730 ScRange& rMergeRange = rRangeList[
i - 1];
753 if( (nHorAlign == XML_centerContinuous) || (nHorAlign == XML_fill) )
794 if( bMultiCol || bMultiRow )
void IncCol(SCCOL nDelta=1)
void IncRow(SCROW nDelta=1)
Accessor class to ScDocument.
void setStringCell(const ScAddress &rPos, const OUString &rStr)
void setTableOpCells(const ScRange &rRange, const ScTabOpParam &rParam)
void invalidateBlockPositionSet(SCTAB nTab)
void setAttrEntries(SCTAB nTab, SCCOL nColStart, SCCOL nColEnd, Attrs &&rAttrs)
Set an array of cell attributes to specified range of columns.
void setNumericCell(const ScAddress &rPos, double fVal)
SC_DLLPUBLIC ScPatternAttr * GetDefPattern() const
SC_DLLPUBLIC ScDocumentPool * GetPool()
SC_DLLPUBLIC SCROW MaxRow() const
SC_DLLPUBLIC void DoMerge(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, SCTAB nTab, bool bDeleteCaptions=true)
SC_DLLPUBLIC void ApplyAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, const SfxPoolItem &rAttr)
SC_DLLPUBLIC const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich) const
SC_DLLPUBLIC const ScPatternAttr * GetPattern(SCCOL nCol, SCROW nRow, SCTAB nTab) const
bool HasAutoFilter() const
SfxItemSet & GetItemSet()
::std::vector< ScRange >::const_iterator begin() const
::std::vector< ScRange >::const_iterator end() const
void push_back(const ScRange &rRange)
void Set(const ScAddress &rAdr, bool bNewRelCol, bool bNewRelRow, bool bNewRelTab)
const T & Put(std::unique_ptr< T > xItem, sal_uInt16 nWhich=0)
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const editeng::SvxBorderLine * GetLine(SvxBoxItemLine nLine) const
void SetLine(const editeng::SvxBorderLine *pNew, SvxBoxItemLine nLine)
void reserve(size_type amount)
std::vector< Value >::const_iterator const_iterator
const_iterator end() const
std::pair< const_iterator, bool > insert(Value &&x)
const_iterator lower_bound(const Value &x) const
static const MapType::mapped_type * getMapElement(const MapType &rMap, const typename MapType::key_type &rKey)
bool setProperty(sal_Int32 nPropId, const Type &rValue)
Converter for cell addresses and cell ranges for OOXML and BIFF filters.
const ScAddress & getMaxApiAddress() const
Returns the biggest valid cell address in the own Calc document.
const AlignmentModel & getModel() const
Returns the alignment model structure.
RichStringRef getString(sal_Int32 nStringId) const
Returns the specified string.
void setErrorCell(const CellModel &rModel, const OUString &rErrorCode)
Inserts an error cell from the passed error code into the sheet.
ColStyles maStylesPerColumn
void setBlankCell(const CellModel &rModel)
Inserts a blank cell (with formatting) into the sheet.
std::map< sal_Int32, std::vector< ValueRange > > maXfIdRowRangeList
True = maSharedFmlaAddr and maSharedBaseAddr are valid.
void createTableOperation(const ScRange &rRange, const DataTableModel &rModel)
Sets a multiple table operation to the passed range.
::std::map< BinAddress, ApiTokenSequence > maSharedFormulas
All table operations in the sheet.
std::vector< TableOperation > maTableOperations
All array formulas in the sheet.
ScAddress maSharedBaseAddr
Address of a cell containing a pending shared formula.
void setRowFormat(sal_Int32 nRow, sal_Int32 nXfId, bool bCustomFormat)
Sets default cell formatting for the specified range of rows.
void setDateCell(const CellModel &rModel, const OUString &rDateString)
Inserts an ISO 8601 date cell into the sheet.
void setMergedRange(const ScRange &rRange)
Merges the cells in the passed cell range.
ScAddress maSharedFmlaAddr
Maps shared formula base address to defined name token index.
void finalizeArrayFormula(const ScRange &rRange, const ApiTokenSequence &rTokens) const
Inserts the passed array formula into the sheet.
SheetDataBuffer(const WorksheetHelper &rHelper)
void setCellFormat(const CellModel &rModel)
Processes the cell formatting data of the passed cell.
void finalizeTableOperation(const ScRange &rRange, const DataTableModel &rModel)
Inserts the passed table operation into the sheet.
void setValueCell(const CellModel &rModel, double fValue)
Inserts a value cell into the sheet.
void createSharedFormula(const ScAddress &rRange, const ApiTokenSequence &rTokens)
::std::pair< sal_Int32, sal_Int32 > XfIdNumFmtKey
void setCellFormula(const ScAddress &rCellAddr, const ApiTokenSequence &rTokens)
Sets the passed formula token array into a cell.
void setDateTimeCell(const CellModel &rModel, const css::util::DateTime &rDateTime)
Inserts a date/time cell into the sheet and adjusts number format.
void setFormulaCell(const CellModel &rModel, const ApiTokenSequence &rTokens)
Inserts a formula cell into the sheet.
void addColXfStyleProcessRowRanges()
void setBooleanCell(const CellModel &rModel, bool bValue)
Inserts a boolean cell into the sheet and adjusts number format.
void setStringCell(const CellModel &rModel, const OUString &rText)
Inserts a simple string cell into the sheet.
MergedRangeVector maCenterFillRanges
Merged cell ranges.
void applyCellMerging(const ScRange &rRange)
Writes all cell formatting attributes to the passed cell range list.
::std::vector< RowRangeStyle > TmpRowStyles
void finalizeImport()
Final processing after the sheet has been imported.
void createArrayFormula(const ScRange &rRange, const ApiTokenSequence &rTokens)
Inserts the passed token array as array formula.
bool mbPendingSharedFmla
Merged cell ranges from 'center across' or 'fill' alignment.
ArrayFormulaVector maArrayFormulas
Stores cell styles by column ( in row ranges )
XfIdRowRange maXfIdRowRange
Base address of the pending shared formula.
::std::map< sal_Int32, TmpRowStyles > TmpColStyles
MergedRangeVector maMergedRanges
Collected XF identifiers for cell rangelists.
std::map< XfIdNumFmtKey, ScRangeList > maXfIdRangeLists
Cached XF identifier for a range of rows.
ApiTokenSequence resolveSharedFormula(const ScAddress &rMapKey) const
Creates a formula token array representing the shared formula with the passed identifier.
FontRef getFontFromCellXf(sal_Int32 nXfId) const
Returns the font object of the specified cell XF.
XfRef getCellXf(sal_Int32 nXfId) const
Returns the specified cell format object.
double calcSerialFromDateTime(const css::util::DateTime &rDateTime) const
Returns the serial value of the passed datetime, based on current nulldate.
SharedStringsBuffer & getSharedStrings() const
Returns the shared strings read from the shared strings substream.
AddressConverter & getAddressConverter() const
Returns the converter for string to cell address/range conversion.
StylesBuffer & getStyles() const
Returns all cell formatting objects read from the styles substream.
FormulaBuffer & getFormulaBuffer() const
ScDocumentImport & getDocImport()
UnitConverter & getUnitConverter() const
Returns the measurement unit converter.
const css::uno::Reference< css::sheet::XSpreadsheetDocument > & getDocument() const
Returns a reference to the source/target spreadsheet document model.
FormulaParser & getFormulaParser() const
Returns a shared import formula parser (import filter only!).
void putRichString(const ScAddress &rAddress, RichString &rString, const oox::xls::Font *pFirstPortionFont)
Inserts a rich-string cell directly into the Calc sheet.
ScDocument & getScDocument()
SCTAB getSheetIndex() const
Returns the index of the current sheet.
void putFormulaTokens(const ScAddress &rAddress, const ApiTokenSequence &rTokens)
Inserts a formula cell directly into the Calc sheet.
css::uno::Reference< css::table::XCell > getCell(const ScAddress &rAddress) const
Returns the XCell interface for the passed cell address.
css::uno::Reference< css::table::XCellRange > getCellRange(const ScRange &rRange) const
Returns the XCellRange interface for the passed cell range address.
Represents a cell format or a cell style (called XF, extended format).
const Alignment & getAlignment() const
Returns the alignment data of this style.
void applyPatternToAttrList(AttrList &rAttrs, SCROW nRow1, SCROW nRow2, sal_Int32 nForceScNumFmt)
static bool parseDateTime(css::util::DateTime &rDateTime, std::u16string_view rString)
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)
std::pair< sal_Int32, sal_Int32 > FormatKeyPair
css::uno::Sequence< ApiToken > ApiTokenSequence
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...
static void addIfNotInMyMap(const StylesBuffer &rStyles, std::map< FormatKeyPair, ScRangeList > &rMap, sal_Int32 nXfId, sal_Int32 nFormatId, const ScRangeList &rRangeList)
static void lcl_SetBorderLine(ScDocument &rDoc, const ScRange &rRange, SCTAB nScTab, SvxBoxItemLine nLine)
std::shared_ptr< RichString > RichStringRef
constexpr TypedWhichId< ScMergeFlagAttr > ATTR_MERGE_FLAG(145)
constexpr TypedWhichId< SvxBoxItem > ATTR_BORDER(150)
const ScPatternAttr * pPattern
std::vector< ScAttrEntry > mvData
Parameter for data table aka multiple operations.
ScRefAddress aRefFormulaEnd
ScRefAddress aRefFormulaCell
A 2D cell address struct for binary filters.
Stores basic data about cell values and formatting.
CellModel()
True = show phonetic text.
sal_Int32 mnXfId
Data type of the cell value.
sal_Int32 mnCellType
The address of the current cell.
Stores data about table operations.
DataTableModel()
True = second reference cell deleted.
bool mbRef2Deleted
True = first reference cell deleted.
bool mb2dTable
Second reference cell for table operations.
OUString maRef2
First reference cell for table operations.
bool mbRowTable
True = 2-dimensional data table.
bool mbRef1Deleted
True = row oriented data table.
bool tryExpand(const ScAddress &rAddress, sal_Int32 nHorAlign)
MergedRange(const ScRange &rRange)
Horizontal alignment in the range.
void set(sal_Int32 nRow, sal_Int32 nXfId)
sal_Int32 mnXfId
Indexes of first and last row.
XfIdRowRange()
XF identifier for the row range.
bool tryExpand(sal_Int32 nRow, sal_Int32 nXfId)
std::vector< ScAttrEntry > maAttrs
constexpr OUStringLiteral PROP_NumberFormat