Problems with encoding when converting xls to csv.

Oct 14, 2014 at 8:01 PM
Edited Oct 15, 2014 at 3:06 AM
My code:
using (var reader = new CsvReader(excelFilePath, Encoding.GetEncoding("windows-1251")))
 {
       using (CsvWriter writer = new CsvWriter(csvOutputFile, Encoding.GetEncoding("windows-1251")))
        {
              reader.ReadHeaderRecord();
              writer.ValueDelimiter = '"';
              writer.ValueSeparator = ';';

              while (reader.HasMoreRecords)
               {
                    var read = reader.ReadDataRecord();
                    writer.WriteRecord(read);
                }
         }
 }
My input file in russian language.

Result:
ђ МT i m e s N e w R o m a n C y r 1 6 Ь  ђ МT i m e s N e w R o m a n C y r 1 . И  ђ МT i m e s N e w R o m a n 1 . И   ј МT i m e s N e w R o m a n 1 . И   ђ МT i m e s N e w R o m a n 1  Ь   ђ МC a l i b r i /   # ;" # # 0 @. ; \ - # "; # # 0 @. 9   # ;" # # 0 @. ; [ R e d ] \ - # ";" # # 0 @. ;  
I'm using version 2.0.2
What I did wrong? Please help me to find couse.

P.S. Maybe I use library incorrect?
Coordinator
Oct 15, 2014 at 2:41 AM
Hi,

It's hard to say without having access to your input file. Are you sure you have the right encoding? What happens if you don't specify an encoding?

Also, what is the purpose of the code that creates a buffer? Your buffer size is one record per byte in the underlying file - I don't think you meant that.

Best,
Kent
Oct 15, 2014 at 3:43 AM
I I use another encoding or nothing like this:
var reader = new CsvReader(excelFilePath)
I get similar result.

My input file with cyrillic (russian)
Coordinator
Oct 15, 2014 at 3:48 AM
Can you email a sample data file? kent.boogaart at gmail.com
Oct 15, 2014 at 5:01 AM
Yes, I send you email with input file.