-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ExcelIO: bool & float write. Fix exceljs: table postion write, ce…
…ll value type read and write, confusing naming. Add scripts for fsspreadsheet write. ✨🤡
- Loading branch information
1 parent
6fe7f89
commit 56d533f
Showing
25 changed files
with
272 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
namespace FsSpreadsheet.Exceljs | ||
|
||
|
||
module JsCell = | ||
|
||
open Fable.Core | ||
open Fable.Core.JsInterop | ||
open FsSpreadsheet | ||
open Fable.ExcelJs | ||
|
||
[<Emit("console.log($0)")>] | ||
let private log (obj:obj) = jsNative | ||
|
||
let writeFromFsCell (fsCell: FsCell) = | ||
match fsCell.DataType with | ||
| Boolean -> | ||
fsCell.ValueAsBool() |> box |> Some | ||
| Number -> | ||
fsCell.ValueAsFloat() |> box |> Some | ||
| Date -> | ||
/// Here it will actually show the correct DateTime. But when writing, exceljs will apply local offset. | ||
let dt = fsCell.ValueAsDateTime() |> System.DateTimeOffset | ||
/// Therefore we add offset and it should work. | ||
let dt = dt + dt.Offset |> box |> Some | ||
dt | ||
| String -> | ||
fsCell.Value |> Some | ||
| anyElse -> | ||
let msg = sprintf "ValueType '%A' is not fully implemented in FsSpreadsheet and is handled as string input." anyElse | ||
#if FABLE_COMPILER_JAVASCRIPT | ||
log msg | ||
#else | ||
printfn "%s" msg | ||
#endif | ||
fsCell.Value |> box |> Some | ||
|
||
/// <summary> | ||
/// `worksheetName`, `rowIndex` and `columnIndex` are only used for debugging. | ||
/// </summary> | ||
/// <param name="worksheetName"></param> | ||
/// <param name="rowIndex"></param> | ||
/// <param name="columnIndex"></param> | ||
/// <param name="jsCell"></param> | ||
let readToFsCell worksheetName rowIndex columnIndex (jsCell: Cell) = | ||
let t = enum<Unions.ValueType>(jsCell.``type``) | ||
let fsadress = FsAddress(jsCell.address) | ||
let createFscell = fun dt v -> FsCell(v,dt,address = fsadress) | ||
let vTemp = string jsCell.value.Value | ||
let fscell = | ||
match t with | ||
| ValueType.Boolean -> | ||
let b = System.Boolean.Parse vTemp | ||
createFscell DataType.Boolean b | ||
| ValueType.Number -> float vTemp |> createFscell DataType.Number | ||
| ValueType.Date -> | ||
let dt = System.DateTime.Parse(vTemp).ToUniversalTime() | ||
/// Without this step universal time get changed to local time? Exceljs tests will hit this. | ||
/// | ||
/// Expected item (from test object): C2 : Sat Oct 14 2023 00:00:00 GMT+0200 (Mitteleuropäische Sommerzeit) | Date | ||
/// | ||
/// Actual item (created here): C2 : Sat Oct 14 2023 02:00:00 GMT+0200 (Mitteleuropäische Sommerzeit) | Date | ||
/// | ||
/// But logging hour minute showed that the values were given correctly and needed to be reinitialized. | ||
let dt = System.DateTime(dt.Year,dt.Month,dt.Day,dt.Hour,dt.Minute, dt.Second) | ||
dt |> createFscell DataType.Date | ||
| ValueType.String -> vTemp |> createFscell DataType.String | ||
| ValueType.Formula -> | ||
match jsCell.formula with | ||
| "TRUE()" -> | ||
let b = true | ||
createFscell DataType.Boolean b | ||
| "FALSE()" -> | ||
let b = false | ||
createFscell DataType.Boolean b | ||
| anyElse -> | ||
let msg = sprintf "ValueType 'Format' (%s) is not fully implemented in FsSpreadsheet and is handled as string input. In %s: (%i,%i)" anyElse worksheetName rowIndex columnIndex | ||
log msg | ||
anyElse |> createFscell DataType.String | ||
| ValueType.Hyperlink -> | ||
//log (c.value.Value?text) | ||
jsCell.value.Value?hyperlink |> createFscell DataType.String | ||
| anyElse -> | ||
let msg = sprintf "ValueType `%A` (%s) is not fully implemented in FsSpreadsheet and is handled as string input. In %s: (%i,%i)" anyElse vTemp worksheetName rowIndex columnIndex | ||
log msg | ||
vTemp |> createFscell DataType.String | ||
fscell | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,51 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<Authors>Kevin Frey, Heinrich Lukas Weil, Oliver Maus, Kevin Schneider, Timo Mühlhaus</Authors> | ||
<Description>Excel IO Extensions for the FsSpreadsheet Datamodel in js environments using exceljs.</Description> | ||
<Summary>Spreadsheet creation and manipulation in FSharp</Summary> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageIcon>logo.png</PackageIcon> | ||
<PackageTags>F# FSharp spreadsheet Excel xlsx datascience fable fable-library fable-javascript</PackageTags> | ||
<RepositoryUrl>https://github.com/CSBiology/FsSpreadsheet</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<Authors>Kevin Frey, Heinrich Lukas Weil, Oliver Maus, Kevin Schneider, Timo Mühlhaus</Authors> | ||
<Description>Excel IO Extensions for the FsSpreadsheet Datamodel in js environments using exceljs.</Description> | ||
<Summary>Spreadsheet creation and manipulation in FSharp</Summary> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageIcon>logo.png</PackageIcon> | ||
<PackageTags>F# FSharp spreadsheet Excel xlsx datascience fable fable-library fable-javascript</PackageTags> | ||
<RepositoryUrl>https://github.com/CSBiology/FsSpreadsheet</RepositoryUrl> | ||
<RepositoryType>git</RepositoryType> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\docs\img\logo.png" Link="logo.png"> | ||
<PackagePath>\</PackagePath> | ||
<Pack>true</Pack> | ||
</None> | ||
<Compile Include="Table.fs" /> | ||
<Compile Include="Worksheet.fs" /> | ||
<Compile Include="Workbook.fs" /> | ||
<Compile Include="Xlsx.fs" /> | ||
<Compile Include="FsExtensions.fs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Fable.Exceljs" Version="1.6.0" /> | ||
<PackageReference Include="Fable.Promise" Version="3.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\FsSpreadsheet\FsSpreadsheet.fsproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="*.fsproj; **\*.fs; **\*.fsi" PackagePath="fable\" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup /> | ||
|
||
<PropertyGroup> | ||
<NpmDependencies> | ||
<NpmPackage Name="@nfdi4plants/exceljs" Version="gte 0.1.0 lt 1.0.0" ResolutionStrategy="Max" /> | ||
</NpmDependencies> | ||
</PropertyGroup> | ||
|
||
</Project> | ||
</None> | ||
<Compile Include="Cell.fs" /> | ||
<Compile Include="Table.fs" /> | ||
<Compile Include="Worksheet.fs" /> | ||
<Compile Include="Workbook.fs" /> | ||
<Compile Include="Xlsx.fs" /> | ||
<Compile Include="FsExtensions.fs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Fable.Exceljs" Version="1.6.0" /> | ||
<PackageReference Include="Fable.Promise" Version="3.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\FsSpreadsheet\FsSpreadsheet.fsproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup /> | ||
|
||
<ItemGroup /> | ||
|
||
<PropertyGroup> | ||
<NpmDependencies> | ||
<NpmPackage Name="@nfdi4plants/exceljs" Version="gte 0.1.0 lt 1.0.0" ResolutionStrategy="Max" /> | ||
</NpmDependencies> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.