前面我们介绍过如何,本文将介绍如何使用spire.presentation重新设置日期和编号的位置。
日期的默认位置在左,编号的默认位置在右,如下图所示:
c#
//加载presentation文档
presentation presentation = new presentation();
presentation.loadfromfile("sample.pptx");
//获取第一张幻灯片
islide slide = presentation.slides[0];
//遍历幻灯片中的形状
foreach (ishape shapetomove in slide.shapes)
{
//改变编号的位置
if (shapetomove.name.contains("slide number placeholder"))
{
shapetomove.left = 0;
}
//改变日期的位置
else if (shapetomove.name.contains("date placeholder"))
{
shapetomove.left = presentation.slidesize.size.width / 2;
//改变日期的格式
(shapetomove as iautoshape).textframe.textrange.paragraph.text = datetime.now.tostring("dd.mm.yyyy");
(shapetomove as iautoshape).textframe.iscentered = true;
}
}
//保存文档
presentation.savetofile("result.pptx", fileformat.pptx2013);
vb.net
'加载presentation文档
dim presentation as new presentation()
presentation.loadfromfile("sample.pptx")
'获取第一张幻灯片
dim slide as islide = presentation.slides(0)
'遍历幻灯片中的形状
for each shapetomove as ishape in slide.shapes
'改变编号的位置
if shapetomove.name.contains("slide number placeholder") then
shapetomove.left = 0
'改变日期的位置
elseif shapetomove.name.contains("date placeholder") then
shapetomove.left = presentation.slidesize.size.width / 2
'改变日期的格式
trycast(shapetomove, iautoshape).textframe.textrange.paragraph.text = datetime.now.tostring("dd.mm.yyyy")
trycast(shapetomove, iautoshape).textframe.iscentered = true
end if
next
'保存文档
presentation.savetofile("result.pptx", fileformat.pptx2013)
生成效果截图如下: