Skip to content

Commit

Permalink
Merge pull request #640 from Lehonti/develop
Browse files Browse the repository at this point in the history
Assorted refactorings and optimizations:
  • Loading branch information
appel1 committed Aug 15, 2023
2 parents 93275f9 + 8c48aba commit 2dc4c7e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/ExcelDataReader/Core/BuiltinNumberFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace ExcelDataReader.Core
{
internal static class BuiltinNumberFormat
{
private static Dictionary<int, NumberFormatString> Formats { get; } = new Dictionary<int, NumberFormatString>()
private static Dictionary<int, NumberFormatString> Formats { get; } = new Dictionary<int, NumberFormatString>
{
{ 0, new NumberFormatString("General") },
{ 1, new NumberFormatString("0") },
Expand Down
3 changes: 1 addition & 2 deletions src/ExcelDataReader/Core/Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
Expand All @@ -11,7 +10,7 @@ namespace ExcelDataReader.Core
/// </summary>
internal static class Helpers
{
private static readonly Regex EscapeRegex = new("_x([0-9A-F]{4,4})_");
private static readonly Regex EscapeRegex = new("_x([0-9A-F]{4,4})_", RegexOptions.Compiled);

/// <summary>
/// Determines whether the encoding is single byte or not.
Expand Down
6 changes: 1 addition & 5 deletions src/ExcelDataReader/Core/OpenXmlFormat/Records/Record.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ExcelDataReader.Core.OpenXmlFormat.Records
namespace ExcelDataReader.Core.OpenXmlFormat.Records
{
internal abstract class Record
{
Expand Down
60 changes: 30 additions & 30 deletions src/ExcelDataReader/Core/OpenXmlFormat/ZipWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,27 @@ public ZipWorker(Stream fileStream)
using var reader = XmlReader.Create(workbookRelsEntry.Open(), XmlSettings);
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == "Relationship")
{
var id = reader.GetAttribute("Id");
var type = reader.GetAttribute("Type");
var target = reader.GetAttribute("Target");
if (reader.NodeType != XmlNodeType.Element || reader.Name != "Relationship")
continue;

switch (type)
{
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet":
case "http://purl.oclc.org/ooxml/officeDocument/relationships/worksheet":
_worksheetRels[id] = ResolvePath(basePath, target);
break;
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles":
case "http://purl.oclc.org/ooxml/officeDocument/relationships/styles":
_fileStyles = ResolvePath(basePath, target);
break;
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings":
case "http://purl.oclc.org/ooxml/officeDocument/relationships/sharedStrings":
_fileSharedStrings = ResolvePath(basePath, target);
break;
}
var id = reader.GetAttribute("Id");
var type = reader.GetAttribute("Type");
var target = reader.GetAttribute("Target");

switch (type)
{
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet":
case "http://purl.oclc.org/ooxml/officeDocument/relationships/worksheet":
_worksheetRels[id] = ResolvePath(basePath, target);
break;
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles":
case "http://purl.oclc.org/ooxml/officeDocument/relationships/styles":
_fileStyles = ResolvePath(basePath, target);
break;
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings":
case "http://purl.oclc.org/ooxml/officeDocument/relationships/sharedStrings":
_fileSharedStrings = ResolvePath(basePath, target);
break;
}
}

Expand Down Expand Up @@ -112,17 +112,17 @@ static string ResolvePath(string? basePath, string path)
using var reader = XmlReader.Create(entry.Open(), XmlSettings);
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == "Relationship")
if (reader.NodeType != XmlNodeType.Element || reader.Name != "Relationship")
continue;

var type = reader.GetAttribute("Type");
var target = reader.GetAttribute("Target");

switch (type)
{
var type = reader.GetAttribute("Type");
var target = reader.GetAttribute("Target");

switch (type)
{
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
case "http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument":
return target;
}
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
case "http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument":
return target;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ExcelDataReader/Misc/DateTimeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static DateTime FromOADate(double d)
internal static long DoubleDateToTicks(double value)
{
if (value >= OADateMaxAsDouble || value <= OADateMinAsDouble)
throw new ArgumentException("Invalid OA Date");
throw new ArgumentException("Invalid OA Date", nameof(value));
long millis = (long)(value * MillisPerDay + (value >= 0 ? 0.5 : -0.5));

// The interesting thing here is when you have a value like 12.5 it all positive 12 days and 12 hours from 01/01/1899
Expand Down

0 comments on commit 2dc4c7e

Please sign in to comment.