23#include <com/sun/star/sheet/NamedRangeFlag.hpp>
24#include <com/sun/star/sheet/XPrintAreas.hpp>
25#include <com/sun/star/sheet/XSpreadsheet.hpp>
27#include <osl/diagnose.h>
28#include <rtl/ustrbuf.hxx>
31#include <oox/token/tokens.hxx>
38#include <tokenarray.hxx>
40#include <compiler.hxx>
41#include <document.hxx>
51const sal_uInt32 BIFF12_DEFNAME_HIDDEN = 0x00000001;
52const sal_uInt32 BIFF12_DEFNAME_FUNC = 0x00000002;
53const sal_uInt32 BIFF12_DEFNAME_VBNAME = 0x00000004;
54const sal_uInt32 BIFF12_DEFNAME_MACRO = 0x00000008;
55const sal_uInt32 BIFF12_DEFNAME_BUILTIN = 0x00000020;
57constexpr OUStringLiteral spcOoxPrefix(u
"_xlnm.");
59const char*
const sppcBaseNames[] =
79 OSL_ENSURE( cBuiltinId <
SAL_N_ELEMENTS( sppcBaseNames ),
"lclGetBaseName - unsupported built-in identifier" );
82 aBuffer.appendAscii( sppcBaseNames[ cBuiltinId ] );
84 aBuffer.append(
static_cast< sal_Int32
>( cBuiltinId ) );
85 return aBuffer.makeStringAndClear();
88OUString lclGetPrefixedName(
sal_Unicode cBuiltinId )
90 return spcOoxPrefix + lclGetBaseName( cBuiltinId );
94sal_Unicode lclGetBuiltinIdFromPrefixedName( std::u16string_view aModelName )
100 OUString aBaseName = lclGetBaseName( cBuiltinId );
101 sal_Int32 nBaseNameLen = aBaseName.getLength();
102 if( (sal_Int32(aModelName.size()) == spcOoxPrefix.getLength() + nBaseNameLen) &&
o3tl::matchIgnoreAsciiCase( aModelName, aBaseName, spcOoxPrefix.getLength() ) )
110sal_Unicode lclGetBuiltinIdFromBaseName( std::u16string_view rModelName )
118OUString lclGetUpcaseModelName(
const OUString& rModelName )
121 return rModelName.toAsciiUpperCase();
150 maScRangeData(nullptr, false),
181 nFlags =
rStrm.readuInt32();
195 if(
getFlag( nFlags, BIFF12_DEFNAME_BUILTIN ) )
199 sal_Int64 nRecPos =
rStrm.tell();
200 sal_Int32 nFmlaSize =
rStrm.readInt32();
201 rStrm.skip( nFmlaSize );
202 sal_Int32 nAddDataSize =
rStrm.readInt32();
203 if( !
rStrm.isEof() && (nFmlaSize > 0) && (nAddDataSize >= 0) && (
rStrm.getRemaining() >= nAddDataSize) )
205 sal_Int32 nTotalSize = 8 + nFmlaSize + nAddDataSize;
207 rStrm.seek( nRecPos );
225 sal_Int32 nNameFlags = 0;
226 using namespace ::com::sun::star::sheet::NamedRangeFlag;
244 const css::uno::Sequence<css::sheet::ExternalLinkInfo>& rExternalLinks)
const
247 OUString aExternDocName;
248 OUString aStartTabName;
249 OUString aEndTabName;
252 aStartTabName, aEndTabName, nFlags,
false,
256 bool bInvalidExternalRef = aExternDocName.toInt32() > 0;
257 return !bInvalidExternalRef;
261 const css::uno::Sequence<css::sheet::ExternalLinkInfo>& rExternalLinks )
273 pArray->SetCodeError(nErr);
287 std::unique_ptr<ScTokenArray> pTokenArray =
getScTokens( rExternalLinks);
288 pScRangeData->
SetCode( *pTokenArray );
292 Sequence< FormulaToken > aFTokenSeq;
305 if( xPrintAreas.is() && !aPrintRanges.
empty() )
314 if( xPrintAreas.is() && !aTitleRanges.
empty() )
316 bool bHasRowTitles =
false;
317 bool bHasColTitles =
false;
319 for (
size_t i = 0, nSize = aTitleRanges.
size();
i < nSize; ++
i)
321 const ScRange& rRange = aTitleRanges[
i];
324 if( !bHasRowTitles && bFullRow && !bFullCol )
326 xPrintAreas->setTitleRows( CellRangeAddress(rRange.
aStart.
Tab(),
329 xPrintAreas->setPrintTitleRows(
true );
330 bHasRowTitles =
true;
332 else if( !bHasColTitles && bFullCol && !bFullRow )
334 xPrintAreas->setTitleColumns( CellRangeAddress(rRange.
aStart.
Tab(),
337 xPrintAreas->setPrintTitleColumns(
true );
338 bHasColTitles =
true;
351 Sequence< FormulaToken > aFTokenSeq;
372 xDefName->importDefinedName( rAttribs );
392 xDefName->createNameObject( ++
index );
396 if( !xDefName->isGlobalName() && xDefName->isBuiltinName() )
399 sal_Int32 nTokenIndex = xDefName->getTokenIndex();
400 if( nTokenIndex >= 0 )
421 OUString aUpcaseName = lclGetUpcaseModelName( rModelName );
424 if( !xDefName && (nCalcSheet >= 0) )
void SetExternalLinks(const css::uno::Sequence< css::sheet::ExternalLinkInfo > &rLinks)
Set external link info for ScAddress::CONV_XL_OOX.
std::unique_ptr< ScTokenArray > CompileString(const OUString &rFormula)
Tokenize formula expression string into an array of tokens.
SC_DLLPUBLIC void CheckLinkFormulaNeedingCheck(const ScTokenArray &rCode)
Check token array and set link check if ocDde/ocWebservice is contained.
SC_DLLPUBLIC void SetCode(const ScTokenArray &)
const sal_Unicode * Parse_XL_Header(const sal_Unicode *pString, const ScDocument &rDocument, OUString &rExternDocName, OUString &rStartTabName, OUString &rEndTabName, ScRefFlags &nFlags, bool bOnlyAcceptSingle, const css::uno::Sequence< css::sheet::ExternalLinkInfo > *pExternalLinks=nullptr, const OUString *pErrRef=nullptr)
Parse an Excel style reference up to and including the sheet name separator '!', including detection ...
static SC_DLLPUBLIC void ConvertToTokenSequence(const ScDocument &rDoc, css::uno::Sequence< css::sheet::FormulaToken > &rSequence, const ScTokenArray &rTokenArray)
std::optional< OUString > getXString(sal_Int32 nAttrToken) const
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
std::optional< bool > getBool(sal_Int32 nAttrToken) const
mapped_type get(key_type nKey) const
value_type get(sal_Int32 nIndex) const
void forEachMem(FuncType pFunc) const
static css::uno::Sequence< css::table::CellRangeAddress > toApiSequence(const ScRangeList &orRanges)
Converts the passed range list to a sequence of cell range addresses.
const ScAddress & getMaxAddress() const
Returns the biggest valid cell address in both Calc and the imported/exported Excel document.
Base class for defined names and external names.
OUString maUpModelName
Model data for this defined name.
const OUString & getUpcaseModelName() const
Returns the original name as imported from or exported to the file.
OUString maCalcName
Model name converted to uppercase ASCII.
DefinedNameBase(const WorkbookHelper &rHelper)
bool isBuiltinName() const
Returns true, if this defined name is a special builtin name.
void convertFormula(const css::uno::Sequence< css::sheet::ExternalLinkInfo > &rExternalLinks)
Converts the formula string or BIFF token array for this defined name.
void createNameObject(sal_Int32 nIndex)
Creates a defined name in the Calc document.
StreamDataSeqPtr mxFormula
Identifier for built-in defined names.
sal_Int16 mnCalcSheet
Name index used in API token array.
bool isValid(const css::uno::Sequence< css::sheet::ExternalLinkInfo > &rExternalLinks) const
void importDefinedName(const AttributeList &rAttribs)
Sets the attributes for this defined name from the passed attribute set.
sal_Int32 mnTokenIndex
ScRangeData of the defined name.
bool isGlobalName() const
Returns true, if this defined name is global in the document.
virtual ~DefinedName() override
bool getAbsoluteRange(ScRange &orRange) const
Tries to resolve the defined name to an absolute cell range.
RangeDataRet maScRangeData
sal_Unicode mcBuiltinId
Calc sheet index for sheet-local names.
void setFormula(const OUString &rFormula)
Sets the formula string from the body of the definedName element.
std::unique_ptr< ScTokenArray > getScTokens(const css::uno::Sequence< css::sheet::ExternalLinkInfo > &rExternalLinks)
DefinedName(const WorkbookHelper &rHelper)
DefNameTokenIdMap maTokenIdMap
Maps all defined names by sheet index and built-in identifier.
DefinedNameRef getByModelName(const OUString &rModelName, sal_Int16 nCalcSheet=-1) const
Returns a defined name by its model name.
DefNameNameMap maModelNameMap
List of all defined names in insertion order.
::std::pair< sal_Int16, sal_Unicode > BuiltinKey
DefinedNameRef getByBuiltinId(sal_Unicode cBuiltinId, sal_Int16 nCalcSheet) const
Returns a built-in defined name by its built-in identifier.
DefNameBuiltinMap maBuiltinMap
Maps all defined names by sheet index and model name.
DefinedNameRef importDefinedName(const AttributeList &rAttribs)
Imports a defined name from the passed attribute set.
void finalizeImport()
Creates all defined names in the document.
DefinedNameRef getByTokenIndex(sal_Int32 nIndex) const
Returns a defined name by token index (index in XDefinedNames container).
DefinedNamesBuffer(const WorkbookHelper &rHelper)
DefinedNameRef createDefinedName()
DefinedNameRef getByIndex(sal_Int32 nIndex) const
Returns a defined name by zero-based index (order of appearance).
::std::pair< sal_Int16, OUString > SheetNameKey
Helper class to provide access to global workbook data.
css::uno::Reference< css::sheet::XSpreadsheet > getSheetFromDoc(sal_Int32 nSheet) const
Returns a reference to the specified spreadsheet in the document model.
WorksheetBuffer & getWorksheets() const
Returns the worksheet buffer containing sheet names and properties.
AddressConverter & getAddressConverter() const
Returns the converter for string to cell address/range conversion.
RangeDataRet createLocalNamedRangeObject(OUString &orName, sal_Int32 nIndex, sal_Int32 nNameFlags, sal_Int32 nTab, bool bHidden) const
Creates and returns a defined name on-the-fly in the sheet.
ScDocument & getScDocument()
FormulaParser & getFormulaParser() const
Returns a shared import formula parser (import filter only!).
ExternalLinkBuffer & getExternalLinks() const
Returns the external links read from the external links substream.
RangeDataRet createNamedRangeObject(OUString &orName, sal_Int32 nIndex, sal_Int32 nNameFlags, bool bHidden) const
Creates and returns a defined name on-the-fly in the Calc document.
sal_Int16 getCalcSheetIndex(sal_Int32 nWorksheet) const
Returns the Calc index of the specified worksheet.
#define SAL_N_ELEMENTS(arr)
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
bool matchIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2, sal_Int32 fromIndex=0)
const sal_Unicode BIFF_DEFNAME_CRITERIA
const sal_Unicode BIFF_DEFNAME_UNKNOWN
std::shared_ptr< DefinedName > DefinedNameRef
const sal_Unicode BIFF_DEFNAME_PRINTAREA
const sal_Unicode BIFF_DEFNAME_PRINTTITLES
const sal_Unicode BIFF_DEFNAME_FILTERDATABASE
css::uno::Sequence< sal_Int8 > StreamDataSequence
bool getFlag(Type nBitField, Type nMask)
bool mbMacro
Function group identifier.
bool mbVBName
True = function, false = command.
sal_Int32 mnFuncGroupId
Sheet index for local names.
bool mbFunction
True = Macro name (VBA or sheet macro).
sal_Int32 mnSheet
The formula string.
bool mbHidden
True = VBA macro, false = sheet macro.
DefinedNameModel()
True = name hidden in UI.
OUString maFormula
The original name.
std::unique_ptr< char[]> aBuffer