该文将详细描述如何使用spire.presentation for java添加、删除和隐藏powerpoint 幻灯片,以及如何调整powerpoint里的幻灯片顺序。
添加新幻灯片到已有的powerpoint文档:
import com.spire.presentation.*;
public class slides {
public static void main(string[] args) throws exception {
//创建一个powerpoint文档并加载示例文档
presentation presentation = new presentation();
presentation.loadfromfile("c:\\users\\administrator\\desktop\\sample.pptx");
//在文档末尾添加新幻灯
presentation.getslides().append();
//在第二页插入空白幻灯片
presentation.getslides().insert(1);
//保存文档
presentation.savetofile("output/addslide.pptx", fileformat.pptx_2010);
}
}
隐藏幻灯片
import com.spire.presentation.*;
public class slides {
public static void main(string[] args) throws exception {
//创建一个powerpoint文档并加载示例文档
presentation presentation = new presentation();
presentation.loadfromfile("c:\\users\\administrator\\desktop\\sample.pptx");
//隐藏第二张幻灯片
presentation.getslides().get(1).sethidden(true);
//保存文档
presentation.savetofile("output/hideslide.pptx", fileformat.pptx_2010);
}
}
删除幻灯片
import com.spire.presentation.*;
public class slides {
public static void main(string[] args) throws exception {
//创建一个powerpoint文档并加载示例文档
presentation presentation = new presentation();
presentation.loadfromfile("c:\\users\\administrator\\desktop\\sample.pptx");
//删除第二张幻灯片
presentation.getslides().removeat(1);
//保存文档
presentation.savetofile("output/removeslide.pptx", fileformat.pptx_2010);
}
}
调整幻灯片顺序
import com.spire.presentation.*;
public class slides {
public static void main(string[] args) throws exception {
//创建一个powerpoint文档并加载示例文档
presentation presentation = new presentation();
presentation.loadfromfile("c:\\users\\administrator\\desktop\\sample.pptx");
//获取文档中的第一张幻灯片并将其设置为第二张
islide slide = presentation.getslides().get(0);
slide.setslidenumber(2);
//保存文档
presentation.savetofile("output/reorderslide.pptx", fileformat.pptx_2010);
}
}