Skip to content

Commit d2f9f10

Browse files
committed
Better solution using existing data-structures
1 parent a4b1660 commit d2f9f10

4 files changed

Lines changed: 11 additions & 12 deletions

File tree

src/EPPlus/Export/HtmlExport/Enums/ePictureInclude.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,9 @@ public enum ePictureInclude
3030
/// Include the images in the html export.
3131
/// </summary>
3232
Include,
33+
/// <summary>
34+
/// Include the images only in the HTML.
35+
/// </summary>
36+
IncludeInHtmlOnly
3337
}
3438
}

src/EPPlus/Export/HtmlExport/Exporters/Internal/HtmlExporterBaseInternal.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ protected HTMLElement GetThead(ExcelRangeBase range, List<string> headers = null
148148

149149
AddTableData(table, contentElement, col);
150150

151-
if (Settings.Pictures.Include == ePictureInclude.Include)
151+
if (Settings.Pictures.Include == (ePictureInclude.Include | ePictureInclude.IncludeInHtmlOnly))
152152
{
153153
image = GetImage(cell.Worksheet.PositionId, cell._fromRow, cell._fromCol);
154154
}
@@ -269,7 +269,7 @@ protected HTMLElement GetTableBody(ExcelRangeBase range, int row, int endRow)
269269

270270
SetColRowSpan(range, tblData, cell);
271271

272-
if (Settings.Pictures.Include == ePictureInclude.Include)
272+
if (Settings.Pictures.Include == (ePictureInclude.Include | ePictureInclude.IncludeInHtmlOnly))
273273
{
274274
image = GetImage(cell.Worksheet.PositionId, cell._fromRow, cell._fromCol);
275275
}
@@ -414,7 +414,7 @@ protected void AddImage(HTMLElement parent, HtmlExportSettings settings, HtmlIma
414414
child.AddAttribute("id", imageName);
415415
}
416416

417-
if(settings.Pictures.EmbedImagesInHtml)
417+
if(settings.Pictures.Include == ePictureInclude.IncludeInHtmlOnly)
418418
{
419419
ePictureType? type;
420420
var _encodedImage = ImageEncoder.EncodeImage(image, out type);

src/EPPlus/Export/HtmlExport/Settings/HtmlPictureSettings.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ internal HtmlPictureSettings()
2323

2424
}
2525

26-
public bool EmbedImagesInHtml = false;
27-
2826
/// <summary>
2927
/// If picture drawings should be included in the html. Default is <see cref="ePictureInclude.Exclude"/>
3028
/// </summary>

src/EPPlusTest/Export/HtmlExport/RangeExporterTests.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public async Task WriteImagesAsync()
197197
}
198198

199199
[TestMethod]
200-
public async Task WriteImagesAsyncBoolEmbed()
200+
public async Task WriteImagesAsyncHTMLOnlyEmbed()
201201
{
202202
using (var p = OpenTemplatePackage("20-CreateAFileSystemReport.xlsx"))
203203
{
@@ -206,16 +206,13 @@ public async Task WriteImagesAsyncBoolEmbed()
206206

207207
exporter.Settings.SetColumnWidth = true;
208208
exporter.Settings.SetRowHeight = true;
209-
exporter.Settings.Pictures.Include = ePictureInclude.Include;
209+
exporter.Settings.Pictures.Include = ePictureInclude.IncludeInHtmlOnly;
210210
exporter.Settings.Minify = false;
211211
exporter.Settings.Encoding = Encoding.UTF8;
212-
exporter.Settings.Pictures.EmbedImagesInHtml = true;
213212

214-
var html = exporter.GetSinglePage();
213+
var html = exporter.GetHtmlString();
215214
var htmlAsync = await exporter.GetSinglePageAsync();
216-
File.WriteAllText("c:\\temp\\" + sheet.Name + ".html", html);
217-
File.WriteAllText("c:\\temp\\" + sheet.Name + "-async.html", htmlAsync);
218-
Assert.AreEqual(html, htmlAsync);
215+
File.WriteAllText("c:\\temp\\" + sheet.Name + "_htmlOnly.html", html);
219216
}
220217
}
221218

0 commit comments

Comments
 (0)