0

Tenho uma aplicação web que lê uma planilha do excel e importa os valores da células para o banco de dados automaticamente. Estou usando COM, logo é necessário na maquina o Microsoft Excel instalado. Quando compilo localmente funciona sem problemas. Porem, hospedei no azure recentemente e o erro se da justamente por não ter o Excel instalado. Como posso contornar este erro? Não entendo muito do azure, então queria saber uma forma de instalar Microsoft Office Excel.

ERRO QUE APARECE:

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

1 Resposta 1

0

Apenas para resumir: Azure App Services WebApp é uma Plataforma como Serviço. Isso quer dizer que a total responsabilidade pela manutenção da infraestrutura é da Microsoft e não do desenvolvedor. Mas para poderem assumir esse papel, eles deve engessar bastante o ambiente de hospedagem, e abrir apenas pontos realmente relevantes para o desenvolvedor - e instalar softwares em seus servidores está totalmente fora de questão.

Existe uma opção que eu recomendo muito para trabalhar com Excel a partir de sistemas .NET: SpreadSheet Light.

Apesar de ser uma biblioteca com métodos procedurais - não é orientado à objetos, é bem intuitiva e até mesmo elegante de se trabalhar. Veja algunas exemplos:

Ler e modificar dados de uma planilha

// SpreadsheetLight works on the idea of a currently selected worksheet.
// If no worksheet name is provided on opening an existing spreadsheet,
// the first available worksheet is selected.

        SLDocument sl = new SLDocument("ModifyExistingSpreadsheetOriginal.xlsx", "Sheet2");

        sl.SetCellValue("E6", "Let's party!!!!111!!!1");

        sl.SelectWorksheet("Sheet3");
        sl.SetCellValue("E6", "Before anyone calls the popo!");

        sl.AddWorksheet("DanceFloor");
        sl.SetCellValue("B4", "Who let the dogs out?");
        sl.SetCellValue("B5", "Woof!");

        sl.SaveAs("ModifyExistingSpreadsheetModified.xlsx");

        Console.WriteLine("End of program");
        Console.ReadLine();

Veja aqui mais exemplos de como trabalhar planilha Excel com c#.

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .