Giter VIP home page Giter VIP logo

Comments (5)

jingwood avatar jingwood commented on May 12, 2024

Please refer to https://reogrid.net/document/customize-function/

unvell.ReoGrid.Formula.FormulaExtension.CustomFunctions["RANK"] = (cell, args) =>
  {
    // sample code

    if (args.Length == 0)
    {
      // this function needs at least one argument
      return null;
    }

    return Convert.ToString(args[0]).ToUpper();
  };

Also will be great if you make the function as a standard built-in function of ReoGrid by pushing your change to this repository.

from reogrid.

segunodu avatar segunodu commented on May 12, 2024

Thank you very much.

from reogrid.

segunodu avatar segunodu commented on May 12, 2024

Hello Jing, I tried to use RANK in the customize function but I am not getting the desired result

FormulaExtension.CustomFunctions["RANK"] = (cell, args) =>
{
  return Rank(cell, args);
};

How do I get the data in the reference cell and rank it in the reference range?

from reogrid.

jingwood avatar jingwood commented on May 12, 2024

@segunodu Did you solve this? I am considering to make the RANK function as a built-in function of ReoGrid in next version.

from reogrid.

segunodu avatar segunodu commented on May 12, 2024

Hello Jingwood, sorry I have not responded since. I have solved the Rank function issue using a Rank method and creating Customize Rank function.

The method:

	public static double Rank<T>(T value, IEnumerable<T> data)
	{
		return data.OrderByDescending(x => x).ToList().IndexOf(value) + 1;
	}

And the Customize function:

		FormulaExtension.CustomFunctions["RANK"] = (cell, args) =>
		{
			if (args.Length < 1 || !(args[0] is CellPosition || args[1] is RangePosition))
			{
				return null;
			}
			double cellVal = (double)args[0];
			RangePosition rangePos = (RangePosition)args[1];
			List <double> rangeNums = new List<double>();

			cell.Worksheet.IterateCells(rangePos, (r, c, inCell) =>
			{
				double rangeVal;
				
				if (CellUtility.TryGetNumberData(inCell.Data, out rangeVal))
				{
					rangeNums.Add(rangeVal);
				}
				return true;
			});
			double[] rangeArray = rangeNums.ToArray();
			double numPos = Rank(cellVal, rangeArray);
			return numPos;
		};

Thank you very much. I hope this method will be easier to add into the next Reogrid release. If you need help creating other Customize functions, let me know.

Thank you.

from reogrid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.