简体   繁体   English

Excel VSTO C#-设置雷达图类别和轴标签的格式

[英]Excel VSTO C# - Format radar chart category and axis labels

I'm trying to change the format of the text on a radar chart's axis and category labels, my code works for the axis font size and gives the desired output but I'm also receiving an error once the code runs on the line ax.Format.TextFrame2.TextRange.Font.Size = 7; 我正在尝试更改雷达图的轴和类别标签上的文本格式,我的代码适用于轴字体大小并提供所需的输出,但是一旦代码在ax.Format.TextFrame2.TextRange.Font.Size = 7;上运行,我也会收到错误消息ax.Format.TextFrame2.TextRange.Font.Size = 7;

Error from debug: 调试错误:

An exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll but was not handled in user code. mscorlib.dll中发生类型'System.Runtime.InteropServices.COMException'的异常,但未在用户代码中处理。 Additional information: Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)) 附加信息:未指定的错误(HRESULT的异常:0x80004005(E_FAIL))

How do I change the category labels and what might be causing the error here once the action is completed? 完成操作后,如何更改类别标签?什么可能导致此错误?

Here's the code: 这是代码:

public static void FormatRadarLabels(Excel._Application xlApp)
{
    Excel.Chart chart = null;
    xlApp.ScreenUpdating = false;

    try {

        chart = xlApp.ActiveChart as Excel.Chart;

        foreach (Excel.Axis ax in chart.Axes()) {
            ax.Format.TextFrame2.TextRange.Font.Size = 7;
        }
    }
    finally {
        if (chart != null) Marshal.ReleaseComObject(chart);
        xlApp.ScreenUpdating = true;
    }

}

The method is called by a method in another class which is called by a button on an excel toolbar but I don't think the error has any issues with anything external as if I comment or removed this piece of code the rest of the formatting works fine. 该方法由另一个类中的方法调用,该类由excel工具栏上的按钮调用,但是我不认为该错误与任何外部问题有关,就像我注释或删除了这段代码,其余的格式化工作一样精细。

Thank you for any help or suggestions offered. 感谢您提供的任何帮助或建议。 Please bear in mind I am relatively new (6 months experience) to C#, VSTO and Visual Studio so may not understand all technical jargon. 请记住,我对C#,VSTO和Visual Studio相对较新(6个月的经验),因此可能不了解所有技术术语。 I'm also happy to provide further information if required. 如果需要,我也很乐意提供更多信息。 :) :)

What property exactly fires an exception? 到底哪个属性引发异常?

ax.Format.TextFrame2.TextRange.Font.Size = 7; ax.Format.TextFrame2.TextRange.Font.Size = 7;

I'd suggest starting from breaking the chain of property and method calls and declaring them on separate lines. 我建议从中断属性和方法调用链开始,并在单独的行中声明它们。 Thus, you will find what property or method exactly fires an exception. 因此,您将找到确切引发异常的属性或方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM