Word Template Hole isn't plugged with the right value.

39 visualizaciones (últimos 30 días)
Avihay
Avihay el 25 de Dic. de 2024 a las 13:28
Editada: Hitesh el 26 de Dic. de 2024 a las 18:59
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 comentarios
Hitesh
Hitesh el 26 de Dic. de 2024 a las 16:31
Could you share your files so that we can reproduce this issue ?
Image Analyst
Image Analyst el 26 de Dic. de 2024 a las 18:55
Editada: Image Analyst el 26 de Dic. de 2024 a las 18:55
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.

Iniciar sesión para comentar.

Respuestas (1)

Hitesh
Hitesh el 26 de Dic. de 2024 a las 18:58
Editada: Hitesh el 26 de Dic. de 2024 a las 18:59
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:

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by