NeoFileMagic 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package NeoFileMagic --version 1.0.2
                    
NuGet\Install-Package NeoFileMagic -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NeoFileMagic" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NeoFileMagic" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="NeoFileMagic" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NeoFileMagic --version 1.0.2
                    
#r "nuget: NeoFileMagic, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NeoFileMagic@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NeoFileMagic&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=NeoFileMagic&version=1.0.2
                    
Install as a Cake Tool

NeoFileMagic

封面圖

提供「安全、輕量、可控資源上限」的多種檔案格式讀取器, 以支援後續應用快速擷取結構化資料(目前先提供 ODS,後續會陸續擴充其他格式)。

專案一覽(3 個專案)

  • NeoFileMagic(類別庫): 核心檔案讀取框架與公開 API(目前含 ODS 模組)。
  • NeoFileMagic.Tests(測試): xUnit 測試,驗證解析正確性與安全/上限行為。
    • 內含最小 ODS 測試檔與外部資料集連結(下載測試預設略過)。
  • Sample(範例): 範例程式,展示如何載入 ODS 與讀取儲存格。

安裝

  • NuGet:dotnet add package NeoFileMagic

基本使用(C#)

using NeoFileMagic.FileReader.Ods;

// 從檔案載入 ODS
var doc = Ods.Load("sample.ods");

// 讀取第一個工作表的 (0,0) 儲存格
var cell = doc.Sheets[0].GetCell(0, 0);
Console.WriteLine(Ods.OneLine(cell));

使用範例

1) 遍歷列與欄

using NeoFileMagic.FileReader.Ods;

var doc = Ods.Load("sample.ods");
var sheet = doc.Sheets[0];

for (int r = 0; r < sheet.RowCount; r++)
{
    var row = sheet.Rows[r];
    for (int c = 0; c < row.ColumnCount; c++)
    {
        var cell = row.Cells[c];
        // 以單行輸出:換行/Tab 摺疊為空白
        Console.Write(Ods.OneLine(cell));
        Console.Write('\t');
    }
    Console.WriteLine();
}

2) 安全與資源上限設定

using NeoFileMagic.FileReader.Ods;

var options = new OdsReaderOptions
{
    // 預設 true:若檔案加密則丟出 NotSupportedException
    ThrowOnEncrypted = true,

    // 控制上限,避免惡意/異常檔案造成記憶體壓力
    MaxSheets = 64,
    MaxRowsPerSheet = 100_000,
    MaxColumnsPerRow = 256,
    MaxRepeatedRows = 100_000,
    MaxRepeatedColumns = 256,
};

var doc = Ods.Load("sample.ods", options);

3) 以強型別模型反序列化工作表

嚴格依表頭(或 [JsonPropertyName])對應欄位,欄位順序/缺漏或格式錯誤會拋出具體例外。

using System.Text.Json.Serialization;
using NeoFileMagic.FileReader.Ods;

public sealed class Person
{
    [JsonPropertyName("Name")] public string Name { get; set; } = string.Empty;
    [JsonPropertyName("Age")]  public int Age  { get; set; }
}

var doc = Ods.Load("people.ods");
var sheet = doc.Sheets[0];
var list = Ods.DeserializeSheetOrThrow<Person>(sheet);
// list 為強型別結果,若欄位/資料不符會拋出 Ods* 相關例外

4) 從 URL 讀取(非同步)

using NeoFileMagic.FileReader.Ods;

var doc = await Ods.LoadFromUrlAsync("https://example.com/data.ods");

建置/測試:

  • 還原/建置:dotnet restoredotnet build NeoFileMagic -c Debug
  • 測試:dotnet test
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.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.