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
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ private string ParseToHeaderFooterFormat(ExcelHeaderFooterTextItem current, Exce
if (current.FontSize != prev.FontSize)
{
hfstring += "&" + current.FontSize;
if (char.IsDigit(current.Text[0]))
if (!string.IsNullOrEmpty(current.Text) && char.IsDigit(current.Text[0]))
{
hfstring += " ";
}
Expand All @@ -748,7 +748,7 @@ private string ParseToHeaderFooterFormat(ExcelHeaderFooterTextItem current, Exce
else if (current.FontSize != null && prev.FontSize == null)
{
hfstring += "&" + current.FontSize;
if (char.IsDigit(current.Text[0]))
if ( !string.IsNullOrEmpty(current.Text) && char.IsDigit(current.Text[0]))
{
hfstring += " ";
}
Expand Down
33 changes: 33 additions & 0 deletions src/EPPlusTest/Issues/LegacyTests/Issues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Date Author Change
using OfficeOpenXml.FormulaParsing.Logging;
using OfficeOpenXml.Sparkline;
using OfficeOpenXml.Style;
using OfficeOpenXml.Style.HeaderFooterTextFormat;
using OfficeOpenXml.Table;
using OfficeOpenXml.Table.PivotTable;
using OfficeOpenXml.Utils.CompundDocument;
Expand All @@ -58,6 +59,7 @@ Date Author Change
using System.Reflection;
using System.Text;
using System.Threading;
using static Microsoft.ApplicationInsights.MetricDimensionNames.TelemetryContext;

namespace EPPlusTest
{
Expand Down Expand Up @@ -6219,5 +6221,36 @@ public void SumIfsRangeCriteriaArray()
Assert.AreEqual(0d, ws.Cells["F6"].Value);
}
}

[TestMethod]
public void i2078()
{
using var p = new ExcelPackage();
var ws =p.Workbook.Worksheets.Add("Sheet 1");
//ws.HeaderFooter.OddHeader.LeftAlignedText = "&12&A";
ws.HeaderFooter.OddHeader.LeftAligned.Add(new()
{
FontSize = 12,
FormatCode = ExcelHeaderFooterFormattingCodes.SheetName,
Text = ""
});
p.SaveAs("c:\\epplustest\\testoutput\\HeaderFooterIssue2078.xlsx");
}

[TestMethod]
public void i2088()
{
using var p = new ExcelPackage();
var ws = p.Workbook.Worksheets.Add("Sheet 1");
var fh = ws.HeaderFooter.FirstHeader;
FileInfo pic = new FileInfo(Resources.GetImageFullFileName("epplusobject.png"));
var drawing = ws.HeaderFooter.FirstHeader.InsertPicture(pic, PictureAlignment.Left);
drawing.Height = 40;

ws.HeaderFooter.FirstHeader.CenteredText = "pageTitle";
ws.HeaderFooter.FirstFooter.LeftAlignedText = $"{ExcelHeaderFooter.CurrentDate} {ExcelHeaderFooter.CurrentTime}";
ws.HeaderFooter.FirstFooter.RightAlignedText = $"Printing: {"user.DisplayName"} - {ExcelHeaderFooter.PageNumber}/{ExcelHeaderFooter.NumberOfPages}";
p.SaveAs("c:\\epplustest\\testoutput\\HeaderFooterIssue2088.xlsx");
}
}
}