在C#中更改Excel图表的背景颜色 [英] Changing the background color of an excel chart in C#

查看:617
本文介绍了在C#中更改Excel图表的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从我的C#应用​​程序创建一个Excel图表,该数据库从我的SQL Server数据库中提取数据,并使用该数据在Excel实例中创建一些图表。我有一个饼图,显示数据,一切都很好,接受我想更改ChartArea的背景颜色,并可能使用渐变添加一点视觉变化。我无法弄清楚如何使用OLE在C#中做到这一点。看起来像是安装了Office 16。这应该很简单,但我遇到了麻烦。我看到了chart.ChartArea.Fill.BackColor属性,但它是只读的(我无法设置它)。不知道如何以编程方式执行此操作。任何想法都会有所帮助。谢谢。



我的尝试:



我搜索过(bing,谷歌)周围,但找不到任何东西。有变化,但不是我的特殊问题。我可以手动更改它,当我的工作表中的图表出现时,但我希望能够以编程方式进行。

解决方案

通过RGB属性访问它Backcolor。

 chart.ChartArea.Fill.BackColor.RGB = RGB(221,221,221)

此外,如果你想要提示如何做在Excel中以编程方式使用C#的东西,你知道如何手动操作,记录一个宏。用宏录制手动完成。之后查看宏代码,了解如何在VBA中执行任务。然后你有提示如何在C#中做到这一点。

干杯!



填充格式对象(Excel)| Microsoft Docs [ ^


I'm working on creating an Excel Chart from my C# application that pulls data out of my SQL Server database, and using that data, creates some Charts in an Excel instance. I have a pie chart that displays with the data, and all is well, accept I want to change the background color of the ChartArea and maybe use a gradient to add a little visual variation. I'm having trouble figuring out how do do that in C# using OLE. It looks like Office 16 is installed. This should be simple, but I'm having trouble with this. I saw a chart.ChartArea.Fill.BackColor property, but it's read only (I can't set it). Not sure how to do this programmatically. Any ideas would be helpful. Thanks.

What I have tried:

I've searched (bing, google)around, but can't find anything. There are variations, but not my particular problem. I can change it manually, when the chart in my worksheet comes up, but I want to be able to do it programmatically.

解决方案

Access it by the RGB property of Backcolor.

chart.ChartArea.Fill.BackColor.RGB = RGB(221, 221, 221)

Also if you want hints at how to do something using C# programatically in Excel that you know how to do manually, record a macro. Do it manuually with the macro recording. review the macro code afterwards for how to do the task in VBA. Then you have hints of how to do it in C#.
Cheers!

FillFormat Object (Excel) | Microsoft Docs[^]


这篇关于在C#中更改Excel图表的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆