本文介绍如何使用spire.presentation for .net设置形状中文字的对齐方式。
c#
using spire.presentation;
using system.drawing;
using spire.presentation.drawing;
namespace textalignment
{
class program
{
static void main(string[] args)
{
//创建presentation对象
presentation presentation = new presentation();
presentation.slidesize.type = slidesizetype.screen16x9;
//添加形状
iautoshape textshape = presentation.slides[0].shapes.appendshape(shapetype.rectangle, new rectanglef(50, 50, 400, 200));
textshape.shapestyle.linecolor.color = color.darkgray;
textshape.fill.filltype = fillformattype.none;
//删除默认段落
textshape.textframe.paragraphs.clear();
//添加段落和文字
textshape.textframe.paragraphs.append(new textparagraph());
textshape.textframe.paragraphs[0].textranges.append(new textrange("文字对齐方式"));
textshape.textframe.paragraphs[0].textranges[0].fontheight = 20f;
textshape.textframe.paragraphs[0].textranges[0].latinfont = new textfont("黑体");
textshape.textframe.paragraphs[0].textranges[0].fill.filltype = fillformattype.solid;
textshape.textframe.paragraphs[0].textranges[0].fill.solidcolor.color = color.black;
//设置文字水平靠右
textshape.textframe.paragraphs[0].alignment = textalignmenttype.right;
//设置文字垂直靠下
textshape.textframe.anchoringtype = textanchortype.bottom;
//保存文档
presentation.savetofile("aligntext.pptx", fileformat.pptx2013);
}
}
}
vb.net
imports spire.presentation
imports system.drawing
imports spire.presentation.drawing
namespace textalignment
class program
shared sub main(byval args() as string)
'创建presentation对象
dim presentation as presentation = new presentation()
presentation.slidesize.type = slidesizetype.screen16x9
'添加形状
dim textshape as iautoshape = presentation.slides(0).shapes.appendshape(shapetype.rectangle,new rectanglef(50,50,400,200))
textshape.shapestyle.linecolor.color = color.darkgray
textshape.fill.filltype = fillformattype.none
'删除默认段落
textshape.textframe.paragraphs.clear()
'添加段落和文字
textshape.textframe.paragraphs.append(new textparagraph())
textshape.textframe.paragraphs(0).textranges.append(new textrange("文字对齐方式"))
textshape.textframe.paragraphs(0).textranges(0).fontheight = 20f
textshape.textframe.paragraphs(0).textranges(0).latinfont = new textfont("黑体")
textshape.textframe.paragraphs(0).textranges(0).fill.filltype = fillformattype.solid
textshape.textframe.paragraphs(0).textranges(0).fill.solidcolor.color = color.black
'设置文字水平靠右
textshape.textframe.paragraphs(0).alignment = textalignmenttype.right
'设置文字垂直靠下
textshape.textframe.anchoringtype = textanchortype.bottom
'保存文档
presentation.savetofile("aligntext.pptx", fileformat.pptx2013)
end sub
end class
end namespace