With Spire.Presentation for Java, we can format a table by applying preset table styles. This article will demonstrate how to apply predefined styles to a table on presentation slides.
Firstly, view the table on the PowerPoint document:
import com.spire.presentation.ITable; import com.spire.presentation.Presentation; import com.spire.presentation.FileFormat; import com.spire.presentation.TableStylePreset; public class SetTableStyle { public static void main(String[] args) throws Exception { //Create a PPT document and load file Presentation presentation = new Presentation(); presentation.loadFromFile("Sample.pptx"); ITable table = null; for (Object shape : presentation.getSlides().get(0).getShapes()) { if (shape instanceof ITable) { table = (ITable) shape; //Set the table style from TableStylePreset and apply it to selected table table.setStylePreset(TableStylePreset.MEDIUM_STYLE_1_ACCENT_2); } } //Save the file presentation.saveToFile("SetTableStyle.pptx", FileFormat.PPTX_2010); } }
Effective screenshot after updating the table style: