WldMr.Excel.Core | WldMr.Excel.Functions | |
---|---|---|
preview | ||
stable |
dotnet tool restore
dotnet paket restore
dotnet build
xlTrimNA
, xlTrimEmpty
, xlStackH
, xlStackV
, xlSlice
xlStringStartsWith
, xlStringEndsWith
, xlStringContains
(with regex support and case-sensitivity options)
xlFormatA
xlRegexMatch
xlRangeAnd
, xlRangeOr
xlDateThirdWednesday
, xlDateThirdFriday
xlToday()
: non-volatile RTD-based variant of TODAY()
open ExcelDna.Integration
open FsToolkit.ErrorHandling
open WldMr.Excel
[<ExcelFunction>]
let StringContains (text:xlObj, subString: xlObj): xlObj =
result {
let! text_ = text |> (XlObj.toString |> XlObjParser.withArgName "Text")
let! subString_ = text |> (XlObj.toString |> XlObjParser.withName "Substring")
return text_.Contains(subString_) |> XlObj.ofBoolean
} |> XlObj.ofResult
[<ExcelFunction(Name="myStringContain2")>]
let myStringContainsWithRange (text:xlObj[,], subString: xlObj[,]): xlObj[,] =
let stringContains (text: string) subString =
text.Contains(subString) |> XlObj.ofBool
ArrayFunctionBuilder
.Add("Text", XlObj.toString, text)
.Add("SubString", XlObj.toString, subString)
.EvalFunction stringContains
|> FunctionCall.eval
[<ExcelFunction(Name="myStringContains3")>]
let myStringContainsWithCase (text:xlObj[,], substring: xlObj[,], ignoreCase: xlObj[,]): xlObj[,] =
let stringContains (text: string) (substring: string) ignoreCase =
if ignoreCase then
text.ToLowerInvariant().Contains(substring.ToLowerInvariant()) |> XlObj.ofBool
else
text.Contains(subString) |> XlObj.ofBool
ArrayFunctionBuilder
.Add("Text", XlObj.toString, text)
.Add("Substring", XlObj.toString, substring)
.Add("IgnoreCase", XlObj.toBool |> XlObjParser.withDefault true, ignoreCase)
.EvalFunction stringContains
|> FunctionCall.eval