Unable to Open Word Template After Compiling app into a Standalone Application
Show older comments
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
dpb
on 15 Jul 2026 at 18:05
Isn't the template in the same place either way?
Nicolas
on 15 Jul 2026 at 18:34
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.
Answers (1)
Ishan
on 21 Jul 2026 at 6:20
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.
Categories
Find more on Adding custom doc in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!