13#include <document.hxx>
17#include <tokenarray.hxx>
22#include <oox/token/tokens.hxx>
45 CachedTokenArray(
const CachedTokenArray&) =
delete;
46 const CachedTokenArray& operator=(
const CachedTokenArray&) =
delete;
53 Item(
const Item&) =
delete;
54 const Item& operator=(
const Item&) =
delete;
59 explicit CachedTokenArray(
const ScDocument& rDoc ) :
62 Item*
get(
const ScAddress& rPos, std::u16string_view rFormula )
65 ColCacheType::iterator it =
maCache.find(rPos.
Col());
69 Item& rCached = *it->second;
72 if (rFormula == aPredicted)
80 ColCacheType::iterator it =
maCache.find(rPos.
Col());
84 std::pair<ColCacheType::iterator,bool> r =
85 maCache.emplace(rPos.
Col(), std::make_unique<Item>());
93 Item& rItem = *it->second;
94 rItem.mnRow = rPos.
Row();
99 typedef std::unordered_map<SCCOL, std::unique_ptr<Item>> ColCacheType;
104void applySharedFormulas(
107 std::vector<FormulaBuffer::SharedFormulaEntry>& rSharedFormulas,
108 std::vector<FormulaBuffer::SharedFormulaDesc>& rCells,
109 bool bGeneratorKnownGood)
114 for (
const FormulaBuffer::SharedFormulaEntry& rEntry : rSharedFormulas)
116 const ScAddress& aPos = rEntry.maAddress;
117 sal_Int32
nId = rEntry.mnSharedId;
118 const OUString& rTokenStr = rEntry.maTokenStr;
122 std::unique_ptr<ScTokenArray> pArray = aComp.
CompileString(rTokenStr);
126 aGroups.
set(
nId, std::move(pArray), aPos);
134 for (
const FormulaBuffer::SharedFormulaDesc& rDesc : rCells)
152 if (rOrigin.
Col() != aPos.
Col())
160 if (bNeedNumberFormat)
163 if (rDesc.maCellValue.isEmpty())
176 switch (rDesc.mnValueType)
180 if (bNeedNumberFormat)
185 if (rDesc.maCellValue ==
"1" || rDesc.maCellValue ==
"0")
203 if (bGeneratorKnownGood)
226void applyCellFormulas(
228 const Sequence<ExternalLinkInfo>& rExternalLinks,
229 const std::vector<FormulaBuffer::TokenAddressItem>& rCells )
231 for (
const FormulaBuffer::TokenAddressItem& rItem : rCells)
234 CachedTokenArray::Item*
p = rCache.get(aPos, rItem.maTokenStr);
240 if (
p->mnRow + 1 == aPos.
Row())
248 assert(rPrev.
aPos.
Row() ==
p->mnRow);
263 p->mnRow = aPos.
Row();
269 aCompiler.SetNumberFormatter(&rFormatter);
270 aCompiler.SetExternalLinks(rExternalLinks);
271 std::unique_ptr<ScTokenArray> pCode = aCompiler.CompileString(rItem.maTokenStr);
275 aCompiler.CompileTokenArray();
281 rCache.store(aPos, pCell);
285void applyArrayFormulas(
287 const Sequence<ExternalLinkInfo>& rExternalLinks,
288 const std::vector<FormulaBuffer::TokenRangeAddressItem>& rArrays )
290 for (
const FormulaBuffer::TokenRangeAddressItem& rAddressItem : rArrays)
292 const ScAddress& aPos = rAddressItem.maTokenAndAddress.maAddress;
295 aComp.SetNumberFormatter(&rFormatter);
296 aComp.SetExternalLinks(rExternalLinks);
297 std::unique_ptr<ScTokenArray> pArray(aComp.CompileString(rAddressItem.maTokenAndAddress.maTokenStr));
303void applyCellFormulaValues(
304 ScDocumentImport& rDoc,
const std::vector<FormulaBuffer::FormulaValue>& rVector,
bool bGeneratorKnownGood )
308 for (
const FormulaBuffer::FormulaValue& rValue : rVector)
310 const ScAddress& aCellPos = rValue.maAddress;
312 const OUString& rValueStr = rValue.maValueStr;
316 switch (rValue.mnCellType)
336 if (bGeneratorKnownGood)
350void processSheetFormulaCells(
352 const Sequence<ExternalLinkInfo>& rExternalLinks,
bool bGeneratorKnownGood )
354 if (rItem.mpSharedFormulaEntries && rItem.mpSharedFormulaIDs)
355 applySharedFormulas(rDoc, rFormatter, *rItem.mpSharedFormulaEntries,
356 *rItem.mpSharedFormulaIDs, bGeneratorKnownGood);
358 if (rItem.mpCellFormulas)
360 CachedTokenArray aCache(rDoc.
getDoc());
361 applyCellFormulas(rDoc, aCache, rFormatter, rExternalLinks, *rItem.mpCellFormulas);
364 if (rItem.mpArrayFormulas)
365 applyArrayFormulas(rDoc, rFormatter, rExternalLinks, *rItem.mpArrayFormulas);
367 if (rItem.mpCellFormulaValues)
368 applyCellFormulaValues(rDoc, *rItem.mpCellFormulaValues, bGeneratorKnownGood);
375 OUString aTokenStr, sal_Int32 nSharedId ) :
376 maAddress(rAddr), maTokenStr(
std::move(aTokenStr)), mnSharedId(nSharedId) {}
379 const ScAddress& rAddr, sal_Int32 nSharedId,
380 OUString aCellValue, sal_Int32 nValueType ) :
381 maAddress(rAddr), maCellValue(
std::move(aCellValue)), mnSharedId(nSharedId),
mnValueType(nValueType) {}
384 mpCellFormulas(nullptr),
385 mpArrayFormulas(nullptr),
386 mpCellFormulaValues(nullptr),
387 mpSharedFormulaEntries(nullptr),
388 mpSharedFormulaIDs(nullptr) {}
414 std::vector<SheetItem> aSheetItems;
415 aSheetItems.reserve(nTabCount);
416 for (
SCTAB nTab = 0; nTab < nTabCount; ++nTab)
429 xFormulaBar->setPosition( 1.0 );
460 sal_Int32 nSharedId,
const OUString& rTokens )
465 rSharedFormulas.push_back( aEntry );
475 const ScAddress& rAddress, sal_Int32 nSharedId,
const OUString& rCellValue, sal_Int32 nValueType )
490 const ScAddress& rAddress,
const OUString& rValueStr, sal_Int32 nCellType )
void SetNumberFormatter(SvNumberFormatter *pFormatter)
std::unique_ptr< ScTokenArray > CompileString(const OUString &rFormula)
Tokenize formula expression string into an array of tokens.
Accessor class to ScDocument.
void setMatrixCells(const ScRange &rRange, const ScTokenArray &rArray, formula::FormulaGrammar::Grammar eGrammar)
void setFormulaCell(const ScAddress &rPos, const OUString &rFormula, formula::FormulaGrammar::Grammar eGrammar, const double *pResult=nullptr)
SC_DLLPUBLIC sal_uInt32 GetNumberFormat(SCCOL nCol, SCROW nRow, SCTAB nTab) const
SC_DLLPUBLIC ScExternalRefManager * GetExternalRefManager() const
SC_DLLPUBLIC void SetAutoNameCache(std::unique_ptr< ScAutoNameCache > pCache)
SC_DLLPUBLIC void SetNumberFormat(const ScAddress &rPos, sal_uInt32 nNumberFormat)
SC_DLLPUBLIC svl::SharedStringPool & GetSharedStringPool()
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
SC_DLLPUBLIC const ScFormulaCell * GetFormulaCell(const ScAddress &rPos) const
SC_DLLPUBLIC SCTAB GetTableCount() const
Use this guard when performing something from the API that might query values from external reference...
void addFilesToLinkManager()
Add all known external files to the LinkManager.
std::unique_ptr< ScTokenArray > Clone() const
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...
virtual ISegmentProgressBarRef createSegment(double fLength) override
Helper class to provide access to global workbook data.
bool isGeneratorKnownGood() const
Returns true when reading a file generated by a known good generator.
ScDocumentImport & getDocImport()
SegmentProgressBar & getProgressBar() const
Returns the filter progress bar.
ExternalLinkBuffer & getExternalLinks() const
Returns the external links read from the external links substream.
const ScAddress & getOrigin() const
const ScTokenArray * getTokenArray() const
SharedString intern(const OUString &rStr)
#define SAL_WARN(area, stream)
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
std::shared_ptr< ISegmentProgressBar > ISegmentProgressBarRef
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
Represents a shared formula definition.
SharedFormulaEntry(const ScAddress &rAddress, OUString aTokenStr, sal_Int32 nSharedId)
Context for creating string from an array of formula tokens, used in ScTokenArray::CreateString().
::boost::intrusive_ptr< ScFormulaCellGroup > ScFormulaCellGroupRef
#define SV_COUNTRY_LANGUAGE_OFFSET