Skip to content

Commit

Permalink
Bug/i888 place holder element detection (#889)
Browse files Browse the repository at this point in the history
* Improve placeholder detection

* Fixed check

* Added test for none type read

* Changed more appropriate test name
  • Loading branch information
OssianEPPlus committed Jun 7, 2023
1 parent 035626f commit 46417b2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/EPPlus/ExcelXMLWriter/ExtLstHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ private void ParseIntialXmlToList(string xml)
int start = 0, end = 0;
GetBlock.Pos(xml, "extLst", ref start, ref end);

bool isPlaceHolder = false;

if(!xml.Substring(start + 1, end - start - 1).Contains("<"))
{
isPlaceHolder = true;
}

//If the node isn't just a placeholder
if (end - start > 10)
if (!isPlaceHolder)
{
int contentStart = start + "<ExtLst>".Length;
string extNodesOnly = xml.Substring(contentStart, end - contentStart - "</ExtLst>".Length);
Expand Down
13 changes: 13 additions & 0 deletions src/EPPlusTest/DataValidation/DataValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ public void DataValidations_ShouldNotThrowIfOperatorIsEqualAndFormula1IsEmpty()
}


[TestMethod]
public void DataValidation_CanReadNoneValidation()
{
var pck = OpenTemplatePackage("i888.xlsx");

var validation = pck.Workbook.Worksheets[0].DataValidations[0];

Assert.IsNotNull(validation);
Assert.AreEqual("A1", validation.Address.ToString());
Assert.AreEqual("test", validation.PromptTitle);
Assert.AreEqual("message", validation.Prompt);
}

[TestMethod]
public void DataValidations_ShouldWriteReadAllValidOperatorsOnAllTypes()
{
Expand Down
24 changes: 24 additions & 0 deletions src/EPPlusTest/Issues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Date Author Change
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using OfficeOpenXml;
using OfficeOpenXml.ConditionalFormatting;
using OfficeOpenXml.DataValidation;
using OfficeOpenXml.Drawing;
using OfficeOpenXml.Drawing.Chart;
using OfficeOpenXml.Drawing.Chart.Style;
Expand Down Expand Up @@ -4859,6 +4861,28 @@ public void i871()
SaveAndCleanup(p);
}
}


[TestMethod]
public void Issue888()
{
using (var package = OpenPackage("issue888.xlsx", true))
{
var ws1 = package.Workbook.Worksheets.Add("ws1");

ws1.DataValidations.AddAnyValidation("A1");

SaveAndCleanup(package);

var readPackage = OpenPackage("issue888.xlsx");

var sheet = readPackage.Workbook.Worksheets[0];
var formatting = sheet.DataValidations[0];

Assert.AreEqual(eDataValidationType.Any, formatting.ValidationType.Type);
}
}

[TestMethod]
public void s466()
{
Expand Down

0 comments on commit 46417b2

Please sign in to comment.