使用c#中的Excel互操作设置饼图样式

时间:2022-09-28 17:23:42

I am working with Excel InterOp to dynamically create a pie chart with C#. I have the chart generating correctly, however I am running into a problem trying to set a style.

我正在使用Excel InterOp动态创建一个带有c#的饼图。我生成的图表是正确的,但是我遇到了设置样式的问题。

If I have the document open in Microsoft Excel and click on the chart I can set a style by doing the following:

如果我在Microsoft Excel中打开文档并点击图表,我可以通过以下方式设置样式:

Click on the Chart -> Click on the Paintbrush Icon --> Style Tab --> Select a style.

点击图表->点击画笔图标-> Style标签->选择一个风格。

The first style that comes up in the list is the one I want to use. It is referred to "Style 1" in Microsoft Excel. I have tried setting the ChartStyle property, but it does not do anything.

列表中出现的第一个样式是我想要使用的。它在Microsoft Excel中被称为“Style 1”。我尝试过设置ChartStyle属性,但是它什么都不做。

the.ChartStyle = 1;

I tried setting it to "Style 1", however this results in an exception being thrown with a message saying to only use integers.

我尝试将它设置为“Style 1”,但是这会导致一个异常被抛出,消息说只使用整数。

Is there an integer value that equates to "Style 1"? If not, what am I doing wrong?

是否有一个整数值等于“Style 1”?如果没有,我做错了什么?

1 个解决方案

#1


1  

"Style 1" has the integer value 201.

“样式1”具有整数值201。

If you want to find which integer value is matching which style, you should record a macro while you are selecting a style with a mouse, and then check what is recorded in a macro.

如果您想查找哪个整数值匹配哪个样式,您应该在使用鼠标选择样式时记录一个宏,然后检查宏中记录的内容。

#1


1  

"Style 1" has the integer value 201.

“样式1”具有整数值201。

If you want to find which integer value is matching which style, you should record a macro while you are selecting a style with a mouse, and then check what is recorded in a macro.

如果您想查找哪个整数值匹配哪个样式,您应该在使用鼠标选择样式时记录一个宏,然后检查宏中记录的内容。