reading csv

  • Thread starter Thread starter Stefan Seidel
  • Start date Start date
S

Stefan Seidel

Hi NG,

i try to read data into a .NET application from Excel with the following
code:
IDataObject cb = Clipboard.GetDataObject();

if ( cb.GetDataPresent(DataFormats.CommaSeparatedValue) ) {

StreamReader sr = new StreamReader((Stream)
cb.GetData(DataFormats.CommaSeparatedValue));

while (sr.Peek() > 0)

string s = sr.ReadLine();

}

The problem ist that i do not receive some signs (special signs as german
"ä" e.g.).

Thanks for any help

Stefan
 
Hi,

Try to use "BinaryReader" with "System.Text.Encoding.Unicode" instead of
"StreamReader".

Tomer.
 
I tried the BinaryReader but still have the same problem. Here's the code:
while ((br.BaseStream.ReadByte()) != -1 ){

br.BaseStream.Position = br.BaseStream.Position - 1;

ch = br.ReadChar();

if (ch != '\n'){

s = s+ch;}

else{// do something with the s

}

s = "";

}
 
Have you tried getting the specific encoding with the codepage that's being
used in this CSV file?

b.t.w - why ReadChar() and not ReadString()?
 
Back
Top