Sylvan.Data.Ods
0.1.0-b0001
Prefix Reserved
dotnet add package Sylvan.Data.Ods --version 0.1.0-b0001
NuGet\Install-Package Sylvan.Data.Ods -Version 0.1.0-b0001
<PackageReference Include="Sylvan.Data.Ods" Version="0.1.0-b0001" />
<PackageVersion Include="Sylvan.Data.Ods" Version="0.1.0-b0001" />
<PackageReference Include="Sylvan.Data.Ods" />
paket add Sylvan.Data.Ods --version 0.1.0-b0001
#r "nuget: Sylvan.Data.Ods, 0.1.0-b0001"
#:package Sylvan.Data.Ods@0.1.0-b0001
#addin nuget:?package=Sylvan.Data.Ods&version=0.1.0-b0001&prerelease
#tool nuget:?package=Sylvan.Data.Ods&version=0.1.0-b0001&prerelease
Sylvan.Data.Ods
A cross-platform .NET library for reading OpenDocument spreadsheet data files.
OdsDataReader provides readonly, row by row, forward-only access to the data. It provides a familiar API via DbDataReader, which is ideal for accessing rectangular, tabular data sets.
The library is a purely managed implementation with no external dependencies.
If you encounter any issues while using this library, please report an issue in the github repository. Be aware that I will be unlikely to investigate any issue unless an example file can be provided reproducing the issue.
Installing
Install-Package Sylvan.Data.Ods
OdsDataReader
OdsDataReader derives from DbDataReader, so it exposes an API that should be familiar for anyone who has worked with ADO.NET before. The field accessors allow reading data in an efficient, strongly-typed manner: GetString, GetInt32, GetDateTime, GetBoolean, etc.
The GetOdsDataType method allows inspecting the native Ods data type of a cell, which may vary from row to row. FieldCount, returns the number of columns in the header row, and doesn't change while processing each row in a sheet. RowFieldCount returns the number of fields in the current row, which might vary from row to row, and can be used to access cells in a "jagged", non-rectangular file.
Reading Data Manually
The OdsDataReader provides a forward only, row by row access to the data in a worksheet. It allows iterating over sheets using the NextResult() method, and iterating over rows using the Read() method. Fields are accessed using standard accessors, most commonly GetString(). GetString() is designed to not throw an exception, except in the case that a cell contains a formula error.
using Sylvan.Data.Ods;
// OdsDataReader derives from System.Data.DbDataReader
using OdsDataReader edr = OdsDataReader.Create("data.ods");
do
{
var sheetName = edr.WorksheetName;
// enumerate rows in current sheet.
while(edr.Read())
{
// iterate cells in row.
// can use edr.RowFieldCount when sheet contains jagged, non-rectangular data
for(int i = 0; i < edr.FieldCount; i++)
{
var value = edr.GetString(i);
}
// Can use other strongly-typed accessors
// bool flag = edr.GetBoolean(0);
// DateTime date = edr.GetDateTime(1);
// decimal amt = edr.GetDecimal(2);
}
// iterates sheets
} while(edr.NextResult());
Bind Ods data to objects using Sylvan.Data
The Sylvan.Data library (a separate nuget package) includes a general-purpose data binder that can bind a DbDataReader to objects. This can be used to easily read an Ods file as a series of strongly typed objects.
using Sylvan.Data;
using Sylvan.Data.Ods;
using var edr = OdsDataReader.Create("data.ods");
foreach (MyRecord item in edr.GetRecords<MyRecord>())
{
Console.WriteLine($"{item.Name} {item.Quantity}");
}
class MyRecord
{
public int Id { get; set; }
public string Name { get; set; }
public int? Quantity { get; set; }
public DateTime Date { get; set; }
}
Converting Ods data to CSV(s)
The Sylvan.Data.Csv library can be used to convert Ods worksheet data to CSV.
using Sylvan.Data.Ods;
using Sylvan.Data.Csv;
using var edr = OdsDataReader.Create("data.ods");
do
{
var sheetName = edr.WorksheetName;
using CsvDataWriter cdw = CsvDataWriter.Create("data-" + sheetName + ".csv")
cdw.Write(edr);
} while(edr.NextResult());
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|