. Net reading Excel content.

Source: Internet
Author: User

. 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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.