Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand Down
7 changes: 7 additions & 0 deletions src/EPPlus/FormulaParsing/ExcelCalculationOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ public bool AlwaysRefreshImageFunction
set;
} = false;

/// <summary>
/// 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 <see cref="AlwaysRefreshImageFunction"/> property if set to true.
/// </summary>
public bool DisableImageFunctionDownloads { get; set; } = false;

/// <summary>
/// Enables Unicode-aware string operations, ensuring correct handling of surrogate pairs for comparisons, substrings, and sorting within the library.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Loading