Skip to content

Commit

Permalink
Merge pull request #1097 from EPPlusSoftware/bug/issue1096
Browse files Browse the repository at this point in the history
Bug/issue1096
  • Loading branch information
OssianEPPlus authored Oct 11, 2023
2 parents 656d197 + 37dfb30 commit ff89383
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/EPPlus/ExcelStyles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,25 +449,41 @@ private void SetStyleFullRow(StyleBase sender, StyleChangeEventArgs e, ExcelAddr
//iterate all columns and set the row to the style of the last column
var cse = new CellStoreEnumerator<ExcelValue>(ws._values, 0, 1, 0, ExcelPackage.MaxColumns);
var cs = 0;
int prevCol = 0;
bool hasFullColCoverage = true;
while (cse.Next())
{
if(prevCol != cse.Column-1)
{
hasFullColCoverage = false;
}
cs = cse.Value._styleId;
if (cs == 0) continue;
var c = ws.GetValueInner(cse.Row, cse.Column) as ExcelColumn;
if (c != null && c.ColumnMax < ExcelPackage.MaxColumns)
if (c != null)
{
for (int col = c.ColumnMin; col < c.ColumnMax; col++)
if(c.ColumnMax < ExcelPackage.MaxColumns || hasFullColCoverage==false)
{
if (!ws.ExistsStyleInner(rowNum, col))
for (int col = c.ColumnMin; col < c.ColumnMax; col++)
{
ws.SetStyleInner(rowNum, col, cs);
if (!ws.ExistsStyleInner(rowNum, col))
{
ws.SetStyleInner(rowNum, col, cs);
}
}
}
else
{
cs = c.StyleID;
break;
}
}
prevCol = c.ColumnMax;
}
ws.SetStyleInner(rowNum, 0, cs);
cse.Dispose();
}

if (styleCashe.ContainsKey(s))
{
ws.SetStyleInner(rowNum, 0, styleCashe[s]);
Expand Down
85 changes: 85 additions & 0 deletions src/EPPlusTest/Issues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5313,5 +5313,90 @@ public void s532()

}
}
[TestMethod]
public void Issue1096()
{
using (var package = OpenPackage("I1096.xlsx", true))
{
var workbook = package.Workbook;

var wss = workbook.Worksheets.Add("test");

var cells = new List<ExcelRange>()
{
wss.Cells[1, 1],
wss.Cells[2, 1],
wss.Cells[3, 1],
};

wss.Cells.Style.Font.Name = "Tahoma";
wss.Cells.Style.Font.Size = 10;

cells.ForEach(x =>
{
x.Value = "test";
});

cells = new List<ExcelRange>()
{
wss.Cells[1, 2],
wss.Cells[2, 2],
wss.Cells[3, 2],
};

cells.ForEach(x =>
{
x.Value = "test";
//x.Style.Font.Size = 10;
});

wss.Column(2).Style.Font.Name = "Wingdings";

cells = new List<ExcelRange>()
{
wss.Cells[1, 3],
wss.Cells[2, 3],
wss.Cells[3, 3],
wss.Cells[1, 4],
wss.Cells[2, 4],
wss.Cells[3, 4],
wss.Cells[1, 5],
wss.Cells[2, 5],
wss.Cells[3, 5],
};

cells.ForEach(x =>
{
x.Value = "hola";
//x.Style.Font.Name = "Wingdings";
//x.Style.Font.Size = 10;
});

void DebugGetFontInfo()
{
for (var row = 1; row <= 3; row++)
{
for (var column = 1; column <= 5; column++)
{
var range = wss.Cells[row, column];
Debug.Write(range.Style.Font.Name + range.Style.Font.Size + ",");
}
Debug.WriteLine("");
}
}


Debug.WriteLine("before:");
DebugGetFontInfo();

var r = wss.Rows[2];
r.Style.Fill.PatternType = ExcelFillStyle.Solid;
r.Style.Fill.BackgroundColor.SetColor(Color.Pink);

Debug.WriteLine("after:");
DebugGetFontInfo();
SaveAndCleanup(package);
}
}
}
}

0 comments on commit ff89383

Please sign in to comment.