diff --git a/ExcelMerge/CsvReader.cs b/ExcelMerge/CsvReader.cs index 5f84dfe..84a77ba 100644 --- a/ExcelMerge/CsvReader.cs +++ b/ExcelMerge/CsvReader.cs @@ -8,8 +8,14 @@ internal class CsvReader { internal static IEnumerable Read(string path) { - using (var sr = new StreamReader(path, Encoding.UTF8)) + using (var stream = File.OpenRead(path)) { + var detector = new Ude.CharsetDetector(); + detector.Feed(stream); + detector.DataEnd(); + var encoding = detector.IsDone() ? Encoding.GetEncoding(detector.Charset) : Encoding.Default; + stream.Position = 0; + var sr = new StreamReader(stream, encoding); var rowIndex = 0; while (!sr.EndOfStream) { @@ -22,5 +28,6 @@ internal static IEnumerable Read(string path) } } } + } } diff --git a/ExcelMerge/ExcelMerge.csproj b/ExcelMerge/ExcelMerge.csproj index bb3f1f4..3eb5c2b 100644 --- a/ExcelMerge/ExcelMerge.csproj +++ b/ExcelMerge/ExcelMerge.csproj @@ -60,6 +60,9 @@ + + ..\packages\Ude.NetStandard.1.2.0\lib\net45\Ude.NetStandard.dll + diff --git a/ExcelMerge/TsvReader.cs b/ExcelMerge/TsvReader.cs index d490e33..d64ddfa 100644 --- a/ExcelMerge/TsvReader.cs +++ b/ExcelMerge/TsvReader.cs @@ -8,8 +8,14 @@ public class TsvReader { internal static IEnumerable Read(string path) { - using (var sr = new StreamReader(path, Encoding.UTF8)) + using (var stream = File.OpenRead(path)) { + var detector = new Ude.CharsetDetector(); + detector.Feed(stream); + detector.DataEnd(); + var encoding = detector.IsDone() ? Encoding.GetEncoding(detector.Charset) : Encoding.Default; + stream.Position = 0; + var sr = new StreamReader(stream, encoding); var rowIndex = 0; while (!sr.EndOfStream) { diff --git a/ExcelMerge/packages.config b/ExcelMerge/packages.config index 74b655d..18044b2 100644 --- a/ExcelMerge/packages.config +++ b/ExcelMerge/packages.config @@ -3,4 +3,5 @@ + \ No newline at end of file