Descripción general de la biblioteca Blazor Excel

    The Infragistics Blazor Excel Library allows you to work with spreadsheet data using familiar Microsoft® Excel® spreadsheet objects like Workbook, Worksheet, Cell, Formula and many more. The Infragistics Blazor Excel Library makes it easy for you to represent the data of your application in an Excel spreadsheet as well as transfer data from Excel into your application.

    Blazor Excel Library Example

    Requirements

    Para utilizar la biblioteca de Excel Blazor, debe agregar la siguiente declaración using:

    @using Infragistics.Documents.Excel
    

    Si está utilizando un proyecto Blazor Web Assembly (WASM), hay un par de pasos adicionales:

    • Agregue una referencia al siguiente script en el archivo wwwroot/index.html:
    <script src="_content/IgniteUI.Blazor.Documents.Excel/excel.js"></script>
    
    • Set the static Workbook.InProcessRuntime to the current runtime. This can be done by using the following code:
    @using Microsoft.JSInterop
    
    @code {
    
        [Inject]
        public IJSRuntime Runtime { get; set; }
    
        protected override void OnInitialized()
        {
            base.OnInitialized();
            Workbook.InProcessRuntime = (IJSInProcessRuntime)this.Runtime;
        }
    }
    

    Supported Versions of Microsoft Excel

    La siguiente es una lista de las versiones compatibles de Excel.**

    • MicrosoftExcel 97

    • MicrosoftExcel 2000

    • MicrosoftExcel 2002

    • MicrosoftExcel 2003

    • MicrosoftExcel 2007

    • MicrosoftExcel 2010

    • MicrosoftExcel 2013

    • Excel 2016

    Load and Save Workbooks

    Ahora que se importa el módulo de la Biblioteca de Excel, el siguiente paso es cargar un libro.

    In order to load and save Workbook objects, you can utilize the save method of the actual Workbook object, as well as its static Load method.

    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 References

    • Load
    • WorkbookInProcessRuntime
    • Worksheet
    • Workbook