Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/EPPlus/OfficeProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,14 @@ public string AppVersion
get { return _extendedHelper.GetXmlNodeString(AppVersionPath); }
set
{
if (value == null)
{
if(_extendedHelper.TopNode != null)
{
_extendedHelper.DeleteNode(AppVersionPath);
}
return;
}
var versions = value.Split('.');
if(versions.Length!=2 || versions.Any(x=>!x.IsInt()))
{
Expand Down
15 changes: 15 additions & 0 deletions src/EPPlusTest/OfficePropertiesTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OfficeOpenXml;
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateAndTime;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -58,5 +59,19 @@ public void ValidateCaseInsensitiveCustomProperties_Loading()
p.Dispose();
p2.Dispose();
}

[TestMethod]
public void AppVersion_SetToNull_RemovesNodeWithoutThrowing()
{
using var package = new ExcelPackage();
var props = package.Workbook.Properties;
var s = package.Workbook.Worksheets.Add("TestSheet");
s.Cells["A1"].Value = "Hej";
props.AppVersion = "16.0300";
Assert.AreEqual("16.0300", props.AppVersion);

props.AppVersion = null;
Assert.IsTrue(string.IsNullOrEmpty(props.AppVersion));
}
}
}
Loading