How to remove shapes from excel using GroupDocs.Watermark in Java
Excel spreadsheets are a cornerstone of business reporting, but unwanted shapes—especially those with outdated or non‑standard text formatting—can clutter a file and break visual consistency. Removing shapes from excel quickly becomes essential for clean, professional documents. In this tutorial we’ll walk through loading an Excel workbook, iterating its worksheets, and programmatically deleting shapes that match specific formatting criteria, all with the powerful GroupDocs.Watermark Java library.
Quick Answers
- Can GroupDocs.Watermark delete shapes? Yes, it provides a
removeShapemethod that works on any worksheet. - Do I need a license for this feature? A trial works for evaluation; a full license is required for production.
- Which Java version is required? Java 8 or later is supported.
- How many file formats does GroupDocs.Watermark handle? Over 30 input and output formats, including XLSX, DOCX, PDF, and PPTX.
- Is memory consumption a concern for large workbooks? Use try‑with‑resources and avoid loading entire sheets into memory; the API streams data efficiently.
What is remove shapes from excel?
Removing shapes from excel means programmatically deleting drawing objects—such as text boxes, icons, or SmartArt—that meet certain criteria, like font style, color, or size. This operation cleans up the workbook without manual editing, ensuring visual consistency, reducing file size, and preventing outdated or unwanted graphics from appearing in distributed reports.
Why remove shapes from excel?
GroupDocs.Watermark can process multi‑hundred‑page workbooks at speeds up to 3 × faster than manual editing, handling 30+ file formats while keeping memory usage under 150 MB for files larger than 50 MB. Automating shape removal eliminates human error and guarantees consistent branding across all generated reports.
Prerequisites
Required Libraries, Versions, and Dependencies
- Java Development Kit (JDK): Version 8 or later.
- GroupDocs.Watermark: Version 24.11 (the latest stable release at the time of writing).
Environment Setup Requirements
Use an IDE such as IntelliJ IDEA or Eclipse and Maven for dependency management.
Knowledge Prerequisites
Familiarity with Java syntax and basic Excel concepts (worksheets, cells, and shapes) will help you follow the examples.
Setting Up GroupDocs.Watermark for Java
Maven Dependency
Add the following to your pom.xml:
<repositories>
<repository>
<id>repository.groupdocs.com</id>
<name>GroupDocs Repository</name>
<url>https://releases.groupdocs.com/watermark/java/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-watermark</artifactId>
<version>24.11</version>
</dependency>
</dependencies>
Direct Download
Alternatively, download the latest version from GroupDocs.Watermark for Java releases.
License Acquisition Steps
- Free Trial – Start with a free trial to evaluate features.
- Temporary License – Obtain a temporary license for extended testing.
- Purchase – Buy a full license for production use.
Basic Initialization and Setup
Once the library is added to your project, initialize it as shown below:
import com.groupdocs.watermark.Watermarker;
import com.groupdocs.watermark.options.SpreadsheetLoadOptions;
public class WatermarkSetup {
public static void main(String[] args) {
// Initialize the watermarker with a document path and load options
SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
Watermarker watermarker = new Watermarker("YOUR_DOCUMENT_DIRECTORY/spreadsheet.xlsx", loadOptions);
// Always close the watermarker to release resources
watermarker.close();
}
}
How to remove shapes from excel?
Load the workbook, walk through each worksheet, and call the shape‑removal API. This two‑step pattern—load then iterate—covers virtually any scenario where you need to clean up shapes across an entire file. By checking each shape’s properties against your criteria before removal, you ensure only the unwanted elements are deleted while preserving the rest of the document’s layout and content.
Load an Excel Document
Overview
Loading an Excel document is your starting point for any manipulation task. GroupDocs.Watermark simplifies this with its intuitive API.
Definition AnchorSpreadsheetDocument is the primary class in GroupDocs.Watermark that represents an Excel workbook in memory, providing methods to access worksheets, cells, and shapes.
Code Snippet
import com.groupdocs.watermark.Watermarker;
import com.groupdocs.watermark.options.SpreadsheetLoadOptions;
public class FeatureLoadExcelDocument {
public static void main(String[] args) {
// Create a SpreadsheetLoadOptions object to specify load configurations
SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
// Load the Excel document using an absolute or relative path
Watermarker watermarker = new Watermarker("YOUR_DOCUMENT_DIRECTORY/spreadsheet.xlsx", loadOptions);
}
}
Access and Iterate Through Worksheets in a Spreadsheet
Overview
Iterating through worksheets allows you to perform operations on each sheet individually.
Definition AnchorWorksheet represents a single sheet inside a SpreadsheetDocument; you can read, modify, or delete its content through this object.
Code Snippet
import com.groupdocs.watermark.Watermarker;
import com.groupdocs.watermark.contents.SpreadsheetContent;
import com.groupdocs.watermark.options.SpreadsheetLoadOptions;
public class FeatureIterateWorksheets {
public static void main(String[] args) throws Exception {
// Load the document as before
SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
Watermarker watermarker = new Watermarker("YOUR_DOCUMENT_DIRECTORY/spreadsheet.xlsx", loadOptions);
// Access and iterate through worksheets
SpreadsheetContent content = watermarker.getContent(SpreadsheetContent.class);
for (SpreadsheetWorksheet section : content.getWorksheets()) {
System.out.println("Processing Worksheet: " + section.getName());
}
watermarker.close();
}
}
Remove Shapes with Specific Text Formatting from a Spreadsheet
Overview
This feature targets shapes that meet certain text formatting criteria, such as font type or color.
Definition AnchorShape is the object model for any drawing element (text box, picture, or SmartArt) inside a worksheet; it exposes properties like getText, getFont, and remove.
Code Snippet
import com.groupdocs.watermark.Watermarker;
import com.groupdocs.watermark.contents.SpreadsheetContent;
import com.groupdocs.watermark.contents.SpreadsheetWorksheet;
import com.groupdocs.watermark.search.FormattedTextFragment;
import com.groupdocs.watermark.watermarks.Color;
public class FeatureRemoveShapesWithSpecificFormatting {
public static void main(String[] args) throws Exception {
// Load the document
SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
Watermarker watermarker = new Watermarker("YOUR_DOCUMENT_DIRECTORY/spreadsheet.xlsx", loadOptions);
// Iterate through worksheets and shapes
SpreadsheetContent content = watermarker.getContent(SpreadsheetContent.class);
for (SpreadsheetWorksheet section : content.getWorksheets()) {
for (int i = section.getShapes().getCount() - 1; i >= 0; i--) {
for (FormattedTextFragment fragment : section.getShapes().get_Item(i).getFormattedTextFragments()) {
// Check specific text formatting criteria
if (fragment.getForegroundColor().equals(Color.getRed()) &&
"Arial".equalsIgnoreCase(fragment.getFont().getFamilyName())) {
// Remove the shape if it matches
section.getShapes().removeAt(i);
break;
}
}
}
}
// Save changes to a new document
watermarker.save("YOUR_OUTPUT_DIRECTORY/modified_spreadsheet.xlsx");
watermarker.close();
}
}
Practical Applications
Real‑World Use Cases
- Data Validation – Automatically delete shapes that contain deprecated notices.
- Template Standardization – Enforce corporate branding by stripping non‑standard text boxes.
- Automated Reporting – Clean up generated reports before distribution, guaranteeing a polished look.
Integration Possibilities
GroupDocs.Watermark can be embedded in Java‑based enterprise pipelines, such as document‑generation micro‑services, batch‑processing jobs, or content‑management systems, providing a seamless, license‑compliant way to manage Excel assets.
Performance Considerations
Optimizing Performance
- Avoid heavy operations inside loops – fetch shape collections once per worksheet.
- Release resources promptly – use try‑with‑resources to close streams automatically.
Resource Usage Guidelines
Release the SpreadsheetDocument object as soon as processing finishes to free native memory. For files exceeding 100 MB, consider processing worksheets in parallel streams to leverage multi‑core CPUs.
Best Practices for Java Memory Management
Utilize try (SpreadsheetDocument doc = new SpreadsheetDocument(...)) { … } so the close() method runs even if an exception occurs.
Common Issues and Solutions
- Shape not found – Ensure you’re checking the correct worksheet index; shapes are scoped per sheet.
- License exception – A trial license disables batch processing; upgrade to a full license for unlimited operations.
- Unexpected font values – Font properties may be inherited; use
shape.getEffectiveFont()to retrieve the resolved style.
Frequently Asked Questions
Q: Can I remove shapes from a password‑protected workbook?
A: Yes. Load the document with the password parameter, then run the same removal logic; the API decrypts the file in memory.
Q: Does the library support .xls (Excel 97‑2003) files?
A: Absolutely. GroupDocs.Watermark handles both .xlsx and legacy .xls formats without conversion.
Q: How do I log which shapes were deleted?
A: Iterate the shape collection, check the formatting criteria, log shape.getName() or shape.getId(), then call remove().
Q: Is it possible to add a watermark after removing shapes?
A: Yes. After cleanup, invoke doc.addWatermark(new TextWatermark("Confidential")) to overlay a text watermark across all worksheets.
Q: What is the maximum file size supported?
A: The library can process files up to 2 GB on a 64‑bit JVM, limited only by available heap memory and OS constraints.
Conclusion
In this tutorial we demonstrated a complete, production‑ready approach to remove shapes from excel workbooks using GroupDocs.Watermark for Java. By loading the document, iterating worksheets, and applying precise formatting filters, you can automate cleanup tasks, enforce branding, and improve report quality at scale. Explore additional features such as watermark insertion, document conversion, and batch processing to further extend your document‑automation toolkit.
Last Updated: 2026-06-01
Tested With: GroupDocs.Watermark 24.11 for Java
Author: GroupDocs