spire.presentation支持修改图表的元素。 本文将详细介绍如何使用spire.presentation修改ppt文档中图表类别坐标轴以及图例的文本字体。
首先,我们看一下原始文档中图表图例文本的字体。
完整代码:
c#
presentation presentation = new presentation();
//加载文件
presentation.loadfromfile(@"sample.pptx", fileformat.pptx2013);
//获取图表
ichart chart = presentation.slides[0].shapes[0] as ichart;
//修改图例段落的填充方式
chart.chartlegend.textproperties.paragraphs[0].defaultcharacterproperties.fill.filltype = fillformattype.solid;
//修改图例段落的填充颜色
chart.chartlegend.textproperties.paragraphs[0].defaultcharacterproperties.fill.solidcolor.knowncolor = knowncolors.red;
//修改图例段落字体大小
chart.chartlegend.textproperties.paragraphs[0].defaultcharacterproperties.fontheight = 15;
//修改图例段落的字体
chart.chartlegend.textproperties.paragraphs[0].defaultcharacterproperties.latinfont = new textfont("宋体");
//修改类别坐标轴段落的填充类型
chart.primarycategoryaxis.textproperties.paragraphs[0].defaultcharacterproperties.fill.filltype = fillformattype.solid;
//修改类别坐标轴段落的填充颜色
chart.primarycategoryaxis.textproperties.paragraphs[0].defaultcharacterproperties.fill.solidcolor.knowncolor = knowncolors.blue;
//修改类别坐标轴段落字体大小
chart.primarycategoryaxis.textproperties.paragraphs[0].defaultcharacterproperties.fontheight = 18;
//修改类别坐标轴段落字体
chart.primarycategoryaxis.textproperties.paragraphs[0].defaultcharacterproperties.latinfont = new textfont("宋体");
//保存文件
presentation.savetofile("result.pptx", fileformat.pptx2010);
vb.net
dim presentation as new presentation()
'加载文件
presentation.loadfromfile("sample.pptx", fileformat.pptx2013)
'获取图表
dim chart as ichart = trycast(presentation.slides(0).shapes(0), ichart)
'修改图例段落的填充方式
chart.chartlegend.textproperties.paragraphs(0).defaultcharacterproperties.fill.filltype = fillformattype.solid
'修改图例段落的填充颜色
chart.chartlegend.textproperties.paragraphs(0).defaultcharacterproperties.fill.solidcolor.knowncolor = knowncolors.red
'修改图例段落字体大小
chart.chartlegend.textproperties.paragraphs(0).defaultcharacterproperties.fontheight = 15
'修改图例段落的字体
chart.chartlegend.textproperties.paragraphs(0).defaultcharacterproperties.latinfont = new textfont("宋体")
'修改类别坐标轴段落的填充类型
chart.primarycategoryaxis.textproperties.paragraphs(0).defaultcharacterproperties.fill.filltype = fillformattype.solid
'修改类别坐标轴段落的填充颜色
chart.primarycategoryaxis.textproperties.paragraphs(0).defaultcharacterproperties.fill.solidcolor.knowncolor = knowncolors.blue
'修改类别坐标轴段落字体大小
chart.primarycategoryaxis.textproperties.paragraphs(0).defaultcharacterproperties.fontheight = 18
'修改类别坐标轴段落字体
chart.primarycategoryaxis.textproperties.paragraphs(0).defaultcharacterproperties.latinfont = new textfont("宋体")
'保存文件
presentation.savetofile("result.pptx", fileformat.pptx2010)
结果展示: