Get CSV Data from Clipboard (pasted from Excel) that contains accented characters

后端 未结 2 945
夕颜
夕颜 2021-01-31 16:48

SCENARIO

  • My users will copy cells from Excel (thus placing it into the clipboard)
  • And my application will retrieve those cells from the clipboard
  • <
2条回答
  •  醉酒成梦
    2021-01-31 17:15

    Excel stores the string on the clipboard using the Unicode character encoding. The reason you get a square when you try to read the string in ANSI is that there is no representation for that character in your system's ANSI codepage. You should just use Unicode. If you're going to be dealing with localization issues, then ANSI is just more trouble than it's worth.

    Edit: Joel Spolsky wrote an excellent introduction to character encodings, which is definitely worth checking out: The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

提交回复
热议问题