Como Configurar Licença IronXL em web.config para Planilha Excel em C

This article was translated from English: Does it need improvement?
Translated
View the article in English

O problema foi resolvido a partir da versão 2024.3.20 do IronXL.

Exception: Unhandled exception. IronSoftware.Exceptions.LicensingException: IronXL must be licensed for development.

Para versões mais antigas do IronXL, especificamente entre as versões 2023.4.13 e 2024.3.20 , existe um problema conhecido de licenciamento em:

  • Projetos ASP.NET
  • Versão do .NET Framework >= 4.6.2

A chave armazenada em um arquivo Web.config NÃO será detectada e usada pelo produto.

Solução alternativa

Para resolver esse problema, recomenda-se recuperar a chave de licença do arquivo Web.config usando o ConfigurationManager no código e, em seguida, aplicá-la à propriedade License.LicenseKey.

Exemplo:

Abaixo segue um exemplo de como armazenar a chave de licença em um arquivo Web.config:

<configuration>
  ...
  <appSettings>
    <add key="IronXL.LicenseKey" value="IronXL-MYLICENSE-KEY-1EF01"/>
  </appSettings>
  ...
</configuration>
<configuration>
  ...
  <appSettings>
    <add key="IronXL.LicenseKey" value="IronXL-MYLICENSE-KEY-1EF01"/>
  </appSettings>
  ...
</configuration>
XML

Com o arquivo XML configurado acima, podemos usar o ConfigurationManager para recuperar o valor da chave de licença e defini-lo na propriedade IronXL.License.LicenseKey:

using System.Configuration;

// Retrieve the license key from the Web.config appSettings section
string licenseKey = ConfigurationManager.AppSettings["IronXL.LicenseKey"];

// Apply the retrieved license key to the IronXL component
IronXL.License.LicenseKey = licenseKey;
using System.Configuration;

// Retrieve the license key from the Web.config appSettings section
string licenseKey = ConfigurationManager.AppSettings["IronXL.LicenseKey"];

// Apply the retrieved license key to the IronXL component
IronXL.License.LicenseKey = licenseKey;
Imports System.Configuration

' Retrieve the license key from the Web.config appSettings section
Private licenseKey As String = ConfigurationManager.AppSettings("IronXL.LicenseKey")

' Apply the retrieved license key to the IronXL component
IronXL.License.LicenseKey = licenseKey
$vbLabelText   $csharpLabel

Neste exemplo, o ConfigurationManager.AppSettings é usado para recuperar o valor de IronXL.LicenseKey de Web.config. A chave de licença recuperada é então definida como IronXL.License.LicenseKey para garantir que os componentes do IronXL possam funcionar corretamente.

Curtis Chau
Redator Técnico

Curtis Chau é bacharel em Ciência da Computação (Universidade Carleton) e se especializa em desenvolvimento front-end, com experiência em Node.js, TypeScript, JavaScript e React. Apaixonado por criar interfaces de usuário intuitivas e esteticamente agradáveis, Curtis gosta de trabalhar com frameworks modernos e criar manuais ...

Leia mais
Pronto para começar?
Nuget Downloads 1,950,735 | Versão: 2026.4 acaba de ser lançado
Still Scrolling Icon

Ainda está rolando a tela?

Quer provas rápidas? PM > Install-Package IronXL.Excel
executar um exemplo Veja seus dados se transformarem em uma planilha.