Edit Excel spreadsheet with C# in Microsoft Azure

Asked

Viewed 358 times

0

I have a web application that reads an excel spreadsheet and imports the cell values into the database automatically. I am using COM, so it is necessary on the machine Microsoft Excel installed. When I compile locally works smoothly. However, I have recently hosted Excel and the error is due to not having Excel installed. How can I get around this error? I don’t understand much of Azure, so I wanted to know a way to install Microsoft Office Excel.

ERROR THAT APPEARS:

Retrieving the COM class Factory for Component with CLSID {00024500-0000-C000-00000046} 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 answer

0

Just to summarize: Azure App Services Webapp is a Platform as a Service. This means that the full responsibility for maintaining the infrastructure lies with Microsoft and not with the developer. But in order to be able to take on this role, they have to cast a lot of the hosting environment, and only open up really relevant points for the developer - and installing software on their servers is totally out of the question.

There is an option that I highly recommend to work with Excel from systems . NET: Spreadsheet Light.

Although it is a library with procedural methods - it is not object-oriented, it is very intuitive and even elegant to work with. See some examples:

Read and modify data from a spreadsheet

// 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();

See here more examples of how to work Excel spreadsheet with c#.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.