You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
4
4
5
5
## Table of Contents
6
6
*[Change History](#change-history)
7
7
*[Prerequisites](#prerequisites)
8
8
*[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)
12
9
*[Questions and comments](#questions-and-comments)
13
10
*[Additional resources](#additional-resources)
14
11
15
12
## Change History
16
13
17
14
* Oct 27, 2017: Initial version.
18
15
* 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.
20
17
21
18
## Prerequisites
22
19
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.
24
21
25
22
## To use the project
26
23
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:
28
25
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]>.
35
36
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:
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
61
38
62
39
We'd love to get your feedback about this sample. You can send your feedback to us in the *Issues* section of this repository.
63
40
@@ -72,4 +49,4 @@ Questions about Microsoft Office 365 development in general should be posted to
72
49
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.
73
50
74
51
## Copyright
75
-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
52
+
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
<li><b>=CONTOSO.NTHPRIME</b> returns the Nth prime. Watch out - it needs a lot of calculation if N is big!</li>
28
21
<li><b>=CONTOSO.GETDAY</b> returns the current day of the week as a string.</li>
29
22
<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>
30
24
</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>.
32
26
For more information, see <ahref=https://aka.ms/customfunctions>https://aka.ms/customfunctions</a>.
0 commit comments