Remove Metadata from XLSX using Java

When handling XLSX files, removing metadata is often essential to safeguard sensitive information or to minimize file size. Metadata can encompass details such as the author’s name, comments, and document history. In this guide, we will walk you through the process of how to remove metadata from XLSX using Java. This will make sure your files are safe and tidy before you share or distribute them. Begin by setting up your development environment with the required tools. Make sure you have a Java development IDE, such as Eclipse, IntelliJ IDEA, or NetBeans, installed on your system. The following steps will outline how to effectively delete metadata from XLSX in Java.

Steps to Remove Metadata from XLSX using Java

  1. Configure your Integrated Development Environment (IDE) to utilize GroupDocs.Metadata for Java to handle metadata removal from XLSX files
  2. Create an instance of the Metadata class, supplying the path to the XLSX file as an argument in its constructor
  3. Eliminate the metadata properties by calling the Metadata.removeProperties method
  4. Save the updated XLSX file to your disk with the Metadata.save method

Removing metadata from your XLSX files provides several advantages. First, it safeguards sensitive information, like the author’s identity or document history, which might accidentally reveal private details. Second, it can reduce the file size, making it simpler to share, especially through email or online platforms. Lastly, it helps make the document look more polished and organized, eliminating any extraneous data that could cause confusion. By following the steps in this guide, you can effectively clear metadata properties in XLSX using Java. This process improves document security and clarity, giving you confidence when sharing your files.

Code to Remove Metadata from XLSX using Java

import com.groupdocs.metadata.Metadata;
import com.groupdocs.metadata.core.FileFormat;
import com.groupdocs.metadata.licensing.License;
import com.groupdocs.metadata.search.FallsIntoCategorySpecification;
import com.groupdocs.metadata.search.WithNameSpecification;
import com.groupdocs.metadata.tagging.Tags;
public class RemoveMetadatafromXLSXUsingJava {
public static void main(String[] args) {
// Set License to avoid the limitations of Metadata library
License license = new License();
license.setLicense("GroupDocs.Metadata.lic");
Metadata metadata = new Metadata("input.xlsx");
if (metadata.getFileFormat() != FileFormat.Unknown
&& !metadata.getDocumentInfo().isEncrypted()) {
System.out.println();
// Remove all mentions of any people contributed in file creation
// Remove a custom property with the specified name
int affected = metadata.removeProperties(new FallsIntoCategorySpecification(
Tags.getPerson()).or(new WithNameSpecification("CustomProperty")));
System.out.println(String.format("Affected properties: %s", affected));
metadata.save("output.xlsx");
}
}
}

To sum up, clear custom properties from XLSX using Java is a simple and efficient method. This approach not only boosts the security and confidentiality of your documents but also helps present them in a more polished and professional manner. With Java already set up on your system, you can easily carry out this task on Windows, macOS, or Linux without requiring any additional software. This setup allows for seamless execution across different operating systems, simplifying the process considerably. By installing the suggested library and configuring the file paths correctly, you can smoothly incorporate the provided code into your projects with ease.

In our previous discussion, we offered a detailed guide on removing metadata from RTF files using Java. For a deeper understanding, we recommend checking out our comprehensive tutorial on how to read metadata from RTF using Java.

 English