Xls.Core.Spreadsheet.Charts;
using System.Drawing;
namespace SetFontOfLegendInChart_XLS
{
class Program
{
static void Main(string[] args)
{
//实例化Workbook类的对象,并加载测试文档
Workbook workbook = new Workbook();
workbook.LoadFromFile("test.xlsx");
//获取工作表中的第一个图表
Worksheet ws = workbook.Worksheets[0];
Spire.Xls.Chart chart = ws.Charts[0];
//填充图例背景色
XlsChartFrameFormat x = chart.Legend.FrameFormat as XlsChartFrameFormat;
//单色填充
x.Fill.FillType = ShapeFillType.SolidColor;
x.ForeGroundColor = Color.Gainsboro;
////渐变色填充
//x.Fill.FillType = ShapeFillType.Gradient;
//x.ForeGroundColor = Color.AliceBlue;
//x.BackGroundColor = Color.Bisque;
////纹理填充
//x.Fill.FillType = ShapeFillType.Texture;
//x.Fill.Texture = GradientTextureType.Bouquet;
////图片填充
//x.Fill.CustomPicture("img.png");
//保存文档
workbook.SaveToFile("output.xlsx", ExcelVersion.Version2010);
System.Diagnostics.Process.Start("output.xlsx");
}
}
}
View Code
更多Excel背景色填充的方法,可参考以下文章:
1. C# 设置Excel单元格背景色
2. C# 设置Excel表格图片背景
(本文完)
转载请注明出处!
|