Skip to content

Commit b9c7431

Browse files
authored
Merge branch 'develop8' into bug/issue1982
2 parents e086d50 + 50cee26 commit b9c7431

14 files changed

Lines changed: 549 additions & 277 deletions

src/EPPlus/ExcelPackage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ public IEnumerable<ExcelInitializationError> InitializationErrors
705705
}
706706
}
707707
/// <summary>
708-
/// Automaticlly adjust drawing size when column width/row height are adjusted, depending on the drawings editBy property.
708+
/// Automatically adjust drawing size when column width/row height are adjusted, depending on the drawings editBy property.
709709
/// Default True
710710
/// </summary>
711711
public bool DoAdjustDrawings

src/EPPlus/ExcelWorkbook.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ internal void Save() // Workbook Save
13821382

13831383
if (loadPivotTable)
13841384
{
1385-
//Updates the Workbook Xml, so must be before saving the wookbook part
1385+
//Updates the Workbook Xml, so must be before saving the workbook part
13861386
SavePivotTableCaches();
13871387
}
13881388

@@ -1552,12 +1552,12 @@ private void SavePivotTableCaches()
15521552
{
15531553
foreach (var cache in info.PivotCaches)
15541554
{
1555-
if (cache._pivotTables.Count == 0)
1555+
if (cache._pivotTables.Count == 0)
15561556
{
15571557
cache.Delete();
15581558
continue;
15591559
}
1560-
//Rewrite the pivottable address again if any rows or columns have been inserted or deleted
1560+
//Rewrite the pivot table address again if any rows or columns have been inserted or deleted
15611561
var r = cache.SourceRange;
15621562
if (r != null && r.Worksheet != null) //Source does not exist
15631563
{
@@ -1580,7 +1580,7 @@ private void SavePivotTableCaches()
15801580
}
15811581
private void FixFieldNamesAndUpdateSharedItems(PivotTableCacheInternal cache, ExcelTable t, XmlNodeList fields)
15821582
{
1583-
cache.RefreshFields();
1583+
cache.RefreshFields(true);
15841584
int ix = 0;
15851585
var flds = new HashSet<string>();
15861586
var sourceRange = cache.SourceRange;

src/EPPlus/FormulaParsing/ErrorValues/ExcelErrorValue.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,22 @@ public override int GetHashCode()
254254
{
255255
return (int)Type;
256256
}
257-
257+
/// <summary>
258+
/// Determines whether the specified <see cref="ExcelErrorValue"/> are equal.
259+
/// </summary>
260+
/// <param name="x">The first object to compare.</param>
261+
/// <param name="y">The first object to compare.</param>
262+
/// <returns>true if the specified objects are equal; otherwise, false.</returns>
258263
public bool Equals(ExcelErrorValue x, ExcelErrorValue y)
259264
{
260265
return x.Type==y.Type;
261266
}
262267

268+
/// <summary>
269+
/// Returns a hash code for the specified object.
270+
/// </summary>
271+
/// <param name="obj">The <see cref="ExcelErrorValue"/> for which a hash code is to be returned</param>
272+
/// <returns>A hash code for the specified object.</returns>
263273
public int GetHashCode(ExcelErrorValue obj)
264274
{
265275
if (obj == null) return -1;

src/EPPlus/Metadata/ExcelMetadata.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@ namespace OfficeOpenXml.Metadata
2929
internal class ExcelMetadata
3030
{
3131
private ExcelWorkbook _wb;
32-
//private readonly ExcelRichData _richData;
3332
private ZipPackagePart _part;
3433
private Uri _uri;
3534

3635
//Preserve xml variables
3736
private string _metadataStringsXml;
3837
private string _metadataStringCount;
39-
private string _mdxMetadataXml;
40-
private string _mdxMetadataCount;
4138
public string _extLstXml;
4239

4340

@@ -91,7 +88,6 @@ private void ReadMetadata(Stream stream)
9188
break;
9289
case "mdxMetadata":
9390
//Currently not used. Preserve.
94-
_mdxMetadataCount = xr.GetAttribute("count");
9591
ReadMdxMetadataItems(xr);
9692
break;
9793
case "futureMetadata":

src/EPPlus/Table/PivotTable/ExcelPivotCacheDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ internal ExcelPivotCacheDefinition(XmlNamespaceManager nsm, ExcelPivotTable pivo
9090
/// </summary>
9191
public void Refresh()
9292
{
93-
_cacheReference.RefreshFields();
93+
_cacheReference.RefreshFields(false);
9494
}
9595

9696
internal Packaging.ZipPackagePart Part

src/EPPlus/Table/PivotTable/ExcelPivotTableCacheField.cs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -165,29 +165,7 @@ internal void WriteSharedItems(XmlElement fieldNode, XmlNamespaceManager nsm)
165165
{
166166
shNode.SetAttribute("containsMixedTypes", "1");
167167
SetFlags(shNode, flags);
168-
169-
//Grouped fields need to have the max and min values set.
170-
if (Grouping != null)
171-
{
172-
if (flags == DataTypeFlags.DateTime)
173-
{
174-
var min = (DateTime)SharedItems.Min();
175-
shNode.SetAttribute("minDate", GetDateString(min));
176-
var max = (DateTime)SharedItems.Max();
177-
shNode.SetAttribute("maxDate", GetDateString(max));
178-
}
179-
else if ((int)(flags & DataTypeFlags.Number | flags & DataTypeFlags.Int | DataTypeFlags.Float) != 0)
180-
{
181-
var min = ConvertUtil.GetValueDouble(SharedItems.Min(), true, true);
182-
var max = ConvertUtil.GetValueDouble(SharedItems.Max(), true, true);
183-
if (!(double.IsNaN(min) || double.IsNaN(max)))
184-
{
185-
shNode.SetAttribute("minValue", min.ToString(CultureInfo.InvariantCulture));
186-
shNode.SetAttribute("maxValue", max.ToString(CultureInfo.InvariantCulture));
187-
}
188-
}
189-
}
190-
}
168+
}
191169
else
192170
{
193171
if ((flags & DataTypeFlags.String) != DataTypeFlags.String &&
@@ -200,6 +178,32 @@ internal void WriteSharedItems(XmlElement fieldNode, XmlNamespaceManager nsm)
200178
}
201179
SetFlags(shNode, flags);
202180
}
181+
182+
//Grouped fields need to have the max and min values set.
183+
if (Grouping != null)
184+
{
185+
if ((flags == DataTypeFlags.DateTime || flags == (DataTypeFlags.DateTime | DataTypeFlags.Empty)) && Grouping is ExcelPivotTableFieldDateGroup)
186+
{
187+
var min = (DateTime)SharedItems.Where(x => x != null && !x.Equals(ExcelPivotTable.PivotNullValue)).Min();
188+
shNode.SetAttribute("minDate", GetDateString(min));
189+
var max = (DateTime)SharedItems.Where(x => x != null && !x.Equals(ExcelPivotTable.PivotNullValue)).Max();
190+
shNode.SetAttribute("maxDate", GetDateString(max));
191+
}
192+
else if (Grouping is ExcelPivotTableFieldNumericGroup)
193+
{
194+
var validFlags = (DataTypeFlags.Number | DataTypeFlags.Int | DataTypeFlags.Float | DataTypeFlags.Empty);
195+
if ((flags & validFlags) != 0 && (flags & ~validFlags) == 0 && flags != DataTypeFlags.Empty) // Check that source data is numeric
196+
{
197+
var min = ConvertUtil.GetValueDouble(SharedItems.Where(x => x != null && !x.Equals(ExcelPivotTable.PivotNullValue)).Min(), true, true);
198+
var max = ConvertUtil.GetValueDouble(SharedItems.Where(x => x != null && !x.Equals(ExcelPivotTable.PivotNullValue)).Max(), true, true);
199+
if (!(double.IsNaN(min) || double.IsNaN(max)))
200+
{
201+
shNode.SetAttribute("minValue", min.ToString(CultureInfo.InvariantCulture));
202+
shNode.SetAttribute("maxValue", max.ToString(CultureInfo.InvariantCulture));
203+
}
204+
}
205+
}
206+
}
203207
}
204208
internal bool IsRowColumnOrPage
205209
{
@@ -334,7 +338,7 @@ private void SetFlags(XmlElement shNode, DataTypeFlags flags)
334338
{
335339

336340
shNode.SetAttribute("containsDate", "1");
337-
if(flags == DataTypeFlags.DateTime)
341+
if(flags == DataTypeFlags.DateTime || flags == (DataTypeFlags.DateTime | DataTypeFlags.Empty))
338342
{
339343
shNode.SetAttribute("containsNonDate", "0");
340344
}

src/EPPlus/Table/PivotTable/ExcelPivotTableDataField.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public string Name
7272
{
7373
if (Field.PivotTable.DataFields.ExistsDfName(value, this))
7474
{
75-
throw (new InvalidOperationException("Duplicate datafield name"));
75+
throw (new InvalidOperationException("Duplicate data field name"));
7676
}
7777
SetXmlNodeString("@name", value);
7878
}

src/EPPlus/Table/PivotTable/ExcelPivotTableField.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ public ExcelPivotTableFieldGroup Grouping
584584
}
585585
}
586586
/// <summary>
587-
/// The numberformat to use for the column
587+
/// The number format to use for the column
588588
/// </summary>
589589
public string Format { get; set; }
590590
#region Private & internal Methods
@@ -736,7 +736,7 @@ public ExcelPivotTableCacheField Cache
736736
}
737737
}
738738
/// <summary>
739-
/// Add numberic grouping to the field
739+
/// Add numeric grouping to the field
740740
/// </summary>
741741
/// <param name="Start">Start value</param>
742742
/// <param name="End">End value</param>

0 commit comments

Comments
 (0)