How can I grab the default value of a chart title?

Hi,

I learned that I can search the title text of a chart appears in a word file, with the code as follows.
dummychart.docx.zip (19.8 KB)

Document doc = new Document("dummychart.docx");
foreach (Section section in doc.Sections)
{
    foreach (var node in section.Body)
    {
        if ( ((Node)node).NodeType == NodeType.Paragraph )
        {
            foreach ( var nodeInPara in ((Paragraph)node).ChildNodes )
            {
                if (((Node)nodeInPara).NodeType == NodeType.Shape)
                {
                    if(((Shape)nodeInPara).HasChart)
                    {
                        Consle.WriteLine(((Shape)nodeInPara).Chart.Title.Text);
                    }
                }
            }
        }
    }
}

I was expecting it to be “グラフ タイトル” as you can see capture.png (35.1 KB) just as predetermined default value.
But in fact Chart.Title.Text property returned “”;
Once I modified very the same string on word and save it, then the same code prints the modified string.
Is there any way I can get the default value?

As always thank you for your kind support.

@KDSSHO,

Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-17271. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi Tahir,

Thank you for your reply.
If it is a bug you can easily reproduce the same situation on Excel and PowerPoint, too.
Not the very same code snippet of course, but with the similar functionality accessing the stuff like Chart.Title.Text respectively for each application.

Sorry that I did not complete the investigation when I open this topic, however, I’d need to add one more question related to this topic.
Do I have an access to “category” property from somewhere relevant to Shape.Chart property mentioned above?
I can touch “title” of the chart ( only if it is modified ).
I can touch “series” of the chart.
How about “categories” ?
Finally I aim to detect all the text property ( including ones not always explicitly visible, such as, AlternativeText ) contained in the chart, then replace them according to a certain manner. I am keep reading the documents and codes to achieve it. Your help will be truly welcomed.

@KDSSHO,

Thanks for your inquiry.

Could you please ZIP and attach your Excel and PowerPoint documents here for testing?

The ChartAxis.CategoryType property gets or sets the type of the category axis. Could you please share your expected output?

Please check this ExcelPowerPoint.zip (52.4 KB)

My expected output is

グラフタイトル
カテゴリ1
カテゴリ2
カテゴリ3
カテゴリ4

with the code like this, three lines added to the above example for printing 4 text strings of categories.


if(((Shape)nodeInPara).HasChart)
{
    Consle.WriteLine(((Shape)nodeInPara).Chart.Title.Text);
    foreach(Category cat in ((Shape)nodeInPara).Chart.Categories)
    {
        Consle.WriteLine(cat.Text);
    }
}

I’m sure that the actual implementation is not like this.
But the point is; I want the text properties. NOT ChartAxis.CategoryType property.

@KDSSHO,

Thanks for sharing the detail.

Please use latest version of Aspose.Cells for .NET 18.7 and Aspose.Slides for .NET 18.7 with following code examples to get the chart’s title.

Presentation pres = new Presentation("dummychart2.pptx");
IChart chart = (IChart)pres.Slides[0].Shapes[0];

String Title= chart.ChartTitle.TextFrameForOverriding.Text;

foreach (var cat in chart.ChartData.Categories)
{
    Console.WriteLine("Category: " + cat.Value);
}

Workbook workbook = new Workbook("e:\\test2\\dummychart.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
Chart chart = worksheet.Charts[0];
chart.Calculate();
string title1Text = chart.Title.Text; //グラフタイトル - Ok


Chart chart1 = worksheet.Charts[1];
chart1.Calculate();
string title2Text = chart1.Title.Text;//Chart Title - Ok

Unfortunately, Aspose.Words does not support the requested feature at the moment. However, we have logged this feature request as WORDSNET-17277 in our issue tracking system. You will be notified via this forum thread once this feature is available.

We apologize for your inconvenience.

Thank you. I could improve my code for Excel.
But chart.ChartTitle.TextFrameForOverriding is null when you load dummychart.pptx I sent.
Would you double check this?

I regret that Aspose.Words doesn’t support some operations on some elements in Word.

@KDSSHO,

Thanks for your inquiry. The TextFrameForOverriding is used when chart title is defined by user. If the chart title is automatic (usually it is appears as “Chart Title”) - chart doesn’t store this value in the document.

If the chart title is overridden by user, you can get it using ChartTitle.TextFrameForOverriding.Text property. Otherwise, it returns null. Please use following line of code to get the correct output.

string title = chart.ChartTitle.TextFrameForOverriding == null ? "Chart Title" : chart.ChartTitle.TextFrameForOverriding.Text;

Thank you for your suggestion. Now I understand that.

I would go with a list of the default strings in target languages presumably applicable for the users’ input Word file, choosing the one fits in the place of “Chart Tiltle”.

@KDSSHO,

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

The issues you have found earlier (filed as WORDSNET-17271) have been fixed in this Aspose.Words for .NET 18.12 update and this Aspose.Words for Java 18.12 update.

The issues you have found earlier (filed as WORDSNET-17277) have been fixed in this Aspose.Words for .NET 23.5 update also available on NuGet.