Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xlsx reader now parses headerless objects #46

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/FsSpreadsheet.ExcelIO/FsExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ module FsExtensions =
let topLeftBoundary, bottomRightBoundary = Table.getArea table |> Table.Area.toBoundaries
let ra = FsRangeAddress(FsAddress(topLeftBoundary), FsAddress(bottomRightBoundary))
let totalsRowShown = if table.TotalsRowShown = null then false else table.TotalsRowShown.Value
FsTable(table.Name, ra, totalsRowShown, true)
let showHeaderRow = if table.HeaderRowCount = null then false else table.HeaderRowCount.Value = 1u
FsTable(table.Name, ra, totalsRowShown, showHeaderRow)

/// <summary>
/// Returns the FsWorksheet associated with the FsTable in a given FsWorkbook.
Expand Down
7 changes: 6 additions & 1 deletion src/FsSpreadsheet.ExcelIO/Table.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ module Table =

/// Given a "A1:A1"-style area, returns A1-based cell start and end cellReferences.
let toBoundaries (area : StringValue) =

area.Value.Split ':'
|> fun a -> a.[0], a.[1]
|> fun a ->
if a.Length = 1 then
area.Value, area.Value
else
a.[0], a.[1]

/// Gets the right boundary of the area.
let rightBoundary (area : StringValue) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<None Include="data/*.xlsx" CopyToOutputDirectory="Always"/>
<Compile Include="Utils.fs" />
<Compile Include="TestObjects.fs" />
<Compile Include="OpenXml\FsExtensions.fs" />
Expand All @@ -19,6 +20,8 @@
<Compile Include="Main.fs" />
</ItemGroup>

<ItemGroup />

<ItemGroup>
<PackageReference Include="Expecto" Version="10.1.0" />
<PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.*" />
Expand Down
9 changes: 8 additions & 1 deletion tests/FsSpreadsheet.ExcelIO.Tests/Table.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ let transformTable =
Expect.isTrue (table.TotalsRowShown = null) "Check that field of interest is None"
FsTable.fromXlsxTable table |> ignore
)

testCase "handleNoHeaders" (fun () ->
let doc = Spreadsheet.fromFile TestObjects.headerLessTablePath false
let wsp = doc.WorkbookPart.WorksheetParts |> Seq.head
let t = wsp |> Worksheet.WorksheetPart.getTables |> Seq.head
let parsed = FsTable.fromXlsxTable t
Expect.equal (parsed.RangeAddress.ToString()) "B8:B8" "Range address should be B8:B8"
Expect.isFalse parsed.ShowHeaderRow "ShowHeaderRow should be false"
)
]


Expand Down
5 changes: 4 additions & 1 deletion tests/FsSpreadsheet.ExcelIO.Tests/TestObjects.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ let sheet2() =
FsCell.createWithDataType DataType.Number 2 4 8
]
|> List.iter (fun c -> ws.Row(c.RowNumber).[c.ColumnNumber].SetValueAs c.Value)
ws
ws

let headerLessTablePath =
"data/headerLessTable.xlsx"
Binary file not shown.
Binary file not shown.