. Net reading Excel content.
I encountered a problem during encoding today. The general description is to read a column in excel,
These are file names, similar to a relational table, and then the code looks for the corresponding file.
The content debugged by the breakpoint is also normal, but none of them can be matched (the file actually exists). When the log is played, the clues are found:
Some spaces are converted into question marks. Isn't it my method of opening wrong ...?
I tried several different encoding methods to open the file, and the problem persists. I personally feel that this file already contains this special character at the time of writing. Only a space is displayed.
Since the opening method is not affected, can I replace the question mark with a space. Write Replace (?, "") This does not work. Therefore, transcoding is required first.
The final solution is:
Byte [] space = new byte [] {0xc2, 0xa0 };
String UTFSpace = Encoding. GetEncoding ("UTF-8"). GetString (space );
Name = name. Replace (UTFSpace ,"");
Problem reference: http://blog.csdn.net/wuhongyao3/article/details/5834921