C#, Excel Interop, & ExcelChartType.BoxAndWhisker RRS feed

  • Question

  • Hi,<o:p></o:p>

    I would like to make a Box and Whisker plot using C# and Excel Interop. The web
    tells me a Box and Whisker plot has ChartType set to ExcelChartType.BoxAndWhisker. Makes sense. But "BoxAndWhisker" is not a member of the ExcelChartType enumeration. <o:p></o:p>

    I can make I can make Box and Whisker plots manually in the Excel I have installed. I can make other types of charts using interop without problem. I am using the latest version of Interop I can find (Microsoft Excel 16.0 Object Library version; also Microsoft Office 16.0 Object Library version  I recorded a macro of making a BoxAndWhisker Plot in Excel, checked the underlying value for ExcelChartType.BoxAndWhisker (seems to be 121) and tried casting that to ExcelChartType, but that gave a bad cast error. <o:p></o:p>

    Anyone know how to get this to work? I assume I need a different or additional reference, but I don't know what.<o:p></o:p>



    Ethan Strauss

    • Moved by CoolDadTx Thursday, March 21, 2019 1:50 PM Office related
    Wednesday, March 20, 2019 3:42 PM

All replies

  • Hi

    Thank you for posting here.

    >> tried casting that to ExcelChartType

    Could you provide the related code about your problem?

    >> but that gave a bad cast error.

    What is your bad cast error?

    We will be appreciated if you provide the above information.

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Thursday, March 21, 2019 3:23 AM
  • Hi,

       The code is below with the error indicated.



            public static void MakeBoxPlot(Worksheet sheet, Range data)
                double left=10;
                double width = 600;
                double top=10;
                double height = 200;
                ChartObject ch = ((ChartObjects)sheet.ChartObjects()).Add(left,top,width,height);
                ch.Chart.ChartType = (XlChartType)121;//This line throws an argument exception "Value does not fall within the expected range."
                foreach (XlChartType type in Enum.GetValues(typeof(XlChartType)))
                    ExcelCell.PutValueAt(type.ToString(), "a1", sheet);
                    ch.Chart.ChartType = type;

    Ethan Strauss

    Thursday, March 21, 2019 3:47 PM
  • Hi, I have exactly the same problem, has any solution to that been found...?
    Thursday, April 4, 2019 8:44 AM