Modify Chart in Word with actxserver

Hello everyone, I'm working on a word template file including chart that have been included from Excel. I'm willing to modify those charts. For now I'm able to find the corresponding chart using the caption. But whenever I modify the chart, it only show 1 point in (0,0) instead of the curve that was shown before.
I would appreciate any help on this !
Thanks in advance
WordApplication=actxserver('Word.Application')
Documents = WordApplication.Documents;
Documents.Open(fullSavefile);
Doc = Documents.Item(Documents.Count);
update_word_chart_by_caption(Doc, 'Caption Title',X,Y);
function update_word_chart_by_caption(Doc, captionText, xValues, yValues, warnings)
chartObj = find_chart_by_caption(Doc, captionText);
Chart = chartObj.Chart;
xValues = double(xValues(:))';
yValues = double(yValues(:))';
Series = Chart.SeriesCollection.Item(1);
Series.XValues = xValues;
Series.Values = yValues;
Chart.Refresh;
end
function chartObj = find_chart_by_caption(Doc, captionText)
chartObj = [];
Text_Margin_Search = 50; %Search in the following 50 characters
for i = 1:Doc.InlineShapes.Count
Item = Doc.InlineShapes.Item(i);
if Item.HasChart
afterStart = Item.Range.End;
afterEnd = min(Item.Range.End + Text_Margin_Search, Doc.Content.End);
txtAfter = char(Doc.Range(afterStart, afterEnd).Text);
aroundText = normalize_text(txtAfter);
if contains(aroundText, target)
chartObj = Item;
return;
end
end
end

2 comentarios

Torsten
Torsten hace alrededor de 1 hora
Why do you try to do this in MATLAB and not directly in Word ?
VINCENT
VINCENT hace alrededor de 1 hora
I have to do it many times (~100 times) and the X and Y values come from calculations, so it would be longer to save them as xlsx files and plot them.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Productos

Versión

R2018b

Preguntada:

el 5 de Ag. de 2026 a las 8:08

Comentada:

hace alrededor de 9 horas

Community Treasure Hunt

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

Start Hunting!

Translated by