How do i reopen a Report which is created with a word tamplate and fill specific holes

3 ビュー (過去 30 日間)
Lukas
Lukas 2024 年 4 月 3 日
コメント済み: Tiffany 2024 年 4 月 5 日
if app.Pushbutton.Value
import mlreportgen.dom.*;
D = mlreportgen.dom.Document("Report", "docx", "Report_Template.dotx"); % Template with Rich Text elements
open(D);
while ~strcmp(D.CurrentHoleId,'5')
switch D.CurrentHoleId
case '1'
append(D, num2str(10)); % Example for Number value
case '2'
append(D, num2str(12));
case '3'
append(D, Text);
case '4'
append(D, Text2);
end
moveToNextHole(D);
end
close(D);
end
Unable to resolve the name 'app.Pushbutton.Value'.
%% It works well up to here
if app.Pushbutton2.Value
import mlreportgen.dom.*;
open(D);
while true
if strcmp(D.CurrentHoleId, '5')
break;
end
moveToNextHole(D);
end
while ~strcmp(D.CurrentHoleId, '7')
switch D.CurrentHoleId
case '5'
append(D, Text3);
case '6'
append(D, Text4);
end
moveToNextHole(D);
end
close(D);
end
Hello,
i use appDesigner and i want to add content to a report, which is created with a word template. The content should be added when you press a pushbutton in app designer. So in the Template are rich text elements with sequential numbers from 1 to in this case 7 (CurrentHoleId s). My code works fine until i want to reopen it. First i tryed to not closing it until the next pushbutton request but that didnt work.
How can i solve this problem? Thank you.
Best Regards
Lukas Rackl
  5 件のコメント
Lukas
Lukas 2024 年 4 月 5 日
Adding the variable "D" to the private property doesnt work either for the open(D) and close(D) per Callback function. In this case i get the following error message:
"Unable to reopen a closed document or document part."
But it does work with not closing the Document between the if-functions of the different pushbutton callback functions. So thank you for your tipp.
Tiffany
Tiffany 2024 年 4 月 5 日
Hi Lukas,
According to the MathWorks Documentation for close, "Once a document is closed, you can no longer append content to it. Closing the document outputs any remaining content, such as remaining template text." This is the reason why you encounter an error message when trying to use open on a closed document. Here is the documentation link for "close": https://www.mathworks.com/help/rptgen/ug/mlreportgen.dom.document.close.html.

サインインしてコメントする。

回答 (0 件)

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by