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
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
<NoWarn>$(NoWarn);CA1834</NoWarn> <!-- Member XXX is explicitly initialized to its default value -->
<NoWarn>$(NoWarn);CA1845</NoWarn> <!-- Use span-based 'string.Concat' and 'AsSpan' instead of 'Substring' -->
<NoWarn>$(NoWarn);CA1850</NoWarn> <!-- Prefer static 'System.Security.Cryptography.MD5.HashData' method over 'ComputeHash' -->
<NoWarn>$(NoWarn);CA1859</NoWarn> <!-- Change return type of method -->
<NoWarn>$(NoWarn);CA1861</NoWarn> <!-- Prefer 'static readonly' fields over constant array arguments -->
<NoWarn>$(NoWarn);CA1862</NoWarn> <!-- Prefer the string comparison method overload -->
<NoWarn>$(NoWarn);CA1872</NoWarn> <!-- Prefer 'System.Convert.ToHexString(byte[])' over call chains based on 'System.BitConverter.ToString(byte[])' -->
Expand Down
16 changes: 8 additions & 8 deletions main/DDF/AbstractEscherOptRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,9 @@ exists it is replaced.
*/
public void SetEscherProperty(EscherProperty value)
{
List<EscherProperty> toRemove = new List<EscherProperty>();
for (IEnumerator<EscherProperty> iterator =
properties.GetEnumerator(); iterator.MoveNext(); )
List<EscherProperty> toRemove = [];
foreach (var prop in properties)
{
EscherProperty prop = iterator.Current;
if (prop.Id == value.Id)
{
//iterator.Remove();
Expand All @@ -174,18 +172,20 @@ public void SetEscherProperty(EscherProperty value)

public void RemoveEscherProperty(int num)
{
List<EscherProperty> toRemove = new List<EscherProperty>();
for (IEnumerator<EscherProperty> iterator = EscherProperties.GetEnumerator(); iterator.MoveNext(); )
List<EscherProperty> toRemove = [];
foreach(var prop in EscherProperties)
{
EscherProperty prop = iterator.Current;
if (prop.PropertyNumber == num)
{
//iterator.Remove();
toRemove.Add(prop);
}
}
foreach (EscherProperty e in toRemove)

foreach(EscherProperty e in toRemove)
{
EscherProperties.Remove(e);
}
}

/**
Expand Down
8 changes: 3 additions & 5 deletions main/DDF/EscherContainerRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,9 @@ public IList<EscherContainerRecord> ChildContainers
{
get
{
IList<EscherContainerRecord> containers = new List<EscherContainerRecord>();
for (IEnumerator iterator = ChildRecords.GetEnumerator(); iterator.MoveNext(); )
List<EscherContainerRecord> containers = [];
foreach (EscherRecord r in ChildRecords)
{
EscherRecord r = (EscherRecord)iterator.Current;
if (r is EscherContainerRecord record)
{
containers.Add(record);
Expand Down Expand Up @@ -344,9 +343,8 @@ public override String ToXml(String tab)
{
StringBuilder builder = new StringBuilder();
builder.Append(tab).Append(FormatXmlRecordHeader(RecordName, HexDump.ToHex(RecordId), HexDump.ToHex(Version), HexDump.ToHex(Instance)));
for (IEnumerator<EscherRecord> iterator = _childRecords.GetEnumerator(); iterator.MoveNext(); )
foreach (var record in _childRecords)
{
EscherRecord record = iterator.Current;
builder.Append(record.ToXml(tab + "\t"));
}
builder.Append(tab).Append("</").Append(RecordName).Append(">\n");
Expand Down
2 changes: 1 addition & 1 deletion main/DDF/EscherDump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public EscherDump()
/// <param name="size">The number of bytes to Read.</param>
public void Dump(byte[] data, int offset, int size)
{
IEscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
DefaultEscherRecordFactory recordFactory = new();
int pos = offset;
while (pos < offset + size)
{
Expand Down
5 changes: 3 additions & 2 deletions main/DDF/UnknownEscherRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,12 @@ public override String ToXml(String tab)
builder.Append(tab).Append(FormatXmlRecordHeader(GetType().Name, HexDump.ToHex(RecordId), HexDump.ToHex(Version), HexDump.ToHex(Instance)))
.Append(tab).Append("\t").Append("<IsContainer>").Append(IsContainerRecord).Append("</IsContainer>\n")
.Append(tab).Append("\t").Append("<Numchildren>").Append(HexDump.ToHex(_childRecords.Count)).Append("</Numchildren>\n");
for (IEnumerator<EscherRecord> iterator = _childRecords.GetEnumerator(); iterator.MoveNext(); )

foreach (EscherRecord record in _childRecords)
{
EscherRecord record = iterator.Current;
builder.Append(record.ToXml(tab + "\t"));
}

builder.Append(theDumpHex).Append("\n");
builder.Append(tab).Append("</").Append(GetType().Name).Append(">\n");
return builder.ToString();
Expand Down
5 changes: 3 additions & 2 deletions main/HPSF/CustomProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public class CustomProperties : Dictionary<long, CustomProperty>
/// </summary>
//private TreeBidiDictionary<long, string> dictionary = new TreeBidiDictionary<long, string>();

private BidirectionalDictionary<long, string> dictionary = new();
private readonly BidirectionalDictionary<long, string> dictionary = new();

/// <summary>
/// Tells whether this object is pure or not.
/// </summary>
Expand Down Expand Up @@ -129,7 +130,7 @@ public CustomProperty Put(String name, CustomProperty cp)
/// <param name="customProperty">customProperty</param>
/// <return>there was already a property with the same name, the old property</return>
/// <exception cref="ClassCastException">ClassCastException</exception>
private object Put(CustomProperty customProperty)
private CustomProperty Put(CustomProperty customProperty)
{
string name = customProperty.Name;

Expand Down
10 changes: 5 additions & 5 deletions main/HPSF/PropertySetFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ limitations under the License.
*
* ==============================================================*/

using System;

using NPOI.HPSF.Wellknown;
using NPOI.POIFS.FileSystem;
using NPOI.Util;

namespace NPOI.HPSF
{
using System.IO;
using NPOI.HPSF.Wellknown;
using System;
using NPOI.POIFS.FileSystem;

/// <summary>
/// Factory class To Create instances of {@link SummaryInformation},
Expand Down Expand Up @@ -63,7 +63,7 @@ public class PropertySetFactory
*/
public static PropertySet Create(DirectoryEntry dir, String name)
{
InputStream inp = null;
DocumentInputStream inp = null;
try
{
DocumentEntry entry = (DocumentEntry)dir.GetEntry(name);
Expand Down
5 changes: 2 additions & 3 deletions main/HPSF/Section.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ namespace NPOI.HPSF
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using Cysharp.Text;
using Cysharp.Text;

/// <summary>
/// Represents a section in a {@link PropertySet}.
Expand Down Expand Up @@ -956,7 +955,7 @@ public int Write(Stream out1)
/// <param name="codepage">The codepage to be used to write the dictionary items.</param>
/// <return>number of bytes written</return>
/// <exception name="IOException">if an I/O exception occurs.</exception>
private static int WriteDictionary(Stream out1, IDictionary dictionary, int codepage)
private static int WriteDictionary(MemoryStream out1, IDictionary dictionary, int codepage)
{
int length = TypeWriter.WriteUIntToStream(out1, (uint)dictionary.Count);
foreach(DictionaryEntry ls in dictionary)
Expand Down
32 changes: 18 additions & 14 deletions main/HPSF/Variant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ limitations under the License.
*
* ==============================================================*/

using System;
using System.Collections.Generic;

namespace NPOI.HPSF
{
using System;
using System.Collections;


/// <summary>
/// The <em>Variant</em> types as defined by Microsoft's COM. I
/// found this information in <a href="http://www.marin.clara.net/COM/variant_type_definitions.htm">
Expand Down Expand Up @@ -358,9 +357,9 @@ public class Variant
* Maps the numbers denoting the variant types To their corresponding
* variant type names.
*/
private static IDictionary numberToName;
private static readonly Dictionary<long, string> numberToName;

private static IDictionary numberToLength;
private static readonly Dictionary<long, int> numberToLength;

/**
* Denotes a variant type with a Length that is unknown To HPSF yet.
Expand Down Expand Up @@ -397,7 +396,7 @@ public class Variant
static Variant()
{
/* Initialize the number-to-name map: */
Hashtable tm1 = new Hashtable();
Dictionary<long, string> tm1 = [];
tm1[0] = "VT_EMPTY";
tm1[1] = "VT_NULL";
tm1[2] = "VT_I2";
Expand Down Expand Up @@ -442,7 +441,7 @@ static Variant()
numberToName = tm1;

/* Initialize the number-to-Length map: */
Hashtable tm2 = new Hashtable();
Dictionary<long, int> tm2 = [];
tm2[0] = Length_0;
tm2[1] = Length_UNKNOWN;
tm2[2] = Length_2;
Expand Down Expand Up @@ -497,8 +496,11 @@ static Variant()
/// <returns>The variant type name or the string "unknown variant type"</returns>
public static String GetVariantName(long variantType)
{
String name = (String)numberToName[variantType];
return name != null ? name : "unknown variant type";
if (!numberToName.TryGetValue(variantType, out string name))
{
return "unknown variant type";
}
return name;
}

/// <summary>
Expand All @@ -512,11 +514,13 @@ public static String GetVariantName(long variantType)
public static int GetVariantLength(long variantType)
{
long key = (int)variantType;
if (numberToLength.Contains(key))
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compared this to Java version and there was actually a bug here, it should have been not contains -> -2


if(!numberToLength.TryGetValue(key, out int value))
{
return -2;
long Length = (long)numberToLength[key];
return Convert.ToInt32(Length);
}
}

return Convert.ToInt32((long) value);
}
}
}
5 changes: 2 additions & 3 deletions main/HSSF/Extractor/EventBasedExcelExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ limitations under the License.
namespace NPOI.HSSF.Extractor
{
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Collections;

using NPOI.HSSF.UserModel;
using NPOI.HSSF.Record;
Expand Down Expand Up @@ -160,7 +159,7 @@ private sealed class TextListener : IHSSFListener
public FormatTrackingHSSFListener ft;
private SSTRecord sstRecord;

private IList sheetNames = new ArrayList();
private List<string> sheetNames = [];
public StringBuilder text = new StringBuilder();
private int sheetNum = -1;
private int rowNum;
Expand Down
11 changes: 6 additions & 5 deletions main/HSSF/Model/DrawingManager2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ the License. You may obtain a copy of the License at
limitations Under the License.
==================================================================== */

using System.Collections.Generic;

using NPOI.DDF;

namespace NPOI.HSSF.Model
{
using NPOI.DDF;
using System.Collections;

/// <summary>
/// Provides utilities to manage drawing Groups.
/// </summary>
Expand All @@ -28,8 +29,8 @@ namespace NPOI.HSSF.Model
/// </remarks>
public class DrawingManager2
{
EscherDggRecord dgg;
IList drawingGroups = new ArrayList();
private readonly EscherDggRecord dgg;
private readonly List<EscherDgRecord> drawingGroups = [];


public DrawingManager2(EscherDggRecord dgg)
Expand Down
2 changes: 1 addition & 1 deletion main/HSSF/Model/HSSFFormulaParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace NPOI.HSSF.Model
public class HSSFFormulaParser
{

private static IFormulaParsingWorkbook CreateParsingWorkbook(HSSFWorkbook book)
private static HSSFEvaluationWorkbook CreateParsingWorkbook(HSSFWorkbook book)
{
return HSSFEvaluationWorkbook.Create(book);
}
Expand Down
19 changes: 12 additions & 7 deletions main/HSSF/Model/InternalSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace NPOI.HSSF.Model
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

using NPOI.HSSF.Record;
using NPOI.HSSF.Record.Aggregates;
using NPOI.SS.Formula;
Expand Down Expand Up @@ -461,9 +461,12 @@ public void VisitRecord(Record r) {
_records.Add(r);
}
}
private static void SpillAggregate(RecordAggregate ra, List<RecordBase> recs) {

private static void SpillAggregate(ChartSubstreamRecordAggregate ra, List<RecordBase> recs)
{
ra.VisitContainedRecords(new RecordVisitor1(recs));
}

/// <summary>
/// Creates a sheet with all the usual records minus values and the "index"
/// record (not required). Sets the location pointer to where the first value
Expand Down Expand Up @@ -2079,14 +2082,16 @@ public void Preserialize()
*/
public void ShiftBreaks(PageBreakRecord breaks, short start, short stop, int count)
{

if (rowBreaks == null)
{
return;
IEnumerator iterator = breaks.GetBreaksEnumerator();
IList ShiftedBreak = new ArrayList();
}

IEnumerator<PageBreakRecord.Break> iterator = breaks.GetBreaksEnumerator();
List<PageBreakRecord.Break> ShiftedBreak = [];
while (iterator.MoveNext())
{
PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.Current;
PageBreakRecord.Break breakItem = iterator.Current;
int breakLocation = breakItem.main;
bool inStart = (breakLocation >= start);
bool inEnd = (breakLocation <= stop);
Expand All @@ -2097,7 +2102,7 @@ public void ShiftBreaks(PageBreakRecord breaks, short start, short stop, int cou
iterator = ShiftedBreak.GetEnumerator();
while (iterator.MoveNext())
{
PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.Current;
PageBreakRecord.Break breakItem = iterator.Current;
breaks.RemoveBreak(breakItem.main);
breaks.AddBreak(breakItem.main + count, breakItem.subFrom, breakItem.subTo);
}
Expand Down
Loading
Loading