Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClosedXML formula support for parsing Chinese #972

Open
1 of 2 tasks
shangrics opened this issue Aug 13, 2018 · 5 comments
Open
1 of 2 tasks

ClosedXML formula support for parsing Chinese #972

shangrics opened this issue Aug 13, 2018 · 5 comments

Comments

@shangrics
Copy link

Read and complete the full issue template

Do you want to request a feature or report a bug?

  • Bug
  • Feature

Version of ClosedXML

e.g. 0.93.1

What is the current behavior?

My Demo.xlsx includes two Sheets, which are all Chinese Sheet name.

I set my formula in the cell, and it refers to another Sheet.

But when I get cell value , the value shows Exception.

demo.xlsx

Did this work in previous versions of our tool? Which versions?

I have tested it with versions: 0.93.1

Code to reproduce problem:

using (var objXLWorkbook = new XLWorkbook(src))
        {
            var objWorksheet = objXLWorkbook.Worksheet("測試二");

            objWorksheet.Cell("A1").FormulaA1 = "=IF(測試一!A1=10,1,2)";

            var objxLCell = objWorksheet.Cell("A1").Value;
        }

exception Message: Identifier expected.
exception StackTrace:
at ClosedXML.Excel.CalcEngine.CalcEngine.GetToken()
at ClosedXML.Excel.CalcEngine.CalcEngine.GetParameters()
at ClosedXML.Excel.CalcEngine.CalcEngine.ParseAtom()
at ClosedXML.Excel.CalcEngine.CalcEngine.ParseUnary()
at ClosedXML.Excel.CalcEngine.CalcEngine.ParsePower()
at ClosedXML.Excel.CalcEngine.CalcEngine.ParseMulDiv()
at ClosedXML.Excel.CalcEngine.CalcEngine.ParseAddSub()
at ClosedXML.Excel.CalcEngine.CalcEngine.ParseCompare()
at ClosedXML.Excel.CalcEngine.CalcEngine.Parse(String expression)
at ClosedXML.Excel.CalcEngine.ExpressionCache.get_Item(String expression)
at ClosedXML.Excel.CalcEngine.CalcEngine.Evaluate(String expression)
at ClosedXML.Excel.XLCell.RecalculateFormula(String fA1)
at ClosedXML.Excel.XLCell.Evaluate(Boolean force)
at ClosedXML.Excel.XLCell.get_Value()

=========================================

I found ClosedXML.Excel.CalcEngine.CalcEngine.GetToken() ,
have a piece of code :

var isLetter = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');

it's seems to only identify English

@shangrics shangrics changed the title ClosedXML Formula Support for parsing Chinese ClosedXML formula support for parsing Chinese Aug 13, 2018
@Pankraty
Copy link
Member

Try to escape the worksheet name. E.g. =IF('測試一'!A1=10,1,2)

@shangrics
Copy link
Author

That is ok but i wonder if you can increase the range of characters' identification
E.g.
var isLetter = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= Convert.ToInt32("4e00", 16) && c <= Convert.ToInt32("9fff", 16));

4e00~9fff: Chinese Unicode range

@igitur
Copy link
Member

igitur commented Aug 14, 2018

We should rather use the Char.IsLetter method. Btw, the expression parser seems to be a derivative work of https://github.com/kahanu/System.Linq.Dynamic/blob/master/Src/System.Linq.Dynamic/DynamicLinq.cs . And it seems they now also use Char.IsLetter.

@shangrics
Copy link
Author

shangrics commented Aug 14, 2018

OK.
With regard to revising this issue, which versions would you consider to launch in?
Thanks.

@igitur
Copy link
Member

igitur commented Feb 20, 2019

Please try with v0.94.2 and let me know if it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants