13 #include <document.hxx>
17 #include <tokenarray.hxx>
22 #include <oox/token/tokens.hxx>
40 class CachedTokenArray
43 CachedTokenArray(
const CachedTokenArray&) =
delete;
44 const CachedTokenArray& operator=(
const CachedTokenArray&) =
delete;
51 Item(
const Item&) =
delete;
52 const Item& operator=(
const Item&) =
delete;
54 Item() : mnRow(-1), mpCell(nullptr) {}
57 explicit CachedTokenArray(
const ScDocument& rDoc ) :
60 Item*
get(
const ScAddress& rPos, std::u16string_view rFormula )
63 ColCacheType::iterator it =
maCache.find(rPos.Col());
67 Item& rCached = *it->second;
70 if (rFormula == aPredicted)
78 ColCacheType::iterator it =
maCache.find(rPos.
Col());
82 std::pair<ColCacheType::iterator,bool> r =
83 maCache.emplace(rPos.
Col(), std::make_unique<Item>());
91 Item& rItem = *it->second;
92 rItem.mnRow = rPos.
Row();
97 typedef std::unordered_map<SCCOL, std::unique_ptr<Item>> ColCacheType;
102 void applySharedFormulas(
105 std::vector<FormulaBuffer::SharedFormulaEntry>& rSharedFormulas,
106 std::vector<FormulaBuffer::SharedFormulaDesc>& rCells,
107 bool bGeneratorKnownGood)
112 for (
const FormulaBuffer::SharedFormulaEntry& rEntry : rSharedFormulas)
114 const ScAddress& aPos = rEntry.maAddress;
115 sal_Int32
nId = rEntry.mnSharedId;
116 const OUString& rTokenStr = rEntry.maTokenStr;
120 std::unique_ptr<ScTokenArray> pArray = aComp.CompileString(rTokenStr);
123 aComp.CompileTokenArray();
124 aGroups.
set(nId, std::move(pArray), aPos);
132 for (
const FormulaBuffer::SharedFormulaDesc& rDesc : rCells)
150 if (rOrigin.
Col() != aPos.
Col())
157 pCell->SetNeedNumberFormat(
true);
159 if (rDesc.maCellValue.isEmpty())
168 switch (rDesc.mnValueType)
172 pCell->SetResultDouble(rDesc.maCellValue.toDouble());
180 if (bGeneratorKnownGood)
188 pCell->SetChanged(
false);
200 void applyCellFormulas(
202 const Sequence<ExternalLinkInfo>& rExternalLinks,
203 const std::vector<FormulaBuffer::TokenAddressItem>& rCells )
205 for (
const FormulaBuffer::TokenAddressItem& rItem : rCells)
208 CachedTokenArray::Item*
p = rCache.get(aPos, rItem.maTokenStr);
214 if (p->mnRow + 1 == aPos.
Row())
222 assert(rPrev.
aPos.
Row() == p->mnRow);
237 p->mnRow = aPos.
Row();
244 aCompiler.SetExternalLinks(rExternalLinks);
245 std::unique_ptr<ScTokenArray> pCode = aCompiler.CompileString(rItem.maTokenStr);
249 aCompiler.CompileTokenArray();
255 rCache.store(aPos, pCell);
259 void applyArrayFormulas(
261 const Sequence<ExternalLinkInfo>& rExternalLinks,
262 const std::vector<FormulaBuffer::TokenRangeAddressItem>& rArrays )
264 for (
const FormulaBuffer::TokenRangeAddressItem& rAddressItem : rArrays)
266 const ScAddress& aPos = rAddressItem.maTokenAndAddress.maAddress;
270 aComp.SetExternalLinks(rExternalLinks);
271 std::unique_ptr<ScTokenArray> pArray(aComp.CompileString(rAddressItem.maTokenAndAddress.maTokenStr));
273 rDoc.
setMatrixCells(rAddressItem.maRange, *pArray, formula::FormulaGrammar::GRAM_OOXML);
277 void applyCellFormulaValues(
278 ScDocumentImport& rDoc,
const std::vector<FormulaBuffer::FormulaValue>& rVector,
bool bGeneratorKnownGood )
282 for (
const FormulaBuffer::FormulaValue& rValue : rVector)
284 const ScAddress& aCellPos = rValue.maAddress;
286 const OUString& rValueStr = rValue.maValueStr;
290 switch (rValue.mnCellType)
310 if (bGeneratorKnownGood)
324 void processSheetFormulaCells(
326 const Sequence<ExternalLinkInfo>& rExternalLinks,
bool bGeneratorKnownGood )
328 if (rItem.mpSharedFormulaEntries && rItem.mpSharedFormulaIDs)
329 applySharedFormulas(rDoc, rFormatter, *rItem.mpSharedFormulaEntries,
330 *rItem.mpSharedFormulaIDs, bGeneratorKnownGood);
332 if (rItem.mpCellFormulas)
334 CachedTokenArray aCache(rDoc.
getDoc());
335 applyCellFormulas(rDoc, aCache, rFormatter, rExternalLinks, *rItem.mpCellFormulas);
338 if (rItem.mpArrayFormulas)
339 applyArrayFormulas(rDoc, rFormatter, rExternalLinks, *rItem.mpArrayFormulas);
341 if (rItem.mpCellFormulaValues)
342 applyCellFormulaValues(rDoc, *rItem.mpCellFormulaValues, bGeneratorKnownGood);
349 const OUString& rTokenStr, sal_Int32 nSharedId ) :
350 maAddress(rAddr), maTokenStr(rTokenStr), mnSharedId(nSharedId) {}
353 const ScAddress& rAddr, sal_Int32 nSharedId,
354 const OUString& rCellValue, sal_Int32 nValueType ) :
355 maAddress(rAddr), maCellValue(rCellValue), mnSharedId(nSharedId),
mnValueType(nValueType) {}
358 mpCellFormulas(nullptr),
359 mpArrayFormulas(nullptr),
360 mpCellFormulaValues(nullptr),
361 mpSharedFormulaEntries(nullptr),
362 mpSharedFormulaIDs(nullptr) {}
388 std::vector<SheetItem> aSheetItems;
389 aSheetItems.reserve(nTabCount);
390 for (
SCTAB nTab = 0; nTab < nTabCount; ++nTab)
403 xFormulaBar->setPosition( 1.0 );
434 sal_Int32 nSharedId,
const OUString& rTokens )
439 rSharedFormulas.push_back( aEntry );
449 const ScAddress& rAddress, sal_Int32 nSharedId,
const OUString& rCellValue, sal_Int32 nValueType )
464 const ScAddress& rAddress,
const OUString& rValueStr, sal_Int32 nCellType )
469 aVal.maValueStr = rValueStr;
470 aVal.mnCellType = nCellType;
Helper class to provide access to global workbook data.
::boost::intrusive_ptr< ScFormulaCellGroup > ScFormulaCellGroupRef
ScDocumentImport & getDocImport()
SharedString intern(const OUString &rStr)
SC_DLLPUBLIC svl::SharedStringPool & GetSharedStringPool()
bool isGeneratorKnownGood() const
Returns true when reading a file generated by a known good generator.
SC_DLLPUBLIC const ScFormulaCell * GetFormulaCell(const ScAddress &rPos) const
Accessor class to ScDocument.
const ScAddress & getOrigin() const
const ScTokenArray * getTokenArray() const
SC_DLLPUBLIC SCTAB GetTableCount() const
void SetNumberFormatter(SvNumberFormatter *pFormatter)
SC_DLLPUBLIC ScExternalRefManager * GetExternalRefManager() const
void setMatrixCells(const ScRange &rRange, const ScTokenArray &rArray, formula::FormulaGrammar::Grammar eGrammar)
SC_DLLPUBLIC void SetAutoNameCache(std::unique_ptr< ScAutoNameCache > pCache)
OUString CreateString(sc::TokenStringContext &rCxt, const ScAddress &rPos) const
Create a string representation of formula token array without modifying the internal state of the tok...
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
ExternalLinkBuffer & getExternalLinks() const
Returns the external links read from the external links substream.
std::shared_ptr< ISegmentProgressBar > ISegmentProgressBarRef
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
SegmentProgressBar & getProgressBar() const
Returns the filter progress bar.
virtual ISegmentProgressBarRef createSegment(double fLength) override
Context for creating string from an array of formula tokens, used in ScTokenArray::CreateString().
SharedFormulaEntry(const ScAddress &rAddress, const OUString &rTokenStr, sal_Int32 nSharedId)
void setFormulaCell(const ScAddress &rPos, const OUString &rFormula, formula::FormulaGrammar::Grammar eGrammar, const double *pResult=nullptr)
css::uno::Sequence< css::sheet::ExternalLinkInfo > getLinkInfos() const
Returns the sequence of link infos needed by the XML formula parser.
void addFilesToLinkManager()
Add all known external files to the LinkManager.
Represents a shared formula definition.
#define SAL_WARN(area, stream)
std::unique_ptr< ScTokenArray > Clone() const
Use this guard when performing something from the API that might query values from external reference...
SC_DLLPUBLIC sal_uInt32 GetNumberFormat(SCCOL nCol, SCROW nRow, SCTAB nTab) const