Hello
I working with Spire.Presentation package and I would like to know how can I get font from ChartLegend using C# code?
And can I switch it to another one?
I need to get font from this chart(Legend.jpg)
Jane.Bai wrote:Hello,
Thanks for your post.
In regards to your needs, please refer to the following article.
https://www.e-iceblue.com/Tutorials/Spire.Presentation/Spire.Presentation-Program-Guide/Chart/Set-font-for-the-text-on-Chart-legend-and-Chart-Axis-in-C.html
Sincerely,
Jane
E-iceblue support team
var font=chart.ChartLegend.TextProperties.Paragraphs[0].DefaultCharacterProperties.LatinFont;
Jane.Bai wrote:Hello,
There's a mistake with your code, please modify it like below.
- Code: Select all
var font=chart.ChartLegend.TextProperties.Paragraphs[0].DefaultCharacterProperties.LatinFont;
Sincerely,
Jane
E-iceblue support team
Jane.Bai wrote:Hello,
To help us look into it, please send your sample document to us.
Sincerely,
Jane
E-iceblue support team
Betsy.jiang wrote:Dear rokaf,
Thanks for your file.
After the initial investigation, I found that the legend didn't have any font set, you could check the screenshot. So the code Jane provided got null. I have posted your requirement to our Dev team, they will check if it could get any default font. Once there is any update, we will let you know.
Sincerely,
Betsy
E-iceblue support team
Betsy.jiang wrote:Dear rokaf,
Thanks for your file.
After the initial investigation, I found that the legend didn't have any font set, you could check the screenshot. So the code Jane provided got null. I have posted your requirement to our Dev team, they will check if it could get any default font. Once there is any update, we will let you know.
Sincerely,
Betsy
E-iceblue support team
Betsy.jiang wrote:Dear rokaf,
After further investigation, I am afraid that it is very difficult to get accurate font information at present, since the legend don't set any font, that means there is no font data for the legend in the file. Considering this case, we suggest setting corresponding font for the legend in MS PowerPoint and then use the code Jane provided to get the font information.
Sincerely,
Betsy
E-iceblue support team
var textParagraph = Chart.ChartLegend.TextProperties.Paragraphs[0];
public static Font GetFont(TextParagraph textParagraph)
{
return new Font(textParagraph.DefaultCharacterProperties.LatinFont.FontName, textParagraph.DefaultCharacterProperties.FontHeight, FontUtilities.GetFontStyle(textParagraph.DefaultCharacterProperties));
}
public static FontStyle GetFontStyle(TextCharacterProperties properties)
{
var enumResult = FontStyle.Regular;
if (properties.IsBold == TriState.True)
{
enumResult |= FontStyle.Bold;
}
if (properties.IsItalic == TriState.True)
{
enumResult |= FontStyle.Italic;
}
if (properties.TextUnderlineType != TextUnderlineType.None &&
properties.TextUnderlineType != TextUnderlineType.UnDefined)
{
enumResult |= FontStyle.Underline;
}
if (properties.TextStrikethroughType != TextStrikethroughType.None &&
properties.TextStrikethroughType != TextStrikethroughType.UnDefined)
{
enumResult |= FontStyle.Strikeout;
}
return enumResult;
}
Jane.Bai wrote:Hello,
Thank you for your post.
Please share your sample document as well as the code snippet to help us look into the issue.
Sincerely,
Jane
E-iceblue support team
Presentation ppt = new Presentation();
ppt.LoadFromFile(diag.FileName);
IChart Chart = null;
foreach (Shape shp in ppt.Slides[0].Shapes)
{
if (shp is IChart)
{
Chart = shp as IChart;
}
}
var textParagraph = Chart.ChartLegend.TextProperties.Paragraphs[0];
Font font = GetFont(textParagraph);
FontStyle fStyle = GetFontStyle(textParagraph.DefaultCharacterProperties);
textParagraph.DefaultCharacterProperties.LatinFont = new TextFont("Arial Unicode MS");
ppt.SaveToFile("123.pptx", FileFormat.Pptx2010);