Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Wed Sep 18, 2024 10:00 am

got wrong Formula result of INDEX of 2Dimensioin nameRange

Spire.XLS.png
Spire.XLS.png (32.93 KiB) Viewed 9 times


An excel file with 2 name Range
1st:NameOfRange1D(2 dimension array cell)
2nd:NameOfRange2D (2 dimension array cell)

Formula:
Sheet("target").Cells("A12").Value2 =COUNTIF(INDEX(NameOfRange2D,MATCH(B9,NameOfRange1D,0),),B9)

--------------------------------------------
MS.net core 8
Spire.XLS 14.9.1
Run at Windows 11 , Visual Studio 2022 IIS Express
--------------------------------------------
Code: Select all
public void Test2D()
{
    string fileName = @"D:\Temp\NameOfRange2D_Test1.xlsx";
    //OpenFile
    Workbook newWorkbook = new Workbook();
    newWorkbook.LoadFromFile(fileName, ExcelVersion.Version2016);

    if (newWorkbook != null)
    {
        //CalculateAllValue of workbook
        newWorkbook.CalculateAllValue();

        //get Sheet
        string srcSheetName = "Source";
        string targetSheetName = "Target";
        Worksheet? _srcSheet = newWorkbook.Worksheets[srcSheetName];
        Worksheet? _targetSheet = newWorkbook.Worksheets[targetSheetName];

        if (_srcSheet != null && _targetSheet != null) {
            //CalculateAllValue of sheet
            _srcSheet.CalculateAllValue();
            _targetSheet.CalculateAllValue();

            //Name Range
            newWorkbook.NameRanges.GetByName("NameOfRange1D");
            newWorkbook.NameRanges.GetByName("NameOfRange2D");
           
            //Get Formula String
            string posString = "A11";
            var _cell = _targetSheet[posString];
            //Get Cell Type
            XlsWorksheet.TRangeValueType cellType = _srcSheet.GetCellType(_cell.Row, _cell.Column, false);
            //Get Cell Formula Value,
            //Formula    "=INDEX(NameOfRange2D,MATCH(B9,NameOfRange1D,0),)"
            string _currentFormula = _cell.Value;
            var formulaResult = newWorkbook.CalculateFormulaValue(_currentFormula);
            Console.WriteLine(formulaResult);

            //Get Formula String
            posString = "A12";
            _cell = _targetSheet[posString];
            //Get Cell Type
            cellType = _srcSheet.GetCellType(_cell.Row, _cell.Column, false);
            //Get Cell Formula Value,
            //Formula    "=INDEX(NameOfRange2D,MATCH(B9,NameOfRange1D,0),)"
            _currentFormula = _cell.Value;
            formulaResult = newWorkbook.CalculateFormulaValue(_currentFormula);
            Console.WriteLine(formulaResult);

            //formulaResult should be 1, but get 0

        }

        //關閉
        newWorkbook.Dispose();
    }
Attachments
NameOfRange2D_Test1.zip
Target A12 Should be 1, but got 0
(9.33 KiB) Downloaded 12 times
Last edited by novajiang on Thu Sep 19, 2024 2:48 am, edited 1 time in total.

novajiang
 
Posts: 3
Joined: Wed Sep 18, 2024 9:12 am

Thu Sep 19, 2024 2:47 am

The Excel File Imag is attatched
Spire.XLS.png
Excel File Imag
Spire.XLS.png (32.93 KiB) Viewed 10 times

novajiang
 
Posts: 3
Joined: Wed Sep 18, 2024 9:12 am

Thu Sep 19, 2024 7:58 am

Hello,

Thank you for your feedback. I have successfully reproduced your issue using the excel document you provided. This issue has been logged in our bug tracking system under the number SPIREXLS-5481. Our Dev team will investigate it further, once there is any update, we will let you know.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 164
Joined: Mon Jul 15, 2024 5:40 am

Fri Sep 20, 2024 1:51 am

Thanks.


Amin.Gan wrote:Hello,

Thank you for your feedback. I have successfully reproduced your issue using the excel document you provided. This issue has been logged in our bug tracking system under the number SPIREXLS-5481. Our Dev team will investigate it further, once there is any update, we will let you know.

Sincerely,
Amin
E-iceblue support team

novajiang
 
Posts: 3
Joined: Wed Sep 18, 2024 9:12 am

Return to Spire.XLS

cron