Package Excel Add-In with Library Compiler App

This example shows how to create a Microsoft® Excel® add-in that computes a magic square using the Library Compiler app. The example uses a MATLAB® function, mymagic, which computes a magic square. You can use this example as a template for deploying functions with no output, scalar output, or multidimensional matrix output.

You can find the code for mymagic.m in the matlabroot\toolbox\matlabxl\examples\xlmagic folder. To deploy your code, move your example code to a new working folder.

Create Function in MATLAB

Examine the MATLAB code to deploy as an Excel add-in.

function y = mymagic(x)
% MYMAGIC Magic square of size x.
%   Y = MYMAGIC(X) returns a magic square of size x.
%   This file is used as an example for the MATLAB Compiler product.
%   Copyright 2001-2007 The MathWorks, Inc.
y = magic(x)

Verify that the example runs in MATLAB.

mymagic(5)
17 24  1  8 15
23  5  7 14 16
 4  6 13 20 22
10 12 19 21  3
11 18 25  2  9

Create Add-In Using Library Compiler App

Launch the Library Compiler app from the MATLAB command line.

libraryCompiler

You can also launch the Library Compiler app on the Apps tab in the Application Deployment section.

On the Compiler tab, in the Type section, select Excel Add-in.

To add the function, on the Compiler tab in the Exported Functions section, click plus to add the function. Browse and select function mymagic.m. The Library Compiler app uses the name of the file as the name of the deployment project file (.prj), shown in the title bar, and as the name of the add-in, shown in the first field of the Library information area. The project file stores the deployment settings so that you can reopen the project.

Modify the main body of the MATLAB Compiler™ project window as required.

  • Library Information — Information that you can add and modify about the deployed application.

  • Additional Installer Options — Default installation path for the generated installer.

  • Files required for your library to run — Additional files for the generated application that are part of the generated application installer.

  • Files installed for your end user — List of files installed with your application. These files include a Visual Basic® file, a DLL, an Excel add-in file, and a read me text file.

  • Additional Runtime Settings — Access to other compiler options.

To create an application installer, on the Compiler tab in the Packaging Options, select the Runtime downloaded from web. This option creates an application installer that automatically downloads the MATLAB Runtime and installs it along with the deployed add-in.

On the Compiler tab, click Package to build Excel add-in.

The Library Compiler app creates a log file PackagingLog.txt and three folders for redistribution and testing.

  • for_redistribution folder consists of the install file of the application. The install file will install the MATLAB Runtime and the application.

  • for_testing folder consists of all the artifacts created by mcc like binaries, jar files, header, and source files depending on the target. Use these files to test the installation.

  • for_redistribution_files_only folder is a subset of the testing folder files. The folder consists of the files required to redistribute the application.

See Also

Was this topic helpful?