Recover excel file via Java
Build Java application to repair excel files using Java.
Repair EXCEL File Using Java
In order to repair EXCEL file, we will use Aspose.Cells for Java API which is a feature-rich, powerful and easy to use document manipulation API for Java 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.
import com.aspose.cells.Workbook;
import com.aspose.cells.WarningInfo;
import com.aspose.cells.LoadOptions;
//1, Define a class that inherits Aspose.Cells.IWarningCallback
public class DefaultWarningCallback implements com.aspose.cells.IWarningCallback {
@Override
public void warning(WarningInfo arg0) {
//Implement this method as needed
}
}
//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.setWarningCallback(w);
var workbook = new Workbook("input.xlsx", options);
//3, Save the workbook, the corrupted file will be repaired.
workbook.save("Output.xlsx");
How to repair excel file using Java
- 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
You can download its latest version directly from
and install it within your Maven-based project by adding the following configurations to the pom.xml.
Repository
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
Dependency
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-cells</artifactId>
<version>version of aspose-cells API</version>
<classifier>jdk17</classifier>
</dependency>
System Requirements
Aspose.Cells for Java is supported on all major operating systems. Just make sure that you have the following prerequisites.
- Microsoft Windows or a compatible OS with Java Runtime Environment for JSP/JSF Application and Desktop Applications.
- Get latest version of Aspose.Cells for Java directly from Maven.
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 Java, one can easily repair other Excel format files.