本文将介绍通过spire.xls 来设置excel图表中的图例背景色填充,包括:
- 单色填充
- 渐变色填充
- 纹理填充
- 加载图片填充
测试文档:
c#
//实例化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("tp.png");
//保存文档
workbook.savetofile("result.xlsx", excelversion.version2010);
vb.net
'实例化workbook类的对象,并加载测试文档
dim workbook as new workbook()
workbook.loadfromfile("test.xlsx")
'获取工作表中的第一个图表
dim ws as worksheet = workbook.worksheets(0)
dim chart as spire.xls.chart = ws.charts(0)
'填充图例背景色
dim x as xlschartframeformat = trycast(chart.legend.frameformat, 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("tp.png");
'保存文档
workbook.savetofile("result.xlsx", excelversion.version2010)
单色填充效果:
渐变填充效果:
纹理填充效果:
图片填充效果: