We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How can we avoid the 'Unexpected token' exception while using formula in XlsIO?

This article explains how to avoid unexpected token exception in XlsIO using C#/VB.NET

What is unexpected token exception?


Unexpected token exception occurs when some arguments or tokens are misplaced or misused in a formula. In XlsIO, while parsing the formula, it is split into tokens. When a token is not a valid one then, the unexpected token exception will be thrown. Argument separator in a formula can be a reason for the exception.


For example, consider that we need to add two numbers using formula like following code.

//Add data

worksheet["B1"].Number = 10;

worksheet["B2"].Number = 20;


//Formula to add two numbers

worksheet["B3"].Formula = "=SUM(B1,B2)";


If we use semicolon (;) instead of comma (,) in the formula like this:


Unexpected token exception will be thrown. This is because, comma (,) is used as a default arguments separator while formula parsing in XlsIO. So, when it encounters semicolon (;) it throws unexpected token exception.

In this case, we can avoid this exception by setting arguments separator as semicolon (;).


Note: If you face this exception in other similar cases, initially you should check whether all the tokens in the formula are used correctly. If you are not sure about the separator to be used, set separators on your own before using the formula.

To know more about formulas in XlsIO, please refer the documentation.

Download Complete Sample

The following C#/VB.NET code shows how to avoid the unexpected exception in XlsIO.



The below screenshot shows the output generated by XlsIO with formula.


Article ID: Published Date: Last Revised Date: Platform: Control:
1952 04/30/2011 02/28/2018 WinForms XlsIO
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Please sign in to access our KB

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon