This article demonstrates how to access a table in an existing PowerPoint document and how to merge and split cells in the table by using Spire.Presentation for Java.
Here is the screenshot of the input file.
import com.spire.presentation.FileFormat; import com.spire.presentation.ITable; import com.spire.presentation.Presentation; public class MergeAndSplitCells { public static void main(String[] args) throws Exception { //create a Presentation object Presentation presentation = new Presentation(); //load a sample PowerPoint file presentation.loadFromFile("C:/Users/Administrator/Desktop/sample.pptx"); //declare ITable variable ITable table = null; //get the table from the presentation slide for (Object shape : presentation.getSlides().get(0).getShapes()) { if (shape instanceof ITable) { table = (ITable) shape; //merge the cells between cell[0,0] and cell[2,0] table.mergeCells(table.get(0, 0), table.get(2, 0), false); //merge the cells between cell[0,1] and cell[0,3] table.mergeCells(table.get(0, 1), table.get(0, 3), false); //split cell[2,3] to 2 columns table.get(2,3).Split(1,2); } } //save to file presentation.saveToFile("MergeAndSplitCells.pptx", FileFormat.PPTX_2010); } }
Output