Main Content

How MATLAB Compiler Excel Integration Works

With MATLAB® Compiler™, you create deployable add-ins from MATLAB code that run in Microsoft® Excel® applications. Use the Library Compiler app, compiler.build.excelAddIn, or mcc to convert MATLAB functions to methods of a class that you define. From this class, the compiler creates the Excel add-in.

MATLAB Compiler generates two primary artifacts from your MATLAB code: a COM component (.dll file) and a Visual Basic® for Applications (VBA) module file (.bas file). The compiler integrates the COM wrapper with the compiler-generated VBA code to create a Microsoft Excel add-in (.xla file), saving you considerable development resources and time.

COM is an acronym for Component Object Model, which is a Microsoft binary standard for object interoperability. COM components use a common integration architecture that provides a consistent model across multiple applications. All Microsoft Office applications support COM add-ins.

Each COM object exposes a class to the Visual Basic programming environment. The class contains a set of functions called methods. These methods correspond to the original MATLAB functions included in the project. MATLAB Compiler generated COM components contain a single class. This class provides the interface to the MATLAB functions that you add to the class at build time. The COM component provides a set of methods that wrap the MATLAB code and a DLL file.

The MATLAB Compiler generates supporting files. Include these supporting files when you package and distribute an application. Include MATLAB Runtime to access an entire library of MATLAB functions without needing a licensed copy of MATLAB.

For information about how MATLAB Compiler works, see How Does MATLAB Deploy Functions?.

To verify your MATLAB code or function can be deployed successfully, see Write Deployable MATLAB Code.

MATLAB Compiler Excel Add-In Limitations

Generated add-ins support the following function outputs:

  • No outputs

  • Figure (graphical) output

  • Scalar output

  • Multidimensional matrix output

MATLAB objects are not supported as inputs or outputs for compiled or deployed functions with MATLAB Compiler for Excel add-ins.

Next Steps

MATLAB Compiler includes several examples in addition to the magic square example. You can find these examples in matlabroot\toolbox\matlabxl\examples\. The following table identifies examples by folder:

For Example Files Relating To...Find Example Code in Folder...For Example Documentation See...
Magic Square Example xlmagicCreate Excel Add-In from MATLAB
Variable-Length Argument ExamplexlmultiCreate Macros from MATLAB Functions with Multiple Arguments
Calling Compiled MATLAB Functions from Microsoft ExcelxlbasicAssign Multiple MATLAB Functions to Excel Class
Spectral Analysis ExamplexlspectralBuild and Integrate Spectral Analysis Functions

The following topics detail some of the more common tasks you perform as you continue to develop your applications.

To:See:
Try more examples using the MATLAB Compiler

MATLAB Central. Set the Search field to File Exchange and search for one or more of the following:

  • InterpExcelDemo

  • MatrixMathExcelDemo

  • ExcelCurveFit

Learn how to write MATLAB code that is optimized for deploymentWrite Deployable MATLAB Code
Work with functions having graphical outputExecute Add-In and Graphical Function
Work with functions having variable inputs and outputCreate Macros from MATLAB Functions with Multiple Arguments
Create displayable dialog boxes and error messagesCreate Dialog Box and Error Message Macros
Troubleshoot common error messagesErrors and Solutions
Integrate your application into your enterprise environment by enhancing your application's generated Visual Basic codeIntegrate Components Using Visual Basic Application

Related Topics