Skip to content

Commit ed8d731

Browse files
committed
EPPlus 5.6.1
1 parent d442d37 commit ed8d731

File tree

7 files changed

+79
-22
lines changed

7 files changed

+79
-22
lines changed

appveyor.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
version: 5.6.0.{build}
1+
version: 5.6.1.{build}
22
branches:
33
only:
44
- develop
55
configuration: release
66
platform: Any CPU
77
init:
88
- ps: >-
9-
Update-AppveyorBuild -Version "5.6.0.$env:appveyor_build_number-$(Get-Date -format yyyyMMdd)-$env:appveyor_repo_branch"
9+
Update-AppveyorBuild -Version "5.6.1.$env:appveyor_build_number-$(Get-Date -format yyyyMMdd)-$env:appveyor_repo_branch"
1010
11-
Write-Host "5.6.0.$env:appveyor_build_number-$(Get-Date -format yyyyMMdd)-$env:appveyor_repo_branch"
11+
Write-Host "5.6.1.$env:appveyor_build_number-$(Get-Date -format yyyyMMdd)-$env:appveyor_repo_branch"
1212
dotnet_csproj:
1313
patch: true
1414
file: '**\*.csproj'
1515
version: '{version}'
16-
assembly_version: 5.6.0.{build}
17-
file_version: 5.6.0.{build}
16+
assembly_version: 5.6.1.{build}
17+
file_version: 5.6.1.{build}
1818
nuget:
1919
project_feed: true
2020
before_build:

docs/articles/fixedissues.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Features / Fixed issues - EPPlus 5
22

3+
## Version 5.6.1
4+
### Fixed issues & minor features
5+
* Styles xml could get corrupt in some cases as the numFmt dxf element was created in the wrong order according to the schema.
6+
* Merged cells could get index out of range if deleting a merged area.
7+
* LoadFromCollection will now set the cell's Hyperlink property for class members of type Uri or ExcelHyperlink.
8+
* EPPlus will now preserve the 'aca' and 'ca' attributes for array formulas.
9+
* ExcelRange.Formula and ExcelRange.FormulaR1C1 didn't return a value for array formulas except for the first cell in the range.
10+
* Defined names containing #REF! throw an exception when copying a worksheet.
11+
* Worksheet.FirstSheet property was set to the first sheet visible, if worksheet with position 0 was hidden.
12+
313
## Version 5.6.0
414
### Features
515
* Custom table styles.

src/EPPlus/Core/Worksheet/WorksheetCopyHelper.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ private static void CloneCellsAndStyles(ExcelWorksheet Copy, ExcelWorksheet adde
145145
}
146146

147147
Dictionary<int, int> styleCashe = new Dictionary<int, int>();
148+
bool hasMetadata = Copy._metadataStore.HasValues;
148149
//Cells
149150
int row, col;
150151
var val = new CellStoreEnumerator<ExcelValue>(Copy._values);
@@ -176,7 +177,7 @@ private static void CloneCellsAndStyles(ExcelWorksheet Copy, ExcelWorksheet adde
176177
}
177178
else
178179
{
179-
styleID = CopyValues(Copy, added, row, col);
180+
styleID = CopyValues(Copy, added, row, col, hasMetadata);
180181
}
181182
if (!sameWorkbook)
182183
{
@@ -675,7 +676,7 @@ private static void AppendDxf(ExcelStyles stylesFrom, ExcelStyles stylesTo, Dict
675676
}
676677
}
677678

678-
private static int CopyValues(ExcelWorksheet Copy, ExcelWorksheet added, int row, int col)
679+
private static int CopyValues(ExcelWorksheet Copy, ExcelWorksheet added, int row, int col, bool hasMetadata)
679680
{
680681
var valueCore = Copy.GetCoreValueInner(row, col);
681682
added.SetValueStyleIdInner(row, col, valueCore._value, valueCore._styleId);
@@ -685,10 +686,13 @@ private static int CopyValues(ExcelWorksheet Copy, ExcelWorksheet added, int row
685686
{
686687
added._flags.SetValue(row, col, fl);
687688
}
688-
ExcelWorksheet.MetaDataReference md = new ExcelWorksheet.MetaDataReference();
689-
if (Copy._metadataStore.Exists(row, col, ref md))
689+
if (hasMetadata)
690690
{
691-
added._metadataStore.SetValue(row, col, md);
691+
ExcelWorksheet.MetaDataReference md = new ExcelWorksheet.MetaDataReference();
692+
if (Copy._metadataStore.Exists(row, col, ref md))
693+
{
694+
added._metadataStore.SetValue(row, col, md);
695+
}
692696
}
693697

694698
var v = Copy._formulas.GetValue(row, col);

src/EPPlus/EPPlus.csproj

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>net5.0;netstandard2.1;netstandard2.0;net45;net40;net35</TargetFrameworks>
5-
<AssemblyVersion>5.6.0.0</AssemblyVersion>
6-
<FileVersion>5.6.0.0</FileVersion>
7-
<Version>5.6.0</Version>
5+
<AssemblyVersion>5.6.1.0</AssemblyVersion>
6+
<FileVersion>5.6.1.0</FileVersion>
7+
<Version>5.6.1</Version>
88
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
99
<PackageProjectUrl>https://epplussoftware.com</PackageProjectUrl>
1010
<Authors>EPPlus Software AB</Authors>
@@ -18,13 +18,16 @@
1818
<PackageTags>Excel ooxml</PackageTags>
1919
<Copyright>EPPlus Software AB</Copyright>
2020
<PackageReleaseNotes>
21-
EPPlus 5.6.0
21+
EPPlus 5.6.1
2222
IMPORTAT NOTICE!
2323
From version 5 EPPlus changes the licence model using a dual license, Polyform Non Commercial / Commercial license.
2424
EPPlus will still have the source available, but for non Polyform NC compliant projects, EPPlus will provide a commercial license.
2525
Commercial licenses can be purchased from https://epplussoftware.com
2626
This applies to EPPlus version 5 and later. Previous versions are still licensed LGPL.
2727

28+
## Version 5.6.1
29+
* Bug fixes. https://epplussoftware.com/Developers/MinorFeaturesAndIssues
30+
2831
## Version 5.6.0
2932
* Custom table styles.
3033
* Create and modify custom table styles that can be applied to tables and pivot tables.
@@ -35,7 +38,7 @@
3538
* HeaderRowStyle
3639
* DataStyle
3740
* TotalsRowStyle
38-
* Bug fixes. https://epplussoftware.com/Developers/MinorFeaturesAndIssues
41+
* Bug fixes.
3942

4043
## Version 5.5.5
4144
* Bug fixes.
@@ -151,9 +154,10 @@
151154
A list of fixed issues can be found here https://epplussoftware.com/docs/5.6/articles/fixedissues.html
152155

153156
Version history
157+
5.6.1 20210322 Minor bug fixes. See https://epplussoftware.com/Developers/MinorFeaturesAndIssues
154158
5.6.0 20210315 Custom table styles. Pivot table styling. Table styling enhancements.
155-
5.5.5 20210223 Minor bug fixes. See https://epplussoftware.com/Developers/MinorFeaturesAndIssues
156-
5.5.4 20210216 Minor bug fixes.
159+
5.5.5 20210223 Minor bug fixes.
160+
5.5.4 20210216 Minor bug fixes.
157161
5.5.3 20210206 Minor bug fixes.
158162
5.5.2 20210118 Minor bug fixes.
159163
5.5.1 20210111 Minor features and bug fixes.

src/EPPlus/ExcelWorkbook.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,11 @@ internal void Save() // Workbook Save
10911091
{
10921092
if(Worksheets[_package._worksheetAdd].Hidden!=eWorkSheetHidden.Visible)
10931093
{
1094-
View.FirstSheet = Worksheets.GetFirstVisibleSheetIndex();
1094+
var ix = Worksheets.GetFirstVisibleSheetIndex();
1095+
if (ix > View.FirstSheet)
1096+
{
1097+
View.FirstSheet = ix;
1098+
}
10951099
}
10961100
_package.SavePart(WorkbookUri, _workbookXml);
10971101
}

src/EPPlus/ExcelWorksheet.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ internal struct MetaDataReference
157157
{
158158
internal int cm;
159159
internal int vm;
160+
internal bool aca;
161+
internal bool ca;
160162
}
161163
/// <summary>
162164
/// Removes all formulas within the entire worksheet, but keeps the calculated values.
@@ -1605,12 +1607,27 @@ private void LoadCells(XmlReader xr)
16051607
else if (t == "array") //TODO: Array functions are not support yet. Read the formula for the start cell only.
16061608
{
16071609
string refAddress = xr.GetAttribute("ref");
1610+
var aca = xr.GetAttribute("aca");
1611+
var ca = xr.GetAttribute("ca");
16081612
string formula = xr.ReadElementContentAsString();
16091613
var afIndex = GetMaxShareFunctionIndex(true);
1610-
if(!string.IsNullOrEmpty(refAddress))
1614+
if (!string.IsNullOrEmpty(refAddress))
16111615
{
16121616
WriteArrayFormulaRange(refAddress, afIndex);
16131617
}
1618+
//Meta data and formula settings. Meta data is only preserved by EPPlus at this point
1619+
if (aca != null || ca != null)
1620+
{
1621+
var md = _metadataStore.GetValue(row, col);
1622+
md.aca = aca == "1";
1623+
md.ca = ca == "1";
1624+
_metadataStore.SetValue(
1625+
row,
1626+
col,
1627+
md);
1628+
};
1629+
1630+
16141631
_sharedFormulas.Add(afIndex, new Formulas(SourceCodeTokenizer.Default) { Index = afIndex, Formula = formula, Address = refAddress, StartRow = address._fromRow, StartCol = address._fromCol, IsArray = true });
16151632
}
16161633
else if (t=="dataTable") //Unsupported
@@ -3072,15 +3089,33 @@ private void UpdateRowCellData(StreamWriter sw, string prefix)
30723089
}
30733090
else
30743091
{
3092+
//Set calc attributes for array formula. We preserve them from load only at this point.
3093+
var mdAttrForFTag = "";
3094+
if (hasMd)
3095+
{
3096+
if (_metadataStore.Exists(cse.Row, cse.Column))
3097+
{
3098+
MetaDataReference md = _metadataStore.GetValue(cse.Row, cse.Column);
3099+
if (md.aca)
3100+
{
3101+
mdAttrForFTag = $" aca=\"1\"";
3102+
}
3103+
if (md.ca)
3104+
{
3105+
mdAttrForFTag += $" ca=\"1\"";
3106+
}
3107+
}
3108+
}
3109+
30753110
// We can also have a single cell array formula
30763111
if (f.IsArray)
30773112
{
3078-
cache.Append($"<{cTag} r=\"{cse.CellAddress}\" s=\"{styleID}\"{GetCellType(v, true)}{mdAttr}><{fTag} ref=\"{string.Format("{0}:{1}", f.Address, f.Address)}\" t=\"array\">{ConvertUtil.ExcelEscapeAndEncodeString(f.Formula)}</{fTag}>{GetFormulaValue(v,prefix)}</{cTag}>");
3113+
cache.Append($"<{cTag} r=\"{cse.CellAddress}\" s=\"{styleID}\"{GetCellType(v, true)}{mdAttr}><{fTag} ref=\"{string.Format("{0}:{1}", f.Address, f.Address)}\" t=\"array\"{mdAttrForFTag}>{ConvertUtil.ExcelEscapeAndEncodeString(f.Formula)}</{fTag}>{GetFormulaValue(v,prefix)}</{cTag}>");
30793114
}
30803115
else
30813116
{
30823117
cache.Append($"<{cTag} r=\"{f.Address}\" s=\"{styleID}\"{GetCellType(v, true)}{mdAttr}>");
3083-
cache.Append($"<{fTag}>{ConvertUtil.ExcelEscapeAndEncodeString(f.Formula)}</{fTag}>{GetFormulaValue(v, prefix)}</{cTag}>");
3118+
cache.Append($"<{fTag}{mdAttrForFTag}>{ConvertUtil.ExcelEscapeAndEncodeString(f.Formula)}</{fTag}>{GetFormulaValue(v, prefix)}</{cTag}>");
30843119
}
30853120
}
30863121
}

src/EPPlus/ExcelWorksheets.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ public void Delete(int Index)
428428
{
429429
if (_pck.Workbook.View.ActiveTab > _pck.Workbook.Worksheets.Count)
430430
{
431-
_pck.Workbook.View.ActiveTab = _pck.Workbook.View.ActiveTab - 1;
431+
_pck.Workbook.View.ActiveTab = Math.Min(_pck.Workbook.View.ActiveTab - 1, _pck.Workbook.Worksheets.Count-1);
432432
}
433433
if (_pck.Workbook.View.ActiveTab == worksheet.SheetId)
434434
{

0 commit comments

Comments
 (0)