@univerjs/sheets-formula 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -719,7 +719,7 @@ To implement a formula, you need to add formula description, internationalizatio
719
719
  - Extract the `description` from the content, as some Excel descriptions are lengthy and need simplification.
720
720
  - `abstract` and `links` generally do not need modification.
721
721
  - `aliasFunctionName` is optional; most formulas do not need to be filled (or can be set for aliases in specific countries). Currently, there is no documentation for formula aliases. Currently I have found a function translation plug-in that may provide similar functions [Excel Functions Translator](https://support.microsoft.com/en-us/office/excel-functions-translator-f262d0c0-991c-485b-89b6-32cc8d326889)
722
- - `functionParameter` needs a name for each parameter. We recommend varying names based on the parameter's meaning, e.g., use `number` for a numeric parameter (if there is only one) or `number1`, `number2` for multiple numeric parameters. Use `range` for a range, `criteria` for conditions, and `sum_range` for the sum range (separated by `_` for multiple words).
722
+ - `functionParameter` needs a name for each parameter. We recommend varying names based on the parameter's meaning, e.g., use `number` for a numeric parameter (if there is only one) or `number1`, `number2` for multiple numeric parameters. Use `range` for a range, `criteria` for conditions, and `sumRange` for the sum range, use `camelCase`. For specific parameter content, the English format of `name` uses the underlined format `sum_range`, other languages use the translated text, and `detail` uses all translations.
723
723
  - Some Chinese translations in the Office function documentation are machine-translated and may be unclear. Modify as needed. For example, `单元格参考` (Cell Reference) should be translated as `单元格引用`. Numeric type parameters are uniformly translated as: `数值`.
724
724
  - Do not end `abstract` with a period (used in the search list when users input cells), but end `description` and `detail` with a period (used in descriptions).
725
725
  - Capitalize the first letter of English sentences.
@@ -743,11 +743,11 @@ To implement a formula, you need to add formula description, internationalizatio
743
743
 
744
744
  Location: [packages/engine-formula/src/functions/math/sumif/index.ts](https://github.com/dream-num/univer/blob/dev/packages/engine-formula/src/functions/math/sumif/index.ts).
745
745
 
746
- Create a new folder for the formula under the current formula category, with one folder per formula. Then create an `index.ts` file to write the formula algorithm. Use camel case for the formula `class` name, considering the formula as one word. If a formula contains `_` or `.`, treat it as two words, such as:
746
+ Create a new formula folder under the classification folder of the current formula. The folder name is the same as the formula, named with `kebab-case`, one folder for each formula. Then create a new `index.ts` file to write the formula algorithm. The name of the formula `class` adopts `PascalCase`. The formula is considered to be one word, and the formula with `_` or `.` is considered to be two words such as
747
747
 
748
- - `SUMIF` => `Sumif`
749
- - `NETWORKDAYS.INTL` => `Networkdays_Intl`
750
- - `ARRAY_CONSTRAIN` => `Array_Constrain`
748
+ - `SUMIF` => folder `sumif`, class `Sumif`
749
+ - `NETWORKDAYS.INTL` => folder `networkdays-intl`, class `NetworkdaysIntl`
750
+ - `ARRAY_CONSTRAIN` => folder `array-constrain`, class `ArrayConstrain`
751
751
 
752
752
  Create a `__tests__` folder at the same level to write unit tests. After writing, remember to add the formula algorithm and function name mapping in the `function-map` file in the category directory to register the formula algorithm.
753
753
 
@@ -772,20 +772,26 @@ To implement a formula, you need to add formula description, internationalizatio
772
772
  - After selecting `SUMIF` or entering `=sumif(`, trigger the formula details popup and carefully check the contents.
773
773
  - Select the data range, trigger the calculation, and check if the formula calculation result is correct.
774
774
 
775
- #### Considerations for Formula Implementation
775
+ ### Considerations for Formula Implementation
776
776
 
777
- - Any formula's input and output can be `A1`, `A1:B10`, etc. When researching Excel, consider all cases, such as `=SIN(A1:B10)`, which expands to the calculated range.
778
- - For example, the `XLOOKUP` function requires at least one of the rows or columns of its two inputs to be of equal size for matrix calculation.
779
- - For example, the `SUMIF` function, although commonly used for summation, can expand based on the second parameter.
777
+ - For most formula rules, please refer to the latest version of Excel. If there are any unreasonable rules, please refer to Google Sheets.
778
+ - The input and output parameters of any formula can be `A1`, `A1:B10`, and the cell content may also be numbers, strings, Boolean values, empty cells, error values, arrays, etc., although the formula tutorial explains In order to identify fixed data types, the program implementation needs to be compatible. When researching Excel, consider all cases, such as `=SIN(A1:B10)`, which expands to the calculated range.
779
+ - For example, the `XLOOKUP` function requires at least one of the rows or columns of its two inputs to be of equal size for matrix calculation.
780
+ - For example, the `SUMIF` function, although commonly used for summation, can expand based on the second parameter.
780
781
  ![sumif array](./assets/sumif-array.png)
781
782
  ![sumif array result](./assets/sumif-array-result.png)
782
- - Excel formula calculation is becoming more like numpy, for example:
783
+ - Excel formula calculation is becoming more like numpy, for example:
783
784
  ![numpy](./assets/numpy.png)
784
- - For numerical calculations in formulas, use built-in methods and try to avoid obtaining values for manual calculation. Because formula parameters can be values, arrays, or references. You can refer to existing `sum` and `minus` functions.
785
- - Precision issues: The formula introduces `big.js`, and using built-in methods will call this library. However, it is nearly 100 times slower than native calculations. Therefore, for methods like `sin`, it is advisable to use native implementations.
786
- - For custom calculations, use the `product` function, suitable for calculating two input parameters. Call `map` to iterate over the values for changes to a parameter's own values.
787
-
788
- #### Formula Basic Tools
785
+ - For numerical calculations in formulas, use built-in methods and try to avoid obtaining values for manual calculation. Because formula parameters can be values, arrays, or references. You can refer to existing `sum` and `minus` functions.
786
+ - Precision issues: The formula introduces `big.js`, and using built-in methods will call this library. However, it is nearly 100 times slower than native calculations. Therefore, for methods like `sin`, it is advisable to use native implementations.
787
+ - For custom calculations, use the `product` function, suitable for calculating two input parameters. Call `map` to iterate over the values for changes to a parameter's own values.
788
+ - Formula algorithm supports two configurations `needsExpandParams` and `needsReferenceObject`
789
+ - `needsExpandParams`: Whether the function needs to expand parameters, mainly handles situations where the `LOOKUP` function needs to handle vectors of different sizes
790
+ - `needsReferenceObject`: Whether the function needs to pass in a reference object. After setting, `BaseReferenceObject` will not be converted into `ArrayValueObject` but will be passed directly into the formula algorithm, such as the `OFFSET` function
791
+ - Formula calculation errors will return fixed types of errors, such as `#NAME?`, `#VALUE!`, which need to be aligned with Excel, because there are functions `ISERR`, `ISNA`, etc. that determine the error type. If the type is not specified correctly, the result will be It may be different.
792
+ - In the formula algorithm, even if it is a required parameter, it is necessary to intercept the case of `null` and return the error `#N/A`, because the user may not enter any parameters. This behavior will be intercepted in Excel and `#N/A` will be returned in Google Sheets. We refer to Google Sheets.
793
+
794
+ ### Formula Basic Tools
789
795
 
790
796
  1. `ValueObjectFactory` is used to automatically recognize parameter formats and create a parameter instance. Use `RangeReferenceObject` to create parameter instances for range-type data.
791
797
  2. The array `toArrayValueObject` can be operated directly with values to get a new array.