www.gusucode.com > rptgen 工具箱matlab源码程序 > rptgen/editTemplate.m

    function editTemplate(id)
%EDITTEMPLATE Opens template in an editor
% editTemplate(id) opens template in an editor if it is not a builtin
% template.

% Copyright 2014 MathWorks, Inc.

cache = rptgen.db2dom.TemplateCache.getTheCache;

templatePath = getHTMLTemplate(cache, id);
if isempty(templatePath)
    templatePath = getDOCXTemplate(cache, id);
    if ~isempty(templatePath)
        if ~rptgen.db2dom.TemplateCache.isTemplateBuiltin(templatePath)
            mlreportgen.Word.openDoc(templatePath);
        else
            errordlg(getString(message('rptgen:r_coutline:builtinTemplateError')), ...
                getString(message('rptgen:r_coutline:editTemplateDialogTitle')));
        end
    else
        errordlg(getString(message('rptgen:r_coutline:templateNotFoundError', id)), ...
            getString(message('rptgen:r_coutline:editTemplateDialogTitle')));
    end
else
    if ~isempty(templatePath)
        if ~rptgen.db2dom.TemplateCache.isTemplateBuiltin(templatePath)
            [tParentDir, tName, ~] = fileparts(templatePath);
            tDir = fullfile(tParentDir, tName);
            
            if ~exist(tDir, 'dir')
                unzip(templatePath, tDir);
            end
            
            mainPart = mlreportgen.dom.Document.getOPCMainPart(templatePath, 'html');
            
            tDocPath = fullfile(tDir, mainPart);
            %
            editCmd = char(javaMethod('getEditHTMLCommand',...
                'com.mathworks.toolbox.rptgencore.tools.RptgenPrefsPanel',...
                tDocPath));
            
            % Launch the viewer
            evalin('base',editCmd);
        else
            errordlg(getString(message('rptgen:r_coutline:builtinTemplateError')), ...
                getString(message('rptgen:r_coutline:editTemplateDialogTitle')));
        end
    else
        errordlg(getString(message('rptgen:r_coutline:templateNotFoundError', id)), ...
            getString(message('rptgen:r_coutline:editTemplateDialogTitle')));
    end
end