14 #include <rtl/strbuf.hxx>
15 #include <rtl/character.hxx>
21 #include <officecfg/Office/Common.hxx>
22 #include <libxml/xpath.h>
25 #include <document.hxx>
26 #include <tokenarray.hxx>
33 #include <string_view>
42 if (!MustHaveParamCount( nParamCount, 2 ) )
45 SCSIZE nMatCols = 1, nMatRows = 1, nNode = 0;
49 if (pJumpMatrix || IsInArrayContext())
56 SCSIZE nCurCol = 0, nCurRow = 0;
57 pJumpMatrix->GetPos( nCurCol, nCurRow);
60 else if (bMatrixFormula)
68 pMyFormulaCell->GetMatColsRows( nCols, nRows);
75 const ScMatrix* pPathMatrix = pStack[sp-1]->GetMatrix();
78 PushIllegalParameter();
91 if (!nMatCols || !nMatRows)
97 OUString aXPathExpression =
GetString().getString();
98 OUString aString =
GetString().getString();
99 if(aString.isEmpty() || aXPathExpression.isEmpty())
101 PushError( FormulaError::NoValue );
105 OString aOXPathExpression =
OUStringToOString( aXPathExpression, RTL_TEXTENCODING_UTF8 );
106 const char* pXPathExpr = aOXPathExpression.getStr();
108 const char* pXML = aOString.getStr();
110 std::shared_ptr<xmlParserCtxt> pContext(
111 xmlNewParserCtxt(), xmlFreeParserCtxt );
113 std::shared_ptr<xmlDoc> pDoc( xmlParseMemory( pXML, aOString.getLength() ),
118 PushError( FormulaError::NoValue );
122 std::shared_ptr<xmlXPathContext> pXPathCtx( xmlXPathNewContext(pDoc.get()),
123 xmlXPathFreeContext );
125 std::shared_ptr<xmlXPathObject> pXPathObj( xmlXPathEvalExpression(BAD_CAST(pXPathExpr), pXPathCtx.get()),
126 xmlXPathFreeObject );
130 PushError( FormulaError::NoValue );
134 switch(pXPathObj->type)
136 case XPATH_UNDEFINED:
141 xmlNodeSetPtr pNodeSet = pXPathObj->nodesetval;
144 PushError( FormulaError::NoValue );
148 const size_t nSize = pNodeSet->nodeNr;
152 PushError( FormulaError::NotAvailable);
164 xResMat = GetNewMat( 1, nMatRows,
true);
167 PushError( FormulaError::CodeOverflow);
172 for ( ; nNode < nMatRows; ++nNode)
177 if(pNodeSet->nodeTab[nNode]->type == XML_NAMESPACE_DECL)
179 xmlNsPtr
ns =
reinterpret_cast<xmlNsPtr
>(pNodeSet->nodeTab[nNode]);
180 xmlNodePtr cur =
reinterpret_cast<xmlNodePtr
>(ns->next);
181 std::shared_ptr<xmlChar> pChar2(xmlNodeGetContent(cur), xmlFree);
182 aResult = OStringToOUString(std::string_view(reinterpret_cast<char*>(pChar2.get())), RTL_TEXTENCODING_UTF8);
186 xmlNodePtr cur = pNodeSet->nodeTab[nNode];
187 std::shared_ptr<xmlChar> pChar2(xmlNodeGetContent(cur), xmlFree);
188 aResult = OStringToOUString(std::string_view(reinterpret_cast<char*>(pChar2.get())), RTL_TEXTENCODING_UTF8);
191 xResMat->PutString( mrStrPool.intern( aResult), 0, nNode);
198 xResMat->PutError( FormulaError::NotAvailable, 0, nNode);
200 PushError( FormulaError::NotAvailable );
204 PushMatrix( xResMat);
209 bool bVal = pXPathObj->boolval != 0;
210 PushDouble(
double(bVal));
215 double fVal = pXPathObj->floatval;
220 PushString(OUString::createFromAscii(reinterpret_cast<char*>(pXPathObj->stringval)));
228 case XPATH_LOCATIONSET:
234 case XPATH_XSLT_TREE:
244 for (
size_t i=0;
i<nCount; ++
i)
249 if (
pLink->GetURL() == rURL)
261 if (aLink.
DataChanged( OUString(), css::uno::Any()) != sfx2::SvBaseLink::UpdateResult::SUCCESS)
275 if (!MustHaveParamCount( nParamCount, 1 ) )
282 PushError( FormulaError::NoValue );
288 if (eProtocol != INetProtocol::Http && eProtocol != INetProtocol::Https)
290 PushError(FormulaError::NoValue);
296 if (!mrDoc.IsFunctionAccess() || mrDoc.HasLinkFormulaNeedingCheck())
298 PushError( FormulaError::NoValue);
304 PushString( aResult);
306 PushError( FormulaError::NoValue);
312 pArr->AddRecalcMode( ScRecalcMode::ONLOAD_LENIENT );
315 bool bOldEnabled = mrDoc.IsIdleEnabled();
316 mrDoc.EnableIdle(
false);
321 bool bWasError = (pMyFormulaCell && pMyFormulaCell->GetRawError() != FormulaError::NONE);
327 if ( mpLinkManager->GetLinks().size() == 1 )
337 if (!mrDoc.HasLinkFormulaNeedingCheck())
345 pMyFormulaCell->StartListening(*pLink);
351 pMyFormulaCell->StartListening(*pLink);
355 if (pMyFormulaCell && pMyFormulaCell->GetRawError() != FormulaError::NONE && !bWasError)
356 pMyFormulaCell->SetErrCode(FormulaError::NONE);
361 else if (mrDoc.HasLinkFormulaNeedingCheck())
380 if (pMyFormulaCell && pMyFormulaCell->HasHybridStringResult())
382 if (pMyFormulaCell->GetCode()->GetCodeLen() == 2)
386 PushString( pMyFormulaCell->GetResultString());
388 PushError(FormulaError::LinkFormulaNeedingCheck);
391 PushError(FormulaError::LinkFormulaNeedingCheck);
394 PushError(FormulaError::LinkFormulaNeedingCheck);
397 PushError(FormulaError::NoValue);
399 mrDoc.EnableIdle(bOldEnabled);
400 mpLinkManager->CloseCachedComps();
416 if ( !MustHaveParamCount( nParamCount, 1 ) )
420 if ( aStr.isEmpty() )
422 PushError( FormulaError::NoValue );
426 OString aUtf8Str( aStr.toUtf8());
427 const sal_Int32 nLen = aUtf8Str.getLength();
428 OStringBuffer aUrlBuf( nLen );
429 for (
int i = 0;
i < nLen;
i++ )
431 char c = aUtf8Str[
i ];
432 if ( rtl::isAsciiAlphanumeric( static_cast<unsigned char>( c ) ) || c ==
'-' || c ==
'_' )
436 aUrlBuf.append(
'%' );
437 OString convertedChar = OString::number( static_cast<unsigned char>( c ), 16 ).toAsciiUpperCase();
442 if (convertedChar.getLength() == 1)
444 aUrlBuf.append(convertedChar);
447 PushString( OUString::fromUtf8( aUrlBuf ) );
456 if (!officecfg::Office::Common::Misc::ExperimentalMode::get())
458 PushError(FormulaError::NoName);
462 if (!MustHaveParamCount(GetByte(), 1))
465 rtl_uString*
p =
GetString().getDataIgnoreCase();
468 PushIllegalParameter();
472 OUString aStrUpper(p);
474 if (aStrUpper ==
"PIVOTCOUNT")
479 if (mrDoc.HasPivotTable())
486 else if (aStrUpper ==
"DATASTREAM_IMPORT")
488 else if (aStrUpper ==
"DATASTREAM_RECALC")
490 else if (aStrUpper ==
"DATASTREAM_RENDER")
493 PushIllegalParameter();
499 if (MustHaveParamCount( nParamCount, 1 ) )
500 PushDouble( std::erf( GetDouble() ) );
506 if (MustHaveParamCount( nParamCount, 1 ) )
507 PushDouble( std::erfc( GetDouble() ) );
513 if(!MustHaveParamCount(nParamCount, 3, 4))
518 nAlpha = rtl::math::approxFloor(GetDouble());
520 if(nAlpha < 0 || nAlpha > 255)
522 PushIllegalArgument();
526 double nBlue = rtl::math::approxFloor(GetDouble());
528 if(nBlue < 0 || nBlue > 255)
530 PushIllegalArgument();
534 double nGreen = rtl::math::approxFloor(GetDouble());
536 if(nGreen < 0 || nGreen > 255)
538 PushIllegalArgument();
542 double nRed = rtl::math::approxFloor(GetDouble());
544 if(nRed < 0 || nRed > 255)
546 PushIllegalArgument();
550 double nVal = 256*256*256*nAlpha + 256*256*nRed + 256*nGreen + nBlue;
Matrix data type that can store values of mixed types.
SC_DLLPUBLIC size_t GetCount() const
const OUString & GetResult() const
void Invalidate(sal_uInt16 nId)
OUString GetString(int nId)
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
const SvBaseLinks & GetLinks() const
static bool lcl_FunctionAccessLoadWebServiceLink(OUString &rResult, ScDocument *pDoc, const OUString &rURI)
void GetDimensions(SCSIZE &rC, SCSIZE &rR) const
double datastream_get_time(DebugTime nIdx)
static ScWebServiceLink * lcl_GetWebServiceLink(const sfx2::LinkManager *pLinkMgr, std::u16string_view rURL)
void ScEncodeURL()
Returns a string in which all non-alphanumeric characters except stroke and underscore (-_) have been...
virtual ::sfx2::SvBaseLink::UpdateResult DataChanged(const OUString &rMimeType, const css::uno::Any &rValue) override
INetProtocol GetProtocol() const