Skip to content

Repository files navigation

ExcelProcesser

Parse excel file with combinator

StablePrerelease
NuGet BadgeNuGet Badge
MacOS/LinuxWindows
CircleCIBuild status
Build HistoryBuild History

Usage

  • Test file can be found in directory ExcelProcesser.Tests
  • Following code can be found in directory ExcelProcesser.Tests too

Parse Cells With Predicate

match cells beginning with GD image

openExcelProcessopenCellParsersopenSystem.DrawingopenArrayParsersletparser:ArrayParser=!@pRegex("GD.*")letworkSheet="test.xlsx"|>Excel.getWorksheetByIndex 1letreply=
workSheet
|>ArrayParser.run parser
|>fun c->c.userRange
|>Seq.map(fun c->c.Address)|>List.ofSeq
match reply with|["D2";"D4";"D11";"D13"]->pass()|_->fail()

Parse Cells With (Predicates Linked By AND)

match cells of which text begins with GD, and of which background color is yellow

letparser:ArrayParser=!@(pRegex("GD.*")<&> pBkColor Color.Yellow)

Parse Cells In Sequence

match cells of which text begins with GD, and of which right cell's font color is blue

letparser:ArrayParser=!@pRegex("GD.*")+>>+!@(pFontColor Color.Blue)

Below operators are similiar

ExprocessorFParsec
+>>+.>>.
+>>.>>
>>+>>.

Parse Cells in multi rows

If operator prefix with ^. eg. ^+>>+ This means it is used to parse multiple rows

Sample: match cells of which text begins with GD, and to which Second perpendicular of which text begins with GD

letparser:ArrayParser=!@pRegex("GD.*")^>>+ yPlaceholder 1^>>+!@pRegex("GD.*")

Parse with many operator

Match cells whose left item beigin with STYLE and whose text begin with number Then batch the result as ExcelRange eg. "B18:E18"

letparser:ArrayParser=letsizeParser=!@pFParsec(pint32.>>pchar '#')|> xlMany
!@pRegex("STYLE.*")>>+ sizeParser
letreply=
workSheet
|> ArrayParser.run parser
|>fun c->c.userRange
|>Seq.map(fun c->c.Address)|>List.ofSeq
match reply with|["B18:E18"]->pass()|_->fail()

Parse with xUntil operator

letparser:ArrayParser=!@(pText ((=)"Begin"))+>> xUntil (fun _ ->true)!@(pText ((=)"Until"))letshift= workSheet
|>runArrayParser parser
|>fun c->c.xShifts
match shift with|[4]->pass()|_->fail()

Parse with yUntil operator

letparser:ArrayParser=!@(pText ((=)"Begin"))^+>> yUntil (fun _ ->true)!@(pText ((=)"Until"))letshift= workSheet
|>runArrayParser parser
|>fun c->c.xShifts
match shift with|[0;0;0;0;0;0;0]->pass()|_->fail()

Advanced: Parser with fparsec parsers and with matrix tuple returned

See Tests.MatrixParsers.fs For Details

Debug Test In VsCode

  • open reposity in VsCode
  • .paket/paket.exe install
  • cd ExcelProcesser.Tests
  • dotnet restore
  • press F5

About

Parse excel file with combinator

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages