Word Template Hole isn't plugged with the right value.
3 ビュー (過去 30 日間)
古いコメントを表示
I am generating reports using a Word template with Holes, each Hole has a different Title so Matlab knows which value to populate in which Hole-Title.
There is one Hole that is titled uniquely 'VST' but it keeps being populated with the value value that is affiliated with Title 'Phone'. If I move things around, then I can get the correct value assoicated with 'VST' to appear in the 'VST' Hole-Title, but then another Hole-Title is erroneously capturing the 'Phone' value again, or the 'VST' Hole-Title is capturing then some other erroneous value.
3 件のコメント
Image Analyst
2024 年 12 月 26 日
編集済み: Image Analyst
2024 年 12 月 26 日
How are you poking values into Word? Are you using ActiveXS on Windows? What operating system do you have? If you have any more questions, then attach your data and code to read it in, and poke to Word, and your Word template or document with the paperclip icon after you read this:
If you can boil it down to a small simple example, that would be good.
回答 (1 件)
Hitesh
2024 年 12 月 26 日
編集済み: Hitesh
2024 年 12 月 26 日
You need to use "Rich Text Content Control" to create hole present in Developer tab in Microsoft Word and save the template in dotx format. Additionally, use the "moveToNextHole" function to navigate to and activate the next placeholder. Kindly refer to the following code for replacing the hole with the right value.
import mlreportgen.dom.*;
% Load the Word template
templateFile = 'word_sample.dotx'; % Replace with your template file name
outputFile = 'outputReport.docx'; % Name of the output Word document
% Create a Word document based on the template
doc = Document(outputFile, 'docx', templateFile);
% Open the document
open(doc);
% Move to the first inline content control placeholder and replace it
moveToNextHole(doc);
VSTContent = Text('VST content.');
append(doc, VSTContent);
% Move to the next block content control placeholder and replace it
moveToNextHole(doc);
phone = Text('9898676565632');
append(doc, phone);
% Close and save the document
close(doc);
% Display the output document
rptview(outputFile);


For more information regarding " Holes in Microsoft Word", kindly refer to the below MATLAB documentation:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!