Table.MergeCells reduct total number of rows and columns

Hi,


We are facing problem in generation of slide table with merged cells.

To explain problem I have attached image of table that we are trying to create.

Problem 1: We are trying to merge two cells with value “COLUMN HEADER 1” vertically. Before merge total number of rows were 6, after merge cell it reduce total number of row to 5. This has reduced table dimension automatically.

Problem 2: We are trying to merge cells with value “ROW HEADER1” horizontally. Before merge total number of columns 7 after merge cell it reduce total number of row to 6. This has reduced table dimension automatically.

Hi Vishal,

Thanks for your interest in Aspose.Slides.

I am sorry for the delayed response. It would have been really helpful for me, if you could please share your code with me. This way, I would better investigate the issue to help you out.

Thanks and Regards,

Sample code follows and check the generated output (attached).

import java.io.File;

import java.io.FileOutputStream;

import com.aspose.slides.Cell;

import com.aspose.slides.Presentation;

import com.aspose.slides.Slide;

import com.aspose.slides.Table;

public class TestPPT {

public static void main(String[] args) {

try

{

//Instantiate a Presentation object that represents a PPT file

Presentation pres=new Presentation();

//Adding an empty slide to the presentation

//Slide slide=pres.addEmptySlide();

//Do some work on the slide

Slide slide = pres.getSlides().get(0);

//Writing the presentation as a PPT file

Table tbl = (Table) slide.getShapes().addTable(100, 600, 2300, 400 , 7, 6);

Cell cell = null;

System.out.println("table rows orgiinally :"+tbl.getRowsNumber());

int rowStart = 1;

int rowEnd = 3;

int columnStart = 1;

int columnEnd = 3;

cell = merge(tbl , rowStart , rowEnd , columnStart , columnEnd);

cell.getTextFrame().getParagraphs().get(0).getPortions().get(0).setText("BLANK");

System.out.println("table rows after 1st merge :"+tbl.getRowsNumber());

rowStart = 1;

rowEnd = 2;

columnStart = 4;

columnEnd = 7;

cell = merge(tbl , rowStart , rowEnd , columnStart , columnEnd);

cell.getTextFrame().getParagraphs().get(0).getPortions().get(0).setText("COL HEADER 1");

System.out.println("table rows after 2nd merge :"+tbl.getRowsNumber());

// rowStart = 2;

// rowEnd = 2;

// columnStart = 4;

// columnEnd = 7;

// cell = merge(tbl , rowStart , rowEnd , columnStart , columnEnd);

// cell.getTextFrame().getParagraphs().get(0).getPortions().get(0).setText("COL HEADER 2");

pres.write(new FileOutputStream(new File("C:\\demo.ppt")));

}

catch(Exception ex)

{

System.out.println(ex.toString());

}

System.out.println("PPT written.");

}

public static Cell merge(Table tbl , int rowStart ,int rowEnd , int columnStart , int columnEnd){

Cell cell = null;

for (int j = rowStart - 1; j <= rowEnd - 1; j++) {

for (int i = columnStart - 1; i < columnEnd - 1; i++) {

cell = tbl.mergeCells(tbl.getCell(i, j), tbl.getCell(i + 1, j));

}

}

if (rowStart < rowEnd) {

for (int j = rowStart - 1; j < rowEnd - 1; j++) {

cell = tbl.mergeCells(tbl.getCell(columnStart - 1, j), tbl.getCell(columnStart - 1, j + 1));

}

}

return cell;

}

}

Hi Vishal,

Thanks for your interest in Aspose.Slides.

I have verified your problem statements, with your code snippet. But I am afraid; I am unable to understand your problem. So, I would request you to elaborate this problem or share some more details. As per my understanding, the problem 1 does not seem to be a problem because when you are merging two rows, you will be getting one row as resultant. So, if there are 6 six rows and you merge 2 rows out of them then resultant rows will be 5.

As far as problem 2 is concerned, please share more details for our understanding.

We are sorry for the inconvenience.