Skip to content

Commit 73c6613

Browse files
committed
Merge over Yo Office custom functions template to Excel-Custom-Functions repo so we don't have two different repos
1 parent 52387c0 commit 73c6613

11 files changed

+189
-147
lines changed

Excel-Custom-Functions.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2121
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2222
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23-
SOFTWARE
23+
SOFTWARE

README.md

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,40 @@
11
# Custom functions in Excel (Preview)
22

3-
Custom functions (similar to user-defined functions, or UDFs) are JavaScript functions that you can add to Excel. This sample accompanies the [Custom Functions Overview](https://docs.microsoft.com/en-us/office/dev/add-ins/excel/custom-functions-overview) topic.
3+
Learn how to use custom functions in Excel (similar to user-defined functions, or UDFs). Custom functions are JavaScript functions that you can add to Excel, and then use them like any native Excel function (for example =Sum). This sample accompanies the [Custom Functions Overview](https://docs.microsoft.com/en-us/office/dev/add-ins/excel/custom-functions-overview) topic.
44

55
## Table of Contents
66
* [Change History](#change-history)
77
* [Prerequisites](#prerequisites)
88
* [To use the project](#to-use-the-project)
9-
* [Making changes](#making-changes)
10-
* [Debugging](#debugging)
11-
* [Intellisense for the JSON file in Visual Studio Code](#intellisense-for-the-json-file-in-visual-studio-code)
129
* [Questions and comments](#questions-and-comments)
1310
* [Additional resources](#additional-resources)
1411

1512
## Change History
1613

1714
* Oct 27, 2017: Initial version.
1815
* April 23, 2018: Revised and expanded.
19-
* May 7, 2018: Updated for the Build preview release of custom functions
16+
* June 1, 2018: Bug fixes.
2017

2118
## Prerequisites
2219

23-
* Install Office 2016 for Windows or Mac and join the [Office Insider](https://products.office.com/en-us/office-insider) program. You must also have Office build build 9325+ on Windows or 13.329+ on Mac.
20+
* Install Office 2016 for Windows and join the [Office Insider](https://products.office.com/en-us/office-insider) program. You must have Office build number 8711 or later.
2421

2522
## To use the project
2623

27-
Follow these instructions to use this custom function sample add-in:
24+
On a machine with a valid instance of an Excel Insider build installed, follow these instructions to use this custom function sample add-in:
2825

29-
1. Publish the code files (HTML, JS, and JSON) to localhost.
30-
2. Replace `http://127.0.0.1:8080` in the manifest file (there are 4 occurrences) with the URL you used, if needed (you might be using a different port number).
31-
3. Sideload the manifest using the instructions found at <https://aka.ms/sideload-addins>.
32-
4. Test a custom function by entering `=CONTOSO.ADD42` in a cell.
33-
5. Try the other functions in the sample: `=CONTOSO.ADD42ASYNC`, `CONTOSO.ISPRIME`, `CONTOSO.NTHPRIME`, `CONTOSO.GETDAY`, `CONTOSO.INCREMENTVALUE`, and `CONTOSO.SECONDHIGHEST`.
34-
7. Follow @OfficeDev on Twitter for updates, post suggestions to the [Excel Add-ins UserVoice page](https://officespdev.uservoice.com/forums/224641-feature-requests-and-feedback/category/163563-add-in-excel) and tag Stack Overflow questions with the [custom-functions-excel](https://stackoverflow.com/questions/tagged/custom-functions-excel) tag.
26+
1. On the machine where your custom functions project is installed, follow the instructions to install the self-signed certificates (https://github.com/OfficeDev/generator-office/blob/master/src/docs/ssl.md) .
27+
2. From a command prompt from within your custom functions project directory, run `npm run start` to start a localhost server instance.
28+
3. Run `npm run sideload` to launch Excel and load the custom functions add-in. Additonal information on sideloading can be found at <https://aka.ms/sideload-addins>.
29+
4. After Excel launches, you will need to register the custom-functions add-in to work around a bug:
30+
a. On the upper-left-hand side of Excel, there is a small hexagon icon with a dropdown arrow. The icon is to right of the Save icon.
31+
b. Click on this dropdown arrow and then click on the Custom Functions Sample add-in to register it.
32+
5. Test a custom function by entering `=CONTOSO.ADD42(num)` in a cell.
33+
6. Try the other functions in the sample: `=CONTOSO.ADD42ASYNC(num, num)`, `CONTOSO.ISPRIME(num)`, `CONTOSO.NTHPRIME(num)`, `CONTOSO.GETDAY()`, `CONTOSO.INCREMENTVALUE(increment)`, and `CONTOSO.SECONDHIGHEST(range)`.
34+
7. If you make changes to the sample add-in, copy the updated files to your website, and then close and reopen Excel. If your functions are not available in Excel, re-insert the add-in using **Insert** > **My Add-ins**.
35+
8. Follow @OfficeDev on Twitter for updates and send feedback to <[email protected]>.
3536

36-
## Making changes
37-
If you make changes to the sample functions code (in the JS file), close and reopen Excel to test them.
38-
39-
If you change the functions metadata (in the JSON file), close Excel and delete your cache folder `Users/<user>/AppData/Local/Microsoft/Office/16.0/Wef/CustomFunctions`. Then re-insert the add-in using **Insert** > **My Add-ins**.
40-
41-
## Debugging
42-
Debugging is only available for asynchronous functions on Excel for Windows currently. To debug:
43-
44-
1. Enable script debugging in Internet Explorer (IE > Options > Advanced).
45-
2. Trigger an asynchronous function in Excel (like `CONTOSO.ADD42ASYNC`). This step ensures that the asynchronous function process is loaded invisibly and ready for debugging.
46-
3. Attach a debugger to the hidden iexplore.exe script process (you could use the [Windows F12 debugger](https://docs.microsoft.com/en-us/office/dev/add-ins/testing/debug-add-ins-using-f12-developer-tools-on-windows-10) or Visual Studio).
47-
48-
## Intellisense for the JSON file in Visual Studio Code
49-
For intellisense to help you edit the JSON file, follow these steps:
50-
51-
1. Open the JSON file (it has a .json extension) in Visual Studio Code.
52-
2. If you are starting a new file from scratch, add the following to the top of the file:
53-
54-
```js
55-
{
56-
"$schema": "https://developer.microsoft.com/en-us/json-schemas/office-js/custom-functions.schema.json",
57-
```
58-
3. Press **Ctrl+Space** and intellisense will prompt you with a list of all items that are valid at the cursor point. For example, if you pressed **Ctrl+Space** immediately after the `"$schema"` line, you are prompted to enter `functions`, which is the only key that is valid at that point. Select it and the `"functions": []` array is entered. If the cursor is between the `[]`, then you are prompted to enter an empty object as a member of the array. If the cursor is in the object, then you are prompted with a list of the keys that are valid in the object.
59-
60-
## Feedback
37+
## Questions and comments
6138

6239
We'd love to get your feedback about this sample. You can send your feedback to us in the *Issues* section of this repository.
6340

@@ -72,4 +49,4 @@ Questions about Microsoft Office 365 development in general should be posted to
7249
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information, see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
7350

7451
## Copyright
75-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
52+
Copyright (c) 2017 Microsoft Corporation. All rights reserved.

customfunctions.json renamed to config/customfunctions.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
2+
"$schema": "https://developer.microsoft.com/en-us/json-schemas/office-js/custom-functions.schema.json",
23
"functions": [
34
{
4-
"name": "ADD42",
5+
"name": "ADD42",
56
"description": "adds 42 to the input numbers",
67
"helpUrl": "http://dev.office.com",
78
"result": {
@@ -97,6 +98,7 @@
9798
"description": "gets the current day of the week",
9899
"helpUrl": "http://dev.office.com",
99100
"result": {
101+
"dimensionality": "scalar",
100102
"type": "string"
101103
},
102104
"parameters": [],

customfunctions.xml renamed to config/manifest.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
55
xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides"
66
xsi:type="TaskPaneApp">
7-
<Id>b12101b4-2706-4128-98b2-d8a1842131a3</Id>
7+
<Id>b12101b1-2706-4128-98b2-d6a1842131a3</Id>
88
<Version>1.0.0.0</Version>
99
<ProviderName>Contoso</ProviderName>
1010
<DefaultLocale>en-US</DefaultLocale>
11-
<DisplayName DefaultValue="Custom Functions Sample" />
11+
<DisplayName DefaultValue="<%= projectDisplayName %>" />
1212
<Description DefaultValue="Samples to test custom functions" />
1313
<Hosts>
1414
<Host Name="Workbook" />
1515
</Hosts>
1616
<DefaultSettings>
17-
<SourceLocation DefaultValue="http://127.0.0.1:8080/customfunctions.html"/>
17+
<SourceLocation DefaultValue="https://localhost:3000/index.html"/>
1818
</DefaultSettings>
1919
<Permissions>ReadWriteDocument</Permissions>
2020
<VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
@@ -38,9 +38,9 @@
3838
</Hosts>
3939
<Resources>
4040
<bt:Urls>
41-
<bt:Url id="JSON-URL" DefaultValue="http://127.0.0.1:8080/customfunctions.json" />
42-
<bt:Url id="JS-URL" DefaultValue="http://127.0.0.1:8080/customfunctions.js" />
43-
<bt:Url id="HTML-URL" DefaultValue="http://127.0.0.1:8080/customfunctions.html" />
41+
<bt:Url id="JSON-URL" DefaultValue="https://localhost:3000/config/customfunctions.json" />
42+
<bt:Url id="JS-URL" DefaultValue="https://localhost:3000/src/customfunctions.js" />
43+
<bt:Url id="HTML-URL" DefaultValue="https://localhost:3000/index.html" />
4444
</bt:Urls>
4545
<bt:ShortStrings>
4646
<bt:String id="namespace" DefaultValue="CONTOSO" />

config/web.config

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<system.webServer>
4+
<httpProtocol>
5+
<customHeaders>
6+
<add name="Access-Control-Allow-Origin" value="*" />
7+
</customHeaders>
8+
</httpProtocol>
9+
</system.webServer>
10+
</configuration>

config/webpack.config.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const HtmlWebpackPlugin = require('html-webpack-plugin');
2+
3+
module.exports = {
4+
entry: {
5+
customfunctions: ["./src/customfunctions.js"],
6+
},
7+
resolve: {
8+
extensions: ['.ts', '.tsx', '.html', '.js']
9+
},
10+
module: {
11+
rules: [
12+
{
13+
test: /\.tsx?$/,
14+
exclude: /node_modules/,
15+
use: 'ts-loader'
16+
},
17+
{
18+
test: /\.html$/,
19+
exclude: /node_modules/,
20+
use: 'html-loader'
21+
},
22+
{
23+
test: /\.(png|jpg|jpeg|gif)$/,
24+
use: 'file-loader'
25+
}
26+
]
27+
},
28+
plugins: [
29+
new HtmlWebpackPlugin({
30+
template: './index.html',
31+
chunks: ['customfunctions']
32+
})
33+
],
34+
devServer: {
35+
port: 3000,
36+
hot: true,
37+
inline: true,
38+
headers: {
39+
"Access-Control-Allow-Origin": "*"
40+
}
41+
}
42+
};

customfunctions.js

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
<!DOCTYPE html>
2-
<html>
2+
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
55
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
6-
<meta http-equiv="Expires" content="0" />
7-
<title></title>
6+
<title>custom-functions-preview</title>
87
<script src="https://unpkg.com/@microsoft/office-js@custom-functions-preview/dist/office.js" type="text/javascript"></script>
9-
10-
<script src="customfunctions.js" type="text/javascript"></script>
8+
<script src="src/customfunctions.js" type="text/javascript"></script>
119
<script type="text/javascript">
12-
(function () {
13-
"use strict";
14-
Office.initialize = function (reason) {
15-
return Excel.CustomFunctions.initialize();
16-
};
17-
})();
10+
Office.Preview.startCustomFunctions();
1811
</script>
1912
</head>
2013
<body>
@@ -27,8 +20,10 @@
2720
<li><b>=CONTOSO.NTHPRIME</b> returns the Nth prime. Watch out - it needs a lot of calculation if N is big!</li>
2821
<li><b>=CONTOSO.GETDAY</b> returns the current day of the week as a string.</li>
2922
<li><b>=CONTOSO.SECONDHIGHEST</b> lets you select a range of data and finds the second highest number.</li>
23+
<li><b>=CONTOSO.INCREMENTVALUE</b> increments the value by the number specified.</li>
3024
</ul>
31-
To change the functions, edit <b>customfunctions.js</b> and <b>customfunctions.json</b>. To change the prefix, edit <b>customfunctions.xml</b>.
25+
To change the functions, edit <b>src/customfunctions.js</b> and <b>config/customfunctions.json</b>. To change the prefix, edit <b>config/<%= projectDisplayName %>-manifest.xml</b>.
3226
For more information, see <a href=https://aka.ms/customfunctions>https://aka.ms/customfunctions</a>.
3327
</body>
3428
</html>
29+

package.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "excel-custom-functions",
3+
"version": "1.0.0",
4+
"description": "Create Excel functions using JavaScript.",
5+
"main": "customfunctions.js",
6+
"scripts": {
7+
"start": "webpack-dev-server --mode development --https --key ./certs/server.key --cert ./certs/server.crt --cacert ./certs/ca.crt --port 3000 --hot --inline",
8+
"sideload": "office-toolbox sideload -m ./config/<%= projectDisplayName %>-manifest.xml -a Excel",
9+
"test": "echo \"Error: no test specified\" && exit 1"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/OfficeDev/Excel-Custom-Functions.git"
14+
},
15+
"author": "",
16+
"license": "ISC",
17+
"bugs": {
18+
"url": "https://github.com/OfficeDev/Excel-Custom-Functions/issues"
19+
},
20+
"homepage": "https://github.com/OfficeDev/Excel-Custom-Functions#readme",
21+
"devDependencies": {
22+
"typescript": "^2.8.1",
23+
"office-toolbox": "^0.1.0",
24+
"@types/office-js": "^0.0.37",
25+
"@types/jquery": "^2.0.39",
26+
"file-loader": "^1.1.11",
27+
"html-loader": "^0.5.5",
28+
"html-webpack-plugin": "^3.0.7",
29+
"office-addin-validator": "^1.0.1",
30+
"ts-loader": "^4.1.0",
31+
"webpack": "^4.1.1",
32+
"webpack-cli": "^2.0.12",
33+
"webpack-dev-server": "^3.1.1"
34+
}
35+
}

0 commit comments

Comments
 (0)