Modify Chart in Word with actxserver
Ältere Kommentare anzeigen
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
Antworten (0)
Kategorien
Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!