Skip to content

Commit 475672d

Browse files
authored
Merge branch 'ExcelDataReader:develop' into fix-578-issue
2 parents a40db58 + 2dc4c7e commit 475672d

File tree

6 files changed

+35
-40
lines changed

6 files changed

+35
-40
lines changed

src/ExcelDataReader/Core/BuiltinNumberFormat.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace ExcelDataReader.Core
55
{
66
internal static class BuiltinNumberFormat
77
{
8-
private static Dictionary<int, NumberFormatString> Formats { get; } = new Dictionary<int, NumberFormatString>()
8+
private static Dictionary<int, NumberFormatString> Formats { get; } = new Dictionary<int, NumberFormatString>
99
{
1010
{ 0, new NumberFormatString("General") },
1111
{ 1, new NumberFormatString("0") },

src/ExcelDataReader/Core/Helpers.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Globalization;
32
using System.Text;
43
using System.Text.RegularExpressions;
@@ -11,7 +10,7 @@ namespace ExcelDataReader.Core
1110
/// </summary>
1211
internal static class Helpers
1312
{
14-
private static readonly Regex EscapeRegex = new("_x([0-9A-F]{4,4})_");
13+
private static readonly Regex EscapeRegex = new("_x([0-9A-F]{4,4})_", RegexOptions.Compiled);
1514

1615
/// <summary>
1716
/// Determines whether the encoding is single byte or not.

src/ExcelDataReader/Core/OpenXmlFormat/BinaryFormat/BiffReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public BiffReader(Stream stream)
2727
return null;
2828

2929
byte[] buffer = recordLength < _buffer.Length ? _buffer : new byte[recordLength];
30-
if (Stream.Read(buffer, 0, (int)recordLength) != recordLength)
30+
if (Stream.ReadAtLeast(buffer, 0, (int)recordLength) != recordLength)
3131
return null;
3232

3333
return ReadOverride(buffer, recordId, recordLength);

src/ExcelDataReader/Core/OpenXmlFormat/Records/Record.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
4-
5-
namespace ExcelDataReader.Core.OpenXmlFormat.Records
1+
namespace ExcelDataReader.Core.OpenXmlFormat.Records
62
{
73
internal abstract class Record
84
{

src/ExcelDataReader/Core/OpenXmlFormat/ZipWorker.cs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,27 @@ public ZipWorker(Stream fileStream)
6464
using var reader = XmlReader.Create(workbookRelsEntry.Open(), XmlSettings);
6565
while (reader.Read())
6666
{
67-
if (reader.NodeType == XmlNodeType.Element && reader.Name == "Relationship")
68-
{
69-
var id = reader.GetAttribute("Id");
70-
var type = reader.GetAttribute("Type");
71-
var target = reader.GetAttribute("Target");
67+
if (reader.NodeType != XmlNodeType.Element || reader.Name != "Relationship")
68+
continue;
7269

73-
switch (type)
74-
{
75-
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet":
76-
case "http://purl.oclc.org/ooxml/officeDocument/relationships/worksheet":
77-
_worksheetRels[id] = ResolvePath(basePath, target);
78-
break;
79-
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles":
80-
case "http://purl.oclc.org/ooxml/officeDocument/relationships/styles":
81-
_fileStyles = ResolvePath(basePath, target);
82-
break;
83-
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings":
84-
case "http://purl.oclc.org/ooxml/officeDocument/relationships/sharedStrings":
85-
_fileSharedStrings = ResolvePath(basePath, target);
86-
break;
87-
}
70+
var id = reader.GetAttribute("Id");
71+
var type = reader.GetAttribute("Type");
72+
var target = reader.GetAttribute("Target");
73+
74+
switch (type)
75+
{
76+
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet":
77+
case "http://purl.oclc.org/ooxml/officeDocument/relationships/worksheet":
78+
_worksheetRels[id] = ResolvePath(basePath, target);
79+
break;
80+
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles":
81+
case "http://purl.oclc.org/ooxml/officeDocument/relationships/styles":
82+
_fileStyles = ResolvePath(basePath, target);
83+
break;
84+
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings":
85+
case "http://purl.oclc.org/ooxml/officeDocument/relationships/sharedStrings":
86+
_fileSharedStrings = ResolvePath(basePath, target);
87+
break;
8888
}
8989
}
9090

@@ -112,17 +112,17 @@ static string ResolvePath(string? basePath, string path)
112112
using var reader = XmlReader.Create(entry.Open(), XmlSettings);
113113
while (reader.Read())
114114
{
115-
if (reader.NodeType == XmlNodeType.Element && reader.Name == "Relationship")
115+
if (reader.NodeType != XmlNodeType.Element || reader.Name != "Relationship")
116+
continue;
117+
118+
var type = reader.GetAttribute("Type");
119+
var target = reader.GetAttribute("Target");
120+
121+
switch (type)
116122
{
117-
var type = reader.GetAttribute("Type");
118-
var target = reader.GetAttribute("Target");
119-
120-
switch (type)
121-
{
122-
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
123-
case "http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument":
124-
return target;
125-
}
123+
case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
124+
case "http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument":
125+
return target;
126126
}
127127
}
128128

src/ExcelDataReader/Misc/DateTimeHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static DateTime FromOADate(double d)
5555
internal static long DoubleDateToTicks(double value)
5656
{
5757
if (value >= OADateMaxAsDouble || value <= OADateMinAsDouble)
58-
throw new ArgumentException("Invalid OA Date");
58+
throw new ArgumentException("Invalid OA Date", nameof(value));
5959
long millis = (long)(value * MillisPerDay + (value >= 0 ? 0.5 : -0.5));
6060

6161
// 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

0 commit comments

Comments
 (0)