6

Not all configurations of Excel use the same list separator symbol. In particular, it is common for Excel to use "," as the list separator in the United States and ";" as the list separator in Europe. Among other things, this affects the syntax for disjoint ranges. The same range may be formally expressed as "Sheet0!A1:B2,Sheet0!C3:D4" on one computer, but "Sheet0!A1:B2;Sheet0!C3:D4" on another computer.

I am writing code to manipulate disjoint ranges. I need to know when to use the "," syntax and when to use the ";" syntax (or, perhaps, when to use something completely different). How can I figure out what syntax to use?

Note that I'm aware that I can read the list separator from the regional settings (as described here). However, I don't want to know the regional setting per se; I want to know Excel's setting. Perhaps they are always the same, but I've seen no claim to that effect.

I'm looking for a solution for all versions of Excel, 2010 and newer. I'm using C# and Excel-DNA, but I would be grateful for a solution in any language.

1

2 Answers 2

9

You can use the property below; which returns the type of separator as a string.

  Application.International(xlListSeparator)
0

For those of you using Windows SDK:

char buf[16];
int res=GetLocaleInfoA(LOCALE_USER_DEFAULT,LOCALE_SLIST,buf,16);
if(res<=0||16<=res){//Call failed. TODO: check GetLastError()
    EXCEPT throw std::exception("Error");}
std::string listSeparator(buf,res-1);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.