24#include <com/sun/star/sheet/XArrayFormulaTokens.hpp>
25#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
26#include <com/sun/star/table/XCell.hpp>
27#include <com/sun/star/table/XCellRange.hpp>
28#include <com/sun/star/util/DateTime.hpp>
29#include <com/sun/star/util/NumberFormat.hpp>
30#include <com/sun/star/util/XNumberFormatTypes.hpp>
31#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
33#include <osl/diagnose.h>
37#include <oox/token/properties.hxx>
38#include <oox/token/tokens.hxx>
44#include <document.hxx>
51#include <numformat.hxx>
64 mbShowPhonetic( false )
90 mbRef1Deleted( false ),
91 mbRef2Deleted( false )
97 mbPendingSharedFmla( false )
114 if (!rText.isEmpty())
122 OSL_ENSURE( rxString,
"SheetDataBuffer::setStringCell - missing rich string object" );
127 if( rxString->extractPlainString( aText, pFirstPortionFont ) )
153 using namespace ::com::sun::star::util::NumberFormat;
154 sal_Int16 nStdFmt = (fSerial < 1.0) ?
TIME : (((rDateTime.Hours > 0) || (rDateTime.Minutes > 0) || (rDateTime.Seconds > 0)) ?
DATETIME : DATE);
158 Reference< XNumberFormatsSupplier > xNumFmtsSupp(
getDocument(), UNO_QUERY_THROW );
159 Reference< XNumberFormatTypes > xNumFmtTypes( xNumFmtsSupp->getNumberFormats(), UNO_QUERY_THROW );
160 sal_Int32
nIndex = xNumFmtTypes->getStandardFormat( nStdFmt,
Locale() );
172 rModel.
maCellAddr, bValue ? OUString(
"TRUE()") : OUString(
"FALSE()"));
192 css::util::DateTime aDateTime;
195 SAL_WARN(
"sc.filter",
"SheetDataBuffer::setDateCell - could not parse: " << rDateString);
226 if( rTokens.hasElements() &&
getFormulaParser().extractSpecialTokenInfo( aTokenInfo, rTokens ) )
233 if( !aTokenInfo.Second )
241 ScAddress aTokenAddr( aTokenInfo.First.Column, aTokenInfo.First.Row, aTokenInfo.First.Sheet );
243 if( !aTokens.hasElements() )
311 auto it = std::find_if(rMap.begin(), rMap.end(),
312 [&nFormatId, &rStyles, &pXf1](
const std::pair<FormatKeyPair, ScRangeList>& rEntry) {
313 if (rEntry.first.second != nFormatId)
315 Xf* pXf2 = rStyles.getCellXf( rEntry.first.first ).get();
316 return *pXf1 == *pXf2;
318 if (it != rMap.end())
322 it->second.insert(it->second.end(), rRangeList.
begin(), rRangeList.
end());
330 std::map< FormatKeyPair, ScRangeList > rangeStyleListMap;
339 for (
const auto& [rFormatKeyPair, rRanges] : rangeStyleListMap )
341 for (
const ScRange & rAddress : rRanges)
344 aStyleRows.
mnNumFmt.first = rFormatKeyPair.first;
345 aStyleRows.
mnNumFmt.second = rFormatKeyPair.second;
346 aStyleRows.
mnStartRow = rAddress.aStart.Row();
347 aStyleRows.
mnEndRow = rAddress.aEnd.Row();
348 for ( sal_Int32 nCol = rAddress.aStart.Col(); nCol <= rAddress.aEnd.Col(); ++nCol )
349 tmpStylesPerColumn[ nCol ].push_back( aStyleRows );
352 for(
auto& rowStyles : tmpStylesPerColumn )
356 s.erase( std::unique( s.begin(), s.end(),
360 { return !StyleRowRangeComp()(lhs,rhs) && !StyleRowRangeComp()(rhs,lhs); } ),
366 s.erase( std::unique( s.begin(), s.end(),
368 { return !StyleRowRangeComp()(lhs,rhs) && !StyleRowRangeComp()(rhs,lhs); } ),
371 maStylesPerColumn[ rowStyles.first ].insert_sorted_unique_vector( std::move( s ));
384 cnt += rRowRangeList.size();
393 for ( sal_Int32 nCol = 0; nCol <= nMaxCol; ++nCol )
402 std::sort(rRowRangeList.begin(), rRowRangeList.end(),
405 return lhs.mnFirst < rhs.mnFirst;
408 for (
const auto& rRange : rRowRangeList )
416 aStyleRows.
mnEndRow = rRange.mnLast;
424 bool bAddRange =
true;
425 for ( ; rows_it != rRowStyles.
end(); ++rows_it )
428 if ( aStyleRows.
mnStartRow < rows_it->mnStartRow )
432 rows_it = rRowStyles.
insert( aSplit ).first;
436 if ( aStyleRows.
mnEndRow <= rows_it->mnEndRow )
443 aStyleRows.
mnStartRow = rows_it->mnEndRow + 1;
446 rRowStyles.
insert( aStyleRows );
457 SCTAB nEndTabInvalidatedIters(0);
464 nStartTabInvalidatedIters = std::min(rRange.aStart.Tab(), nStartTabInvalidatedIters);
465 nEndTabInvalidatedIters = std::max(rRange.aEnd.Tab(), nEndTabInvalidatedIters);
468 for (
SCTAB nTab = nStartTabInvalidatedIters; nTab <= nEndTabInvalidatedIters; ++nTab)
485 SCCOL pendingColStart = -1;
486 SCCOL pendingColEnd = -1;
495 bool bAutoFilter =
true;
497 while ( bAutoFilter && nScRow < rDoc.
MaxRow() )
509 if ( !pDefPattern || nScRow == rDoc.
MaxRow() )
513 for (
const auto& rRowStyle : rRowStyles )
515 Xf* pXf = rStyles.
getCellXf( rRowStyle.mnNumFmt.first ).get();
519 rRowStyle.mnNumFmt.first, rRowStyle.mnNumFmt.second, aPatternCache );
527 aAttrs.
maAttrs.push_back(aEntry);
538 if( pendingColStart != -1 && pendingColEnd == nScCol - 1 && aAttrParam == aPendingAttrParam )
542 if( pendingColStart != -1 )
544 pendingColStart = pendingColEnd = nScCol;
545 aPendingAttrParam = std::move( aAttrParam );
548 if( pendingColStart != -1 )
574 if( mnXfId == nXfId )
576 if( maRowRange.mnLast + 1 == nRow )
581 if( maRowRange.mnFirst == nRow + 1 )
583 --maRowRange.mnFirst;
598 mnHorAlign( nHorAlign )
604 if( (mnHorAlign == nHorAlign) && (
maRange.aStart.Row() == rAddress.
Row() ) &&
615 if( rTokens.hasElements() )
631 Reference< XArrayFormulaTokens > xTokens(
getCellRange( rRange ), UNO_QUERY );
632 OSL_ENSURE( xTokens.is(),
"SheetDataBuffer::finalizeArrayFormula - missing formula token interface" );
634 xTokens->setArrayTokens( rTokens );
642 if (rModel.
maRef1.isEmpty())
665 if (rModel.
maRef2.isEmpty())
722 if (!rRangeList.
empty() &&
725 else if (!rRangeList.
empty() &&
736 pLastRange = &rRangeList.
back();
739 if (rRangeList.
size() > 1)
741 for (
size_t i = rRangeList.
size() - 1;
i != 0; --
i)
743 ScRange& rMergeRange = rRangeList[
i - 1];
766 if( (nHorAlign == XML_centerContinuous) || (nHorAlign == XML_fill) )
807 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!).
ScDocument & getScDocument()
SCTAB getSheetIndex() const
Returns the index of the current sheet.
void putRichString(const ScAddress &rAddress, RichString &rString, const oox::xls::Font *pFirstPortionFont, bool bSingleLine=false)
Inserts a rich-string cell directly into the Calc 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).
void applyPatternToAttrList(AttrList &rAttrs, SCROW nRow1, SCROW nRow2, sal_Int32 nXfId, sal_Int32 nForceScNumFmt, ScPatternCache &rCache)
const Alignment & getAlignment() const
Returns the alignment data of this style.
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
bool mbWrapText
Indentation.
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