excel.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. /*
  2. Language: Excel formulae
  3. Author: Victor Zhou <OiCMudkips@users.noreply.github.com>
  4. Description: Excel formulae
  5. Website: https://products.office.com/en-us/excel/
  6. Category: enterprise
  7. */
  8. /** @type LanguageFn */
  9. function excel(hljs) {
  10. // built-in functions imported from https://web.archive.org/web/20160513042710/https://support.office.com/en-us/article/Excel-functions-alphabetical-b3944572-255d-4efb-bb96-c6d90033e188
  11. const BUILT_INS = [
  12. "ABS",
  13. "ACCRINT",
  14. "ACCRINTM",
  15. "ACOS",
  16. "ACOSH",
  17. "ACOT",
  18. "ACOTH",
  19. "AGGREGATE",
  20. "ADDRESS",
  21. "AMORDEGRC",
  22. "AMORLINC",
  23. "AND",
  24. "ARABIC",
  25. "AREAS",
  26. "ASC",
  27. "ASIN",
  28. "ASINH",
  29. "ATAN",
  30. "ATAN2",
  31. "ATANH",
  32. "AVEDEV",
  33. "AVERAGE",
  34. "AVERAGEA",
  35. "AVERAGEIF",
  36. "AVERAGEIFS",
  37. "BAHTTEXT",
  38. "BASE",
  39. "BESSELI",
  40. "BESSELJ",
  41. "BESSELK",
  42. "BESSELY",
  43. "BETADIST",
  44. "BETA.DIST",
  45. "BETAINV",
  46. "BETA.INV",
  47. "BIN2DEC",
  48. "BIN2HEX",
  49. "BIN2OCT",
  50. "BINOMDIST",
  51. "BINOM.DIST",
  52. "BINOM.DIST.RANGE",
  53. "BINOM.INV",
  54. "BITAND",
  55. "BITLSHIFT",
  56. "BITOR",
  57. "BITRSHIFT",
  58. "BITXOR",
  59. "CALL",
  60. "CEILING",
  61. "CEILING.MATH",
  62. "CEILING.PRECISE",
  63. "CELL",
  64. "CHAR",
  65. "CHIDIST",
  66. "CHIINV",
  67. "CHITEST",
  68. "CHISQ.DIST",
  69. "CHISQ.DIST.RT",
  70. "CHISQ.INV",
  71. "CHISQ.INV.RT",
  72. "CHISQ.TEST",
  73. "CHOOSE",
  74. "CLEAN",
  75. "CODE",
  76. "COLUMN",
  77. "COLUMNS",
  78. "COMBIN",
  79. "COMBINA",
  80. "COMPLEX",
  81. "CONCAT",
  82. "CONCATENATE",
  83. "CONFIDENCE",
  84. "CONFIDENCE.NORM",
  85. "CONFIDENCE.T",
  86. "CONVERT",
  87. "CORREL",
  88. "COS",
  89. "COSH",
  90. "COT",
  91. "COTH",
  92. "COUNT",
  93. "COUNTA",
  94. "COUNTBLANK",
  95. "COUNTIF",
  96. "COUNTIFS",
  97. "COUPDAYBS",
  98. "COUPDAYS",
  99. "COUPDAYSNC",
  100. "COUPNCD",
  101. "COUPNUM",
  102. "COUPPCD",
  103. "COVAR",
  104. "COVARIANCE.P",
  105. "COVARIANCE.S",
  106. "CRITBINOM",
  107. "CSC",
  108. "CSCH",
  109. "CUBEKPIMEMBER",
  110. "CUBEMEMBER",
  111. "CUBEMEMBERPROPERTY",
  112. "CUBERANKEDMEMBER",
  113. "CUBESET",
  114. "CUBESETCOUNT",
  115. "CUBEVALUE",
  116. "CUMIPMT",
  117. "CUMPRINC",
  118. "DATE",
  119. "DATEDIF",
  120. "DATEVALUE",
  121. "DAVERAGE",
  122. "DAY",
  123. "DAYS",
  124. "DAYS360",
  125. "DB",
  126. "DBCS",
  127. "DCOUNT",
  128. "DCOUNTA",
  129. "DDB",
  130. "DEC2BIN",
  131. "DEC2HEX",
  132. "DEC2OCT",
  133. "DECIMAL",
  134. "DEGREES",
  135. "DELTA",
  136. "DEVSQ",
  137. "DGET",
  138. "DISC",
  139. "DMAX",
  140. "DMIN",
  141. "DOLLAR",
  142. "DOLLARDE",
  143. "DOLLARFR",
  144. "DPRODUCT",
  145. "DSTDEV",
  146. "DSTDEVP",
  147. "DSUM",
  148. "DURATION",
  149. "DVAR",
  150. "DVARP",
  151. "EDATE",
  152. "EFFECT",
  153. "ENCODEURL",
  154. "EOMONTH",
  155. "ERF",
  156. "ERF.PRECISE",
  157. "ERFC",
  158. "ERFC.PRECISE",
  159. "ERROR.TYPE",
  160. "EUROCONVERT",
  161. "EVEN",
  162. "EXACT",
  163. "EXP",
  164. "EXPON.DIST",
  165. "EXPONDIST",
  166. "FACT",
  167. "FACTDOUBLE",
  168. "FALSE|0",
  169. "F.DIST",
  170. "FDIST",
  171. "F.DIST.RT",
  172. "FILTERXML",
  173. "FIND",
  174. "FINDB",
  175. "F.INV",
  176. "F.INV.RT",
  177. "FINV",
  178. "FISHER",
  179. "FISHERINV",
  180. "FIXED",
  181. "FLOOR",
  182. "FLOOR.MATH",
  183. "FLOOR.PRECISE",
  184. "FORECAST",
  185. "FORECAST.ETS",
  186. "FORECAST.ETS.CONFINT",
  187. "FORECAST.ETS.SEASONALITY",
  188. "FORECAST.ETS.STAT",
  189. "FORECAST.LINEAR",
  190. "FORMULATEXT",
  191. "FREQUENCY",
  192. "F.TEST",
  193. "FTEST",
  194. "FV",
  195. "FVSCHEDULE",
  196. "GAMMA",
  197. "GAMMA.DIST",
  198. "GAMMADIST",
  199. "GAMMA.INV",
  200. "GAMMAINV",
  201. "GAMMALN",
  202. "GAMMALN.PRECISE",
  203. "GAUSS",
  204. "GCD",
  205. "GEOMEAN",
  206. "GESTEP",
  207. "GETPIVOTDATA",
  208. "GROWTH",
  209. "HARMEAN",
  210. "HEX2BIN",
  211. "HEX2DEC",
  212. "HEX2OCT",
  213. "HLOOKUP",
  214. "HOUR",
  215. "HYPERLINK",
  216. "HYPGEOM.DIST",
  217. "HYPGEOMDIST",
  218. "IF",
  219. "IFERROR",
  220. "IFNA",
  221. "IFS",
  222. "IMABS",
  223. "IMAGINARY",
  224. "IMARGUMENT",
  225. "IMCONJUGATE",
  226. "IMCOS",
  227. "IMCOSH",
  228. "IMCOT",
  229. "IMCSC",
  230. "IMCSCH",
  231. "IMDIV",
  232. "IMEXP",
  233. "IMLN",
  234. "IMLOG10",
  235. "IMLOG2",
  236. "IMPOWER",
  237. "IMPRODUCT",
  238. "IMREAL",
  239. "IMSEC",
  240. "IMSECH",
  241. "IMSIN",
  242. "IMSINH",
  243. "IMSQRT",
  244. "IMSUB",
  245. "IMSUM",
  246. "IMTAN",
  247. "INDEX",
  248. "INDIRECT",
  249. "INFO",
  250. "INT",
  251. "INTERCEPT",
  252. "INTRATE",
  253. "IPMT",
  254. "IRR",
  255. "ISBLANK",
  256. "ISERR",
  257. "ISERROR",
  258. "ISEVEN",
  259. "ISFORMULA",
  260. "ISLOGICAL",
  261. "ISNA",
  262. "ISNONTEXT",
  263. "ISNUMBER",
  264. "ISODD",
  265. "ISREF",
  266. "ISTEXT",
  267. "ISO.CEILING",
  268. "ISOWEEKNUM",
  269. "ISPMT",
  270. "JIS",
  271. "KURT",
  272. "LARGE",
  273. "LCM",
  274. "LEFT",
  275. "LEFTB",
  276. "LEN",
  277. "LENB",
  278. "LINEST",
  279. "LN",
  280. "LOG",
  281. "LOG10",
  282. "LOGEST",
  283. "LOGINV",
  284. "LOGNORM.DIST",
  285. "LOGNORMDIST",
  286. "LOGNORM.INV",
  287. "LOOKUP",
  288. "LOWER",
  289. "MATCH",
  290. "MAX",
  291. "MAXA",
  292. "MAXIFS",
  293. "MDETERM",
  294. "MDURATION",
  295. "MEDIAN",
  296. "MID",
  297. "MIDBs",
  298. "MIN",
  299. "MINIFS",
  300. "MINA",
  301. "MINUTE",
  302. "MINVERSE",
  303. "MIRR",
  304. "MMULT",
  305. "MOD",
  306. "MODE",
  307. "MODE.MULT",
  308. "MODE.SNGL",
  309. "MONTH",
  310. "MROUND",
  311. "MULTINOMIAL",
  312. "MUNIT",
  313. "N",
  314. "NA",
  315. "NEGBINOM.DIST",
  316. "NEGBINOMDIST",
  317. "NETWORKDAYS",
  318. "NETWORKDAYS.INTL",
  319. "NOMINAL",
  320. "NORM.DIST",
  321. "NORMDIST",
  322. "NORMINV",
  323. "NORM.INV",
  324. "NORM.S.DIST",
  325. "NORMSDIST",
  326. "NORM.S.INV",
  327. "NORMSINV",
  328. "NOT",
  329. "NOW",
  330. "NPER",
  331. "NPV",
  332. "NUMBERVALUE",
  333. "OCT2BIN",
  334. "OCT2DEC",
  335. "OCT2HEX",
  336. "ODD",
  337. "ODDFPRICE",
  338. "ODDFYIELD",
  339. "ODDLPRICE",
  340. "ODDLYIELD",
  341. "OFFSET",
  342. "OR",
  343. "PDURATION",
  344. "PEARSON",
  345. "PERCENTILE.EXC",
  346. "PERCENTILE.INC",
  347. "PERCENTILE",
  348. "PERCENTRANK.EXC",
  349. "PERCENTRANK.INC",
  350. "PERCENTRANK",
  351. "PERMUT",
  352. "PERMUTATIONA",
  353. "PHI",
  354. "PHONETIC",
  355. "PI",
  356. "PMT",
  357. "POISSON.DIST",
  358. "POISSON",
  359. "POWER",
  360. "PPMT",
  361. "PRICE",
  362. "PRICEDISC",
  363. "PRICEMAT",
  364. "PROB",
  365. "PRODUCT",
  366. "PROPER",
  367. "PV",
  368. "QUARTILE",
  369. "QUARTILE.EXC",
  370. "QUARTILE.INC",
  371. "QUOTIENT",
  372. "RADIANS",
  373. "RAND",
  374. "RANDBETWEEN",
  375. "RANK.AVG",
  376. "RANK.EQ",
  377. "RANK",
  378. "RATE",
  379. "RECEIVED",
  380. "REGISTER.ID",
  381. "REPLACE",
  382. "REPLACEB",
  383. "REPT",
  384. "RIGHT",
  385. "RIGHTB",
  386. "ROMAN",
  387. "ROUND",
  388. "ROUNDDOWN",
  389. "ROUNDUP",
  390. "ROW",
  391. "ROWS",
  392. "RRI",
  393. "RSQ",
  394. "RTD",
  395. "SEARCH",
  396. "SEARCHB",
  397. "SEC",
  398. "SECH",
  399. "SECOND",
  400. "SERIESSUM",
  401. "SHEET",
  402. "SHEETS",
  403. "SIGN",
  404. "SIN",
  405. "SINH",
  406. "SKEW",
  407. "SKEW.P",
  408. "SLN",
  409. "SLOPE",
  410. "SMALL",
  411. "SQL.REQUEST",
  412. "SQRT",
  413. "SQRTPI",
  414. "STANDARDIZE",
  415. "STDEV",
  416. "STDEV.P",
  417. "STDEV.S",
  418. "STDEVA",
  419. "STDEVP",
  420. "STDEVPA",
  421. "STEYX",
  422. "SUBSTITUTE",
  423. "SUBTOTAL",
  424. "SUM",
  425. "SUMIF",
  426. "SUMIFS",
  427. "SUMPRODUCT",
  428. "SUMSQ",
  429. "SUMX2MY2",
  430. "SUMX2PY2",
  431. "SUMXMY2",
  432. "SWITCH",
  433. "SYD",
  434. "T",
  435. "TAN",
  436. "TANH",
  437. "TBILLEQ",
  438. "TBILLPRICE",
  439. "TBILLYIELD",
  440. "T.DIST",
  441. "T.DIST.2T",
  442. "T.DIST.RT",
  443. "TDIST",
  444. "TEXT",
  445. "TEXTJOIN",
  446. "TIME",
  447. "TIMEVALUE",
  448. "T.INV",
  449. "T.INV.2T",
  450. "TINV",
  451. "TODAY",
  452. "TRANSPOSE",
  453. "TREND",
  454. "TRIM",
  455. "TRIMMEAN",
  456. "TRUE|0",
  457. "TRUNC",
  458. "T.TEST",
  459. "TTEST",
  460. "TYPE",
  461. "UNICHAR",
  462. "UNICODE",
  463. "UPPER",
  464. "VALUE",
  465. "VAR",
  466. "VAR.P",
  467. "VAR.S",
  468. "VARA",
  469. "VARP",
  470. "VARPA",
  471. "VDB",
  472. "VLOOKUP",
  473. "WEBSERVICE",
  474. "WEEKDAY",
  475. "WEEKNUM",
  476. "WEIBULL",
  477. "WEIBULL.DIST",
  478. "WORKDAY",
  479. "WORKDAY.INTL",
  480. "XIRR",
  481. "XNPV",
  482. "XOR",
  483. "YEAR",
  484. "YEARFRAC",
  485. "YIELD",
  486. "YIELDDISC",
  487. "YIELDMAT",
  488. "Z.TEST",
  489. "ZTEST"
  490. ];
  491. return {
  492. name: 'Excel formulae',
  493. aliases: [
  494. 'xlsx',
  495. 'xls'
  496. ],
  497. case_insensitive: true,
  498. keywords: {
  499. $pattern: /[a-zA-Z][\w\.]*/,
  500. built_in: BUILT_INS
  501. },
  502. contains: [
  503. {
  504. /* matches a beginning equal sign found in Excel formula examples */
  505. begin: /^=/,
  506. end: /[^=]/,
  507. returnEnd: true,
  508. illegal: /=/, /* only allow single equal sign at front of line */
  509. relevance: 10
  510. },
  511. /* technically, there can be more than 2 letters in column names, but this prevents conflict with some keywords */
  512. {
  513. /* matches a reference to a single cell */
  514. className: 'symbol',
  515. begin: /\b[A-Z]{1,2}\d+\b/,
  516. end: /[^\d]/,
  517. excludeEnd: true,
  518. relevance: 0
  519. },
  520. {
  521. /* matches a reference to a range of cells */
  522. className: 'symbol',
  523. begin: /[A-Z]{0,2}\d*:[A-Z]{0,2}\d*/,
  524. relevance: 0
  525. },
  526. hljs.BACKSLASH_ESCAPE,
  527. hljs.QUOTE_STRING_MODE,
  528. {
  529. className: 'number',
  530. begin: hljs.NUMBER_RE + '(%)?',
  531. relevance: 0
  532. },
  533. /* Excel formula comments are done by putting the comment in a function call to N() */
  534. hljs.COMMENT(/\bN\(/, /\)/,
  535. {
  536. excludeBegin: true,
  537. excludeEnd: true,
  538. illegal: /\n/
  539. })
  540. ]
  541. };
  542. }
  543. export { excel as default };