Recover EXCEL file via C#
Build your own .NET application to repair excel files using .NET.
Repair EXCEL File Using .NET
In order to repair EXCEL file, we will use
API which is a feature-rich, powerful and easy to use document manipulation API for C# platform.
Aspose.Cells API can be used to create, edit, convert and render Microsoft Excel formats to different formats. Moreover, it can be used for comprehensive charting, scalable reporting and reliable calculations within software applications. Aspose.Cells is a standalone API and it does not require any software like Microsoft or OpenOffice.
using Aspose.Cells;
//1, Define a class that inherits Aspose.Cells.IWarningCallback
class DefaultWarningCallback : IWarningCallback
{
//Implement this method as needed
public void Warning(WarningInfo warningInfo){ }
}
//2, Load the corrupted file by creating an instance of Workbook, using the inheritance class above
DefaultWarningCallback w = new DefaultWarningCallback();
LoadOptions options = new LoadOptions();
options.WarningCallback = w;
var workbook = new Workbook("corrupted.xlsx", options);
//3, Save the workbook, the corrupted file will be repaired.
workbook.Save("repaired.xlsx");
How to repair excel file using C#
- Define a class that inherits Aspose.Cells.IWarningCallback.
- Load EXCEL file by creating an instance of Workbook, using the inheritance class above, refer to the code above.
- Save the workbook, the corrupted excel file will be repaired.
Install Aspose.Cells to repair excel file
There are three alternative options to install Aspose.Cells for .NET in your system.
- Open NuGet package manager, search for Aspose.Cells and install.
- Install Aspose.Cells with NuGet package manager in Visual Studio. See Documentation .
- Download Aspose.Cells.msi and install it on windows.
System Requirements
Aspose.Cells for .NET is supported on all major operating systems. Just make sure that you have the following prerequisites.
Aspose.Cells is fully cross-platform and supports all major .NET implementations following .NET Standard 2.0 specification:
- .NET Framework, starting from the earliest 2.0 version, and ending with the latest .NET Framework 4.8.
- .NET Core, starting from the earliest 2.0, and ending with the latest .NET 6.
As far as .NET code does not depend on the underlying hardware or operating system, but only on a Virtual Machine, you are free to develop any kind of software for Windows, Linux, macOS, Android and iOS. Azure and AWS Lambda is also supported. Just make sure you have installed the corresponding version of .NET Framework, .NET Core, Windows Azure, Mono or Xamarin.
We recommend using Microsoft Visual Studio, VSCode to create C#, F#, VB.NET applications.
EXCEL What is EXCEL File Format?
XLSX is well-known format for Microsoft Excel documents that was introduced by Microsoft with the release of Microsoft Office 2007. Based on structure organized according to the Open Packaging Conventions as outlined in Part 2 of the OOXML standard ECMA-376, the new format is a zip package that contains a number of XML files. The underlying structure and files can be examined by simply unzipping the .xlsx file.
Read MoreRepair Other Supported Excel Formats
Using C#, one can easily repair other Excel format files.