Editing the format of a chart title in excel through actxserver
I have been trying to work out how to underscore a section of a chart title string in an existing chart in excel through actxserver. I would typically use invoke to format strings in excel cells, but I can’t use that approach in chart titles.
In the code below I am replacing a section of the title string, which has a portion already underscored. This automically underscoes the whole title for some reason, which I then remove and try to underscore just the section that was already underscored.
If anyone has a solution it would be much appreciated. I have tried different LLMs, but this is the method they suggest. Which should work based on excel VBA. Possibly this is just not supported in Matlab?
Example of editing characters in a chart title that doesn’t work.
excel = actxserver(‘Excel.Application’);
file = excel.Workbooks.Open("ABC.xlsx");
Sheet = excel.Worksheets.Item(‘ABC’);
ChartObjects = Sheet.ChartObjects;
chart = ChartObjects.Item(1).Chart; % Selecting chart
s = chart.ChartTitle.Text; % find current chart title
chart.ChartTitle.Text = strrep(s, OldWord, NewWord); % Replace key word in chart title
chart.ChartTitle.Characters.Font.Underline = 0; % Removing all underscored characters
pos = strfind(s, ‘-‘); % finding end of region to underline
% Works up to this last line
chart.ChartTitle.Characters(1, pos(1)-2).Font.Underline = 2; % Underscoring desired region
Example for editing a string in a excel cell that works.
Range = get(Sheet,’Range’, ‘A1’);
Range.Value = {‘(Test Area = 21.65 cm2)’};
Chars = invoke(Range,’Characters’,22,1); % Selecting character range within cell starting at character 22 and continuing for 1 length
Chars.Font.Superscript = ‘true’; % Seting selected character to supersciptI have been trying to work out how to underscore a section of a chart title string in an existing chart in excel through actxserver. I would typically use invoke to format strings in excel cells, but I can’t use that approach in chart titles.
In the code below I am replacing a section of the title string, which has a portion already underscored. This automically underscoes the whole title for some reason, which I then remove and try to underscore just the section that was already underscored.
If anyone has a solution it would be much appreciated. I have tried different LLMs, but this is the method they suggest. Which should work based on excel VBA. Possibly this is just not supported in Matlab?
Example of editing characters in a chart title that doesn’t work.
excel = actxserver(‘Excel.Application’);
file = excel.Workbooks.Open("ABC.xlsx");
Sheet = excel.Worksheets.Item(‘ABC’);
ChartObjects = Sheet.ChartObjects;
chart = ChartObjects.Item(1).Chart; % Selecting chart
s = chart.ChartTitle.Text; % find current chart title
chart.ChartTitle.Text = strrep(s, OldWord, NewWord); % Replace key word in chart title
chart.ChartTitle.Characters.Font.Underline = 0; % Removing all underscored characters
pos = strfind(s, ‘-‘); % finding end of region to underline
% Works up to this last line
chart.ChartTitle.Characters(1, pos(1)-2).Font.Underline = 2; % Underscoring desired region
Example for editing a string in a excel cell that works.
Range = get(Sheet,’Range’, ‘A1’);
Range.Value = {‘(Test Area = 21.65 cm2)’};
Chars = invoke(Range,’Characters’,22,1); % Selecting character range within cell starting at character 22 and continuing for 1 length
Chars.Font.Superscript = ‘true’; % Seting selected character to superscipt I have been trying to work out how to underscore a section of a chart title string in an existing chart in excel through actxserver. I would typically use invoke to format strings in excel cells, but I can’t use that approach in chart titles.
In the code below I am replacing a section of the title string, which has a portion already underscored. This automically underscoes the whole title for some reason, which I then remove and try to underscore just the section that was already underscored.
If anyone has a solution it would be much appreciated. I have tried different LLMs, but this is the method they suggest. Which should work based on excel VBA. Possibly this is just not supported in Matlab?
Example of editing characters in a chart title that doesn’t work.
excel = actxserver(‘Excel.Application’);
file = excel.Workbooks.Open("ABC.xlsx");
Sheet = excel.Worksheets.Item(‘ABC’);
ChartObjects = Sheet.ChartObjects;
chart = ChartObjects.Item(1).Chart; % Selecting chart
s = chart.ChartTitle.Text; % find current chart title
chart.ChartTitle.Text = strrep(s, OldWord, NewWord); % Replace key word in chart title
chart.ChartTitle.Characters.Font.Underline = 0; % Removing all underscored characters
pos = strfind(s, ‘-‘); % finding end of region to underline
% Works up to this last line
chart.ChartTitle.Characters(1, pos(1)-2).Font.Underline = 2; % Underscoring desired region
Example for editing a string in a excel cell that works.
Range = get(Sheet,’Range’, ‘A1’);
Range.Value = {‘(Test Area = 21.65 cm2)’};
Chars = invoke(Range,’Characters’,22,1); % Selecting character range within cell starting at character 22 and continuing for 1 length
Chars.Font.Superscript = ‘true’; % Seting selected character to superscipt actxserver, excel, chart title, underscore MATLAB Answers — New Questions









