-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for Excel formula (#2219)
This adds support for Excel's formula terms.
- Loading branch information
1 parent
1e3070a
commit bf4f7bf
Showing
17 changed files
with
422 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
Prism.languages['excel-formula'] = { | ||
'comment': { | ||
pattern: /(\bN\(\s*)"(?:[^"]|"")*"(?=\s*\))/i, | ||
lookbehind: true, | ||
greedy: true | ||
}, | ||
'string': { | ||
pattern: /"(?:[^"]|"")*"(?!")/, | ||
greedy: true | ||
}, | ||
'reference': { | ||
// https://www.ablebits.com/office-addins-blog/2015/12/08/excel-reference-another-sheet-workbook/ | ||
|
||
// Sales!B2 | ||
// 'Winter sales'!B2 | ||
// [Sales.xlsx]Jan!B2:B5 | ||
// D:\Reports\[Sales.xlsx]Jan!B2:B5 | ||
// '[Sales.xlsx]Jan sales'!B2:B5 | ||
// 'D:\Reports\[Sales.xlsx]Jan sales'!B2:B5 | ||
|
||
pattern: /(?:'[^']*'|(?:[^\s()[\]{}<>*?"';,$&]*\[[^^\s()[\]{}<>*?"']+\])?\w+)!/, | ||
greedy: true, | ||
alias: 'string', | ||
inside: { | ||
'operator': /!$/, | ||
'punctuation': /'/, | ||
'sheet': { | ||
pattern: /[^[\]]+$/, | ||
alias: 'function' | ||
}, | ||
'file': { | ||
pattern: /\[[^[\]]+\]$/, | ||
inside: { | ||
'punctuation': /[[\]]/ | ||
} | ||
}, | ||
'path': /[\s\S]+/ | ||
} | ||
}, | ||
'function-name': { | ||
pattern: /[A-Z]\w*(?=\()/i, | ||
alias: 'keyword' | ||
}, | ||
'range': { | ||
pattern: /\$?(?:[A-Z]+\$?\d+:\$?[A-Z]+\$?\d+|[A-Z]+:\$?[A-Z]+|\d+:\$?\d+)/i, | ||
alias: 'property', | ||
inside: { | ||
'operator': /:/, | ||
'cell': /\$?[A-Z]+\$?\d+/i, | ||
'column': /\$?[A-Z]+/i, | ||
'row': /\$?\d+/ | ||
} | ||
}, | ||
'cell': { | ||
// Excel is case insensitive, so the string "foo1" could be either a variable or a cell. | ||
// To combat this, we match cells case insensitive, if the contain at least one "$", and case sensitive otherwise. | ||
pattern: /[A-Z]+\d+|\$[A-Za-z]+\$?\d+|[A-Za-z]+\$\d+/, | ||
alias: 'property' | ||
}, | ||
'number': /(?:\b\d+(?:\.\d+)?|\B\.\d+)(?:e[+-]?\d+)?\b/i, | ||
'boolean': /\b(?:TRUE|FALSE)\b/i, | ||
'operator': /[-+*/^%=&,]|<[=>]?|>=?/, | ||
'punctuation': /[[\]();{}|]/ | ||
}; | ||
|
||
Prism.languages['xlsx'] = Prism.languages['xls'] = Prism.languages['excel-formula']; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<h2>Full example</h2> | ||
<pre><code>=SUM(G7*9) | ||
=INT(RAND()*999) | ||
=AVERAGE(A4:A13)+N("Average user rating") | ||
=CONCATENATE(F4, ",", " ", G4," ",H4) | ||
=IF($A4>500, $A4, 0) | ||
=AND($B4>=501,$C4<=500) | ||
=SUBTOTAL(103,staff[Name]) | ||
=TRIMMEAN(staff[Salary],10%) | ||
=SUM([Sales.xlsx]Jan!B2:B5)</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
B1 | ||
BBB1111 | ||
|
||
$B2 | ||
B$2 | ||
$B$2 | ||
|
||
$b2 | ||
b$2 | ||
$b$2 | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["cell", "B1"], | ||
["cell", "BBB1111"], | ||
["cell", "$B2"], | ||
["cell", "B$2"], | ||
["cell", "$B$2"], | ||
["cell", "$b2"], | ||
["cell", "b$2"], | ||
["cell", "$b$2"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for cells. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
SUM() | ||
FOO() | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["function-name", "SUM"], | ||
["punctuation", "("], | ||
["punctuation", ")"], | ||
["function-name", "FOO"], | ||
["punctuation", "("], | ||
["punctuation", ")"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for functions. |
Oops, something went wrong.