Parse excel file with combinator
Stable | Prerelease |
---|---|
MacOS/Linux | Windows |
---|---|
- Test file can be found in directory ExcelProcesser.Tests
- Following code can be found in directory ExcelProcesser.Tests too
open ExcelProcess
open CellParsers
open System.Drawing
open ArrayParsers
let parser:ArrayParser=
!@pRegex("GD.*")
let workSheet= "test.xlsx"
|>Excel.getWorksheetByIndex 1
let reply=
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()
match cells of which text begins with GD, and of which background color is yellow
let parser:ArrayParser=
!@(pRegex("GD.*") <&> pBkColor Color.Yellow)
match cells of which text begins with GD, and of which right cell's font color is blue
let parser:ArrayParser=
!@pRegex("GD.*") +>>+ !@(pFontColor Color.Blue)
Below operators are similiar
Exprocessor | FParsec |
---|---|
+>>+ | .>>. |
+>> | .>> |
>>+ | >>. |
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
let parser:ArrayParser=
!@pRegex("GD.*")
^>>+ yPlaceholder 1
^>>+ !@pRegex("GD.*")
Match cells whose left item beigin with STYLE and whose text begin with number Then batch the result as ExcelRange eg. "B18:E18"
let parser:ArrayParser=
let sizeParser = !@pFParsec(pint32.>>pchar '#') |> xlMany
!@pRegex("STYLE.*") >>+ sizeParser
let reply=
workSheet
|> ArrayParser.run parser
|>fun c->c.userRange
|>Seq.map(fun c->c.Address)
|>List.ofSeq
match reply with
|["B18:E18"]->pass()
|_->fail()
let parser:ArrayParser=
!@ (pText ((=) "Begin")) +>> xUntil (fun _ -> true) !@ (pText ((=) "Until"))
let shift= workSheet
|>runArrayParser parser
|>fun c->c.xShifts
match shift with
|[4] ->pass()
|_->fail()
let parser:ArrayParser=
!@ (pText ((=) "Begin")) ^+>> yUntil (fun _ -> true) !@ (pText ((=) "Until"))
let shift= workSheet
|>runArrayParser parser
|>fun c->c.xShifts
match shift with
| [0;0;0;0;0;0;0] ->pass()
|_->fail()
See Tests.MatrixParsers.fs For Details
- open reposity in VsCode
- .paket/paket.exe install
- cd ExcelProcesser.Tests
- dotnet restore
- press F5