Hi Aspose Support Team,
I’m encountering a file corruption issue when processing Excel workbooks with Aspose.Cells.
We have purchased your license
Issue Description:
After editing a large Excel file that contains many formulas and then removing a watermark using Aspose.Cells, the output file becomes corrupted.
When opening the resulting .xlsx in Microsoft Excel, I get the following message:
“We found a problem with some content in ‘’. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes.”
If I click “Yes,” Excel attempts to repair the file, but some data or formulas are lost after recovery.
Steps to Reproduce:
- Open a large Excel workbook with multiple formula-heavy worksheets.
- Modify data programmatically using Aspose.Cells.
- Remove an existing watermark.
- Save the file.
- Open the saved file in Excel — the above error appears.
Expected Behavior:
Excel should open the workbook normally, with all formulas and data preserved after watermark removal.
Actual Behavior:
Excel reports that the file contains invalid or missing content and attempts to repair it, resulting in data loss.
Environment Details:
- Aspose.Cells version: [e.g., 23.5.0]
- File format: XLSX
- Programming language: [C#.]
- Excel version: [Microsoft 365]
I’ve attached the screenshot of the Excel error message for reference.
Please let me know if you’d like me to share a sample file and code snippet to help reproduce the issue.
Thanks,
Rahul Ghevare
@rahulgheware
Hello Rahul,
I understand that you are facing file corruption issues after removing a watermark from a large Excel workbook using Aspose.Cells. This can occur for various reasons, particularly with complex files that contain numerous formulas.
Here are some troubleshooting steps to help you resolve this issue:
-
Update Aspose.Cells: Make sure you are using the latest version of Aspose.Cells. Newer releases often include bug fixes that may address your problem.
-
Review Watermark Removal Code: Double-check the code you are using to remove the watermark. Ensure it is implemented correctly. Here’s a basic example of how to remove a watermark:
Workbook workbook = new Workbook("input.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
// Assuming the watermark is a shape
for (int i = worksheet.Shapes.Count - 1; i >= 0; i--)
{
if (worksheet.Shapes[i].Name == "WatermarkName") // Replace with your watermark's name
{
worksheet.Shapes.RemoveAt(i);
}
}
workbook.Save("output.xlsx");
-
Specify Save Options: When saving the workbook, consider using explicit save options. For example, you can specify the SaveFormat:
workbook.Save("output.xlsx", SaveFormat.Xlsx);
-
Test with a Smaller File: If feasible, try to replicate the issue with a smaller Excel file. This can help determine if the problem is related to file size or complexity.
-
Inspect for Corrupt Elements: Certain elements within the workbook may cause corruption. Inspect the workbook for any unusual shapes or data that could be problematic.
-
Contact Support: If the issue persists, consider reaching out to Aspose support with a sample file and the code snippet you are using. They can provide more targeted assistance.
If you follow these steps and continue to encounter issues, please let me know, and we can explore further options.
Best regards!
@rahulgheware
We recommend you to kindly try using our latest version: Aspose.Cells for .NET 25.10.
If you still find the issue, kindly do share your complete sample (runnable) code and template Excel file (if any) to reproduce the issue on our end. If the file cannot be uploaded to the forum due to its large size. Please upload the file to the cloud and share the link here. We will check it soon.
File cloud path
e - copy - copy - copy - copy1.xlsx
and code shared below
sheet.BackgroundImage = null; // Remove the background image
//check for shapes
if (string.IsNullOrEmpty(m_strProperty) == false)
{
for (int j = 0; j < sheet.Shapes.Count; j++)
{
Aspose.Cells.Drawing.Shape shapeObj = sheet.Shapes[j];
if (shapeObj != null)
{
if (shapeObj.Name == m_strProperty)
{
//remove this shape from document
sheet.Shapes.Remove(shapeObj);
}
}
}
}
remove watermark image from header and footer if any addd for printing
try
{
//let;'s check if it GXKWATERMARK image is added
//Aspose.Cells.Drawing.Picture picObject = sheet.PageSetup.GetPicture(false, 1);
//if (picObject != null && picObject.Name == “GXKWATERMARK”)
{
//remove this image
sheet.PageSetup.SetFooterPicture(1, null); // Removes the image
sheet.PageSetup.SetFooter(1, string.Empty); // Clears the &G reference
}
}
catch (Exception)
{
}
@rahulgheware,
Thanks for the template Excel file.
Please try our latest version: Aspose.Cells for .NET v25.10.
I have tested your scenario/case using your template Excel file and following sample code. It works fine and the output Excel file is fine tuned. I do not get errors when opening the output Excel file into MS Excel manually.
Workbook workbook = new Workbook("e:\\test2\\e - copy - copy - copy - copy1.xlsx");
Worksheet sheet = workbook.Worksheets[0];
sheet.BackgroundImage = null; // Remove the background image
for (int j = 0; j < sheet.Shapes.Count; j++)
{
Aspose.Cells.Drawing.Shape shapeObj = sheet.Shapes[j];
if (shapeObj != null)
{
//remove this shape from document
sheet.Shapes.Remove(shapeObj);
}
}
//remove this image
sheet.PageSetup.SetFooterPicture(1, null); // Removes the image
sheet.PageSetup.SetFooter(1, string.Empty); // Clears the &G reference
workbook.Save("e:\\test2\\out1.xlsx");
If you still find the issue with Aspose.Cells for .NET v25.10, kindly do provide your complete sample (runnable) code with output Excel file and we will check your issue soon.