Unable to Open Word Template After Compiling app into a Standalone Application

Hello, I created an application that opens a word template file with rich content fields that is populated by variables within matlab using the mlreportgen.dom module.
I open the document using the command below where TemplatePath is the directory of my template.
D=Document(Output_File,'docx',TemplatePath);
open(D);
On the web application side of code, I am running a script that detects whether the application is packaged or not and retrieves the directory of the template file.
if isdeployed
% Compiled app
baseDir = ctfroot
else
% Running in MATLAB
baseDir = fileparts(mfilename('fullpath'));
end
TemplatePath = fullfile(baseDir, 'TemplateFile.dotx');
My concern is that the application runs fine without creating the standalone application. However, as soon as I try to package into a standalone application, the script above is unable to open the document and the application cannot finish.

3 Comments

Isn't the template in the same place either way?
Hi dpq,
From my understanding, when the application is packaged into a standalone application, the template is compiled into a application resources folder and the file directory changes for the template location. That is the reason why the template path is different depending on if the application is packaged as an app or running via matlab. I am currently having issues when the application is packaged as an app, and I try to open the word template as shown in the code above.
dpb
dpb on 15 Jul 2026 at 21:19
Edited: dpb on 16 Jul 2026 at 12:12
I've never built anything but compiled app, not web apps so don't really know -- I suppose the web side doesn't have access to the other location anyway? If it weren't prevented, that be the simple hack solution.
The way MATLAB does that for compiled apps also seemed really arcane and had some similar issues with an initial configuration file. After installation, I had to go locate where it actually did get installed and fix up the search path based on that; I never did get the builtins to work as advertised.
ADDENDUM
The other possibility is to ensure that the compiler actually did find the dependency and package the template file as an additional dependency.

Sign in to comment.

Answers (1)

The path selection logic using ctfroot appears reasonable for a deployed application. One thing I would verify is that the .dotx template is actually included in the application package, since files referenced only at runtime are not always detected automatically during dependency analysis.
In deployed mode, you can check whether the template exists before creating the Document object:
exist(TemplatePath,'file')
If the file is not found, add the template as an additional file when packaging the application and rebuild.
Since you are using MATLAB Report Generator in a standalone application, also ensure that your report-generation code has been prepared for compilation using:
makeDOMCompilable();
as described in the Report Generator deployment documentation.
If the template file exists under ctfroot, could you provide the exact error message returned by Document or open(D)? That would help determine whether the issue is related to locating the template or processing the template itself.

Products

Release

R2025b

Tags

Asked:

on 15 Jul 2026 at 16:27

Answered:

on 21 Jul 2026 at 6:20

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!