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())
156 if (rDesc.maCellValue.isEmpty())
165 switch (rDesc.mnValueType)
169 pCell->SetResultDouble(rDesc.maCellValue.toDouble());
177 if (bGeneratorKnownGood)
185 pCell->SetChanged(
false);
197 void applyCellFormulas(
199 const Sequence<ExternalLinkInfo>& rExternalLinks,
200 const std::vector<FormulaBuffer::TokenAddressItem>& rCells )
202 for (
const FormulaBuffer::TokenAddressItem& rItem : rCells)
205 CachedTokenArray::Item*
p = rCache.get(aPos, rItem.maTokenStr);
211 if (p->mnRow + 1 == aPos.
Row())
232 p->mnRow = aPos.
Row();
239 aCompiler.SetExternalLinks(rExternalLinks);
240 std::unique_ptr<ScTokenArray> pCode = aCompiler.CompileString(rItem.maTokenStr);
244 aCompiler.CompileTokenArray();
248 rCache.store(aPos, pCell);
252 void applyArrayFormulas(
254 const Sequence<ExternalLinkInfo>& rExternalLinks,
255 const std::vector<FormulaBuffer::TokenRangeAddressItem>& rArrays )
257 for (
const FormulaBuffer::TokenRangeAddressItem& rAddressItem : rArrays)
259 const ScAddress& aPos = rAddressItem.maTokenAndAddress.maAddress;
263 aComp.SetExternalLinks(rExternalLinks);
264 std::unique_ptr<ScTokenArray> pArray(aComp.CompileString(rAddressItem.maTokenAndAddress.maTokenStr));
266 rDoc.
setMatrixCells(rAddressItem.maRange, *pArray, formula::FormulaGrammar::GRAM_OOXML);
270 void applyCellFormulaValues(
271 ScDocumentImport& rDoc,
const std::vector<FormulaBuffer::FormulaValue>& rVector,
bool bGeneratorKnownGood )
275 for (
const FormulaBuffer::FormulaValue& rValue : rVector)
279 const OUString& rValueStr =
rValue.maValueStr;
283 switch (
rValue.mnCellType)
303 if (bGeneratorKnownGood)
317 void processSheetFormulaCells(
319 const Sequence<ExternalLinkInfo>& rExternalLinks,
bool bGeneratorKnownGood )
321 if (rItem.mpSharedFormulaEntries && rItem.mpSharedFormulaIDs)
322 applySharedFormulas(rDoc, rFormatter, *rItem.mpSharedFormulaEntries,
323 *rItem.mpSharedFormulaIDs, bGeneratorKnownGood);
325 if (rItem.mpCellFormulas)
327 CachedTokenArray aCache(rDoc.
getDoc());
328 applyCellFormulas(rDoc, aCache, rFormatter, rExternalLinks, *rItem.mpCellFormulas);
331 if (rItem.mpArrayFormulas)
332 applyArrayFormulas(rDoc, rFormatter, rExternalLinks, *rItem.mpArrayFormulas);
334 if (rItem.mpCellFormulaValues)
335 applyCellFormulaValues(rDoc, *rItem.mpCellFormulaValues, bGeneratorKnownGood);
342 const OUString& rTokenStr, sal_Int32 nSharedId ) :
343 maAddress(rAddr), maTokenStr(rTokenStr), mnSharedId(nSharedId) {}
346 const ScAddress& rAddr, sal_Int32 nSharedId,
347 const OUString& rCellValue, sal_Int32 nValueType ) :
348 maAddress(rAddr), mnSharedId(nSharedId), maCellValue(rCellValue),
mnValueType(nValueType) {}
351 mpCellFormulas(nullptr),
352 mpArrayFormulas(nullptr),
353 mpCellFormulaValues(nullptr),
354 mpSharedFormulaEntries(nullptr),
355 mpSharedFormulaIDs(nullptr) {}
381 std::vector<SheetItem> aSheetItems;
382 aSheetItems.reserve(nTabCount);
383 for (
SCTAB nTab = 0; nTab < nTabCount; ++nTab)
396 xFormulaBar->setPosition( 1.0 );
427 sal_Int32 nSharedId,
const OUString& rTokens )
432 rSharedFormulas.push_back( aEntry );
442 const ScAddress& rAddress, sal_Int32 nSharedId,
const OUString& rCellValue, sal_Int32 nValueType )
457 const ScAddress& rAddress,
const OUString& rValueStr, sal_Int32 nCellType )
462 aVal.maValueStr = rValueStr;
463 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
css::uno::Any const & rValue
const ScTokenArray * getTokenArray() const
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
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...