EPPlusSoftware / EPPlus

EPPlus-Excel spreadsheets for .NET
https://epplussoftware.com
Other
1.79k stars 273 forks source link

The `x:Anchor` field is not mandatory and must exist #1596

Open uganh opened 2 weeks ago

uganh commented 2 weeks ago

EPPlus usage

Noncommercial use

Environment

Windows

Epplus version

7.3.1

Spreadsheet application

Excel

Description

https://github.com/EPPlusSoftware/EPPlus/blob/5bb2d0dab7ce9445506e0980d3988fb0d8fb4b95/src/EPPlus/Drawing/Vml/ExcelVmlDrawingPosition.cs#L114

When calling ExcelWorksheet.DeleteRow on a xlsx file, an exception is thrown: Anchor element is invalid in vmlDrawing.

According to the specifications, the x:Anchor field is not mandatory, so exceptions should not be thrown here.

swmal commented 2 weeks ago

Please upload a workbook or provide code that helps us to replicate this issue.

uganh commented 1 week ago

Please upload a workbook or provide code that helps us to replicate this issue.

AudioConfig.xlsx

This is a sample file, and if you unzip it, you will find that the x:Anchor field is missing in xl/drawings/vmlDrawing1.vml. I can operate it through Microsoft Office.

But when I modified it using the following code, an unexpected exception was thrown.

using OfficeOpenXml;

ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

FileInfo fileInfo = new FileInfo(fileName);
ExcelPackage package = new ExcelPackage();

using (var stream = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
    package.Load(stream);
}

ExcelWorkbook workbook = package.Workbook;
ExcelWorksheet worksheet = workbook.Worksheets[1];

worksheet.DeleteRow(256);

I hope you can fix this issue in future versions. best wishes.

JanKallman commented 1 week ago

Thanks, I will have a look at it and get back to you here.

JanKallman commented 6 days ago

The commentsDrawing1.vml inside this workbook misses the the element x:ClientData/x:Anchor, that EPPlus currently requires. If you resave the workbook with Excel, it works as expected. I'll see if I can add fix so it works without this element as well.