//table data
String[][] data = { { "INPUT FILE", "NUMBER OF RECORDS" },
{ "Item File", "11,559" }, { "Vendor File", "300" },
{ "Purchase History File", "10,000" },
{ "Total # of requisitions", "10,200,038" } };
SlideShow ppt = new SlideShow();
Slide slide = ppt.createSlide();
// create a table of 5 rows and 2 columns
Table table = new Table(5, 2);
for (int i = 0; i < data.length; i++)
{
for (int j = 0; j < data[i].length; j++)
{
TableCell cell = table.getCell(i, j);
cell.setText(data[i][j]);
RichTextRun rt = cell.getTextRun().getRichTextRuns()[0];
rt.setFontName("Arial");
rt.setFontSize(10);
cell.setVerticalAlignment(TextBox.AnchorMiddle);
cell.setHorizontalAlignment(TextBox.AlignCenter);
}
}
// set table borders
Line border = table.createBorder();
border.setLineColor(Color.black);
border.setLineWidth(1.0);
table.setAllBorders(border);
// set width of the 1st column
table.setColumnWidth(0, 300);
// set width of the 2nd column
table.setColumnWidth(1, 150);
slide.addShape(table);
table.moveTo(100, 100);
//Instantiate Presentation class that represents PPTX file
Presentation pres = new Presentation();
//Access first slide
ISlide sld = pres.getSlides().get_Item(0);
//Define columns with widths and rows with heights
double[] dblCols = { 50, 50, 50 };
double[] dblRows = { 50, 30, 30, 30, 30 };
//Add table shape to slide
ITable tbl = sld.getShapes().addTable(100, 50, dblCols, dblRows);
//Set border format for each cell
for(int row = 0; row < tbl.getRows().size(); row++)
{
for (int cell = 0; cell < tbl.getRows().get_Item(row).size(); cell++)
{
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().getFillFormat().setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().getFillFormat().getSolidFillColor().setColor(Color.RED);
tbl.getRows().get_Item(row).get_Item(cell).getBorderTop().setWidth(5);
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().getFillFormat().setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().getFillFormat().getSolidFillColor().setColor(Color.RED);
tbl.getRows().get_Item(row).get_Item(cell).getBorderBottom().setWidth(5);
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().getFillFormat().setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().getFillFormat().getSolidFillColor().setColor(Color.RED);
tbl.getRows().get_Item(row).get_Item(cell).getBorderLeft().setWidth(5);
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().getFillFormat().setFillType(FillType.Solid);
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().getFillFormat().getSolidFillColor().setColor(Color.RED);
tbl.getRows().get_Item(row).get_Item(cell).getBorderRight().setWidth(5);
}
}
//Merge cells 1 & 2 of row 1
tbl.mergeCells(tbl.getRows().get_Item(0).get_Item(0), tbl.getRows().get_Item(1).get_Item(0), false);
//Add text to the merged cell
tbl.getRows().get_Item(0).get_Item(0).getTextFrame().setText("Merged Cells");
Download Source Code