From 3fe6f77d248db9b945e3111ce6ecaab5d1a039ec Mon Sep 17 00:00:00 2001 From: KarlKallman Date: Mon, 29 Jun 2026 10:35:40 +0200 Subject: [PATCH] Allow AppVersion in OfficeProperties to be set to null. #2393. --- src/EPPlus/OfficeProperties.cs | 8 ++++++++ src/EPPlusTest/OfficePropertiesTests.cs | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/EPPlus/OfficeProperties.cs b/src/EPPlus/OfficeProperties.cs index 210483766f..39c01c4596 100644 --- a/src/EPPlus/OfficeProperties.cs +++ b/src/EPPlus/OfficeProperties.cs @@ -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())) { diff --git a/src/EPPlusTest/OfficePropertiesTests.cs b/src/EPPlusTest/OfficePropertiesTests.cs index 2ac4cc6657..17bf6342f8 100644 --- a/src/EPPlusTest/OfficePropertiesTests.cs +++ b/src/EPPlusTest/OfficePropertiesTests.cs @@ -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; @@ -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)); + } } }