访问图表的 X 轴并动态设置标签之间的间隔

Access X axis of the chart and Set interval between labels dynamically

我有一个包含图表的模板文档。

使用此模板生成报告。

当我有一定数量的值时它工作正常,在给定的示例中为 7。但是当样本数据增加时,类别轴看起来是聚集的,如图所示。

我想将标签之间的间隔动态设置为自动或使用公式指定间隔,但我无法访问此属性。

我尝试用谷歌搜索但没有帮助。 如果有人可以帮助我,我将不胜感激。

我测试了一个解决方案,似乎没问题:

在测试我的 word 文件之前:

Axis Properties

我的代码:

using Word = Microsoft.Office.Interop.Word;
:
:
    private void WordWithExcel()
    {
        object missing = System.Reflection.Missing.Value;
        Word.Application application = new Word.Application();
        Word.Document wordDoc = application.Documents.Add(@"d:\+test3.docx");

        //i suppose there is only one inline -> always begin by 1 dunno why
        Word.InlineShape shape = wordDoc.InlineShapes[1];
        Word.Chart chart = shape.Chart;

        var axis = chart.Axes(Word.XlAxisType.xlCategory);
        axis.TickLabelSpacingIsAuto = false;

        // if you want modify the spacing value
        // axis.TickLabelSpacing = 2;

        object filename = @"d:\++t.docx";
        wordDoc.SaveAs2(ref filename);
        wordDoc.Close(ref missing, ref missing, ref missing);
        application.Quit(ref missing, ref missing, ref missing);
    }

结果: