From 224624cc7d0e5ce93d6797df20a0fb1289948b83 Mon Sep 17 00:00:00 2001 From: swmal <{ID}+username}@users.noreply.github.com> Date: Mon, 27 Jul 2026 15:43:51 +0200 Subject: [PATCH] #2441 - Added DisableImageFunctionDownloads property to ExcelCalculationOption --- .../RpnOptimizedDependencyChain.cs | 1 + .../FormulaParsing/ExcelCalculationOption.cs | 7 +++++++ .../Functions/RefAndLookup/ImageFunctionTests.cs | 15 +++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/src/EPPlus/FormulaParsing/DependencyChain/RpnOptimizedDependencyChain.cs b/src/EPPlus/FormulaParsing/DependencyChain/RpnOptimizedDependencyChain.cs index 72678303a5..34f64b6ab3 100644 --- a/src/EPPlus/FormulaParsing/DependencyChain/RpnOptimizedDependencyChain.cs +++ b/src/EPPlus/FormulaParsing/DependencyChain/RpnOptimizedDependencyChain.cs @@ -44,6 +44,7 @@ public RpnOptimizedDependencyChain(ExcelWorkbook wb, ExcelCalculationOption opti config.CacheExpressions = options.CacheExpressions; config.PrecisionAndRoundingStrategy = options.PrecisionAndRoundingStrategy; config.AlwaysRefreshImageFunction = options.AlwaysRefreshImageFunction; + config.DisableImageFunctionDownloads = options.DisableImageFunctionDownloads; config.EnableUnicodeAwareStringOperations = options.EnableUnicodeAwareStringOperations; }); diff --git a/src/EPPlus/FormulaParsing/ExcelCalculationOption.cs b/src/EPPlus/FormulaParsing/ExcelCalculationOption.cs index 3e61ec6539..809de23ab4 100644 --- a/src/EPPlus/FormulaParsing/ExcelCalculationOption.cs +++ b/src/EPPlus/FormulaParsing/ExcelCalculationOption.cs @@ -116,6 +116,13 @@ public bool AlwaysRefreshImageFunction set; } = false; + /// + /// If true the IMAGE function will never download external content in formula calculation. + /// It will instead return the NAME error as if the function was not implemented. + /// NB! This property overrides the property if set to true. + /// + public bool DisableImageFunctionDownloads { get; set; } = false; + /// /// Enables Unicode-aware string operations, ensuring correct handling of surrogate pairs for comparisons, substrings, and sorting within the library. /// diff --git a/src/EPPlusTest/FormulaParsing/Excel/Functions/RefAndLookup/ImageFunctionTests.cs b/src/EPPlusTest/FormulaParsing/Excel/Functions/RefAndLookup/ImageFunctionTests.cs index a4d6608a54..720f13623f 100644 --- a/src/EPPlusTest/FormulaParsing/Excel/Functions/RefAndLookup/ImageFunctionTests.cs +++ b/src/EPPlusTest/FormulaParsing/Excel/Functions/RefAndLookup/ImageFunctionTests.cs @@ -148,5 +148,20 @@ public void ImageTest_ShouldReturnNameErrorWhenServiceIsNull() Assert.AreEqual(ExcelErrorValue.Create(eErrorType.Name), sheet.Cells["A1"].Value); } + + [TestMethod] + public void ImageTest_ShouldNotDownloadWhenDownloadsDisabled() + { + using var package = new ExcelPackage(); + var httpsService = new TestHttpsService(); + package.Settings.ImageFunctionService = httpsService; + var sheet = package.Workbook.Worksheets.Add("Sheet1"); + sheet.Cells["A1"].Formula = "IMAGE(\"https://epplussoftware.com/img/EPPlus-logo-full.png\", \"Alt text\", 1)"; + + sheet.Calculate(opt => opt.DisableImageFunctionDownloads = true); + + Assert.AreEqual(0, httpsService.NumberOfCalls, "the download service should not be called when downloads are disabled"); + Assert.AreEqual(ExcelErrorValue.Create(eErrorType.Name), sheet.Cells["A1"].Value); + } } }