Blazor Excel ライブラリの概要

    Infragistics Blazor Excel ライブラリは、WorkbookWorksheetIgbCellFormula などの人気の Microsoft® Excel® スプレッドシート オブジェクトを使用してスプレッドシート データで作業をすることができます。Infragistics Blazor Excel ライブラリによって Excel スプレッドシートでアプリケーションのデータを表示するだけでなく、Excel からアプリケーションへのデータの転送も簡単になります。

    Blazor Excel ライブラリの例

    要件

    Blazor Excel ライブラリを使用するには、次の using ステートメントを追加する必要があります:

    @using Infragistics.Documents.Excel
    

    Web Assembly (WASM) Blazor プロジェクトを使用している場合は、いくつかの追加手順があります:

    • wwwroot/index.html ファイルに次のスクリプトへの参照を追加します:
    <script src="_content/IgniteUI.Blazor.Documents.Excel/excel.js"></script>
    
    • 静的な Workbook.InProcessRuntime を現在のランタイムに設定します。以下のコードを使用できます:
    @using Microsoft.JSInterop
    
    @code {
    
        [Inject]
        public IJSRuntime Runtime { get; set; }
    
        protected override void OnInitialized()
        {
            base.OnInitialized();
            Workbook.InProcessRuntime = (IJSInProcessRuntime)this.Runtime;
        }
    }
    

    サポートされるバージョンの Microsoft Excel

    以下は Excel のサポートされるバージョンのリストです。

    • Microsoft Excel 97

    • Microsoft Excel 2000

    • Microsoft Excel 2002

    • Microsoft Excel 2003

    • Microsoft Excel 2007

    • Microsoft Excel 2010

    • Microsoft Excel 2013

    • Microsoft Excel 2016

    protected override void OnInitialized()
    {
        var memoryStream = new System.IO.MemoryStream();
        workbook.Save(memoryStream);
    
        memoryStream.Position = 0;
        var bytes = memoryStream.ToArray();
        this.SaveFile(bytes, "fileName.xlsx", string.Empty);
    }
    
    private void SaveFile(byte[] bytes, string fileName, string mime)
    {
        if (this.Runtime is WebAssemblyJSRuntime wasmRuntime)
          wasmRuntime.InvokeUnmarshalled<string, string, byte[], bool>("BlazorDownloadFileFast", fileName, mime, bytes);
        else if (this.Runtime is IJSInProcessRuntime inProc)
          inProc.InvokeVoid("BlazorDownloadFile", fileName, mime, bytes);
    }
    

    API リファレンス

    • Load
    • WorkbookInProcessRuntime
    • Worksheet
    • Workbook