Splitting a Cell of a Table and Fetching the Center of the Splitted Cell in Presentation

Hi,

I have a requirement where suppose we have a table with 2 rows and 3 columns.
And as and when the data is populated on the second row for second column, the height of the second row gets auto adjusted based on the content size.

Now, on the Third column of the second row, I need to split this cell equally and then add some score/text on the middle of the split cells.

Request to please help with the same on how I can retrieve the number of equally split cells based on the given height and also how can I retrieve the middle of that cell and write content on it.

Example Code:-

ISlide sld = pres.getSlides().get_Item(0);
double[] dblCols = {20, 50, 50};
double[] dblRows = {20, 50};

ITable table = sld.getShapes().addTable(100, 50, dblCols, dblRows);
ICell rowCell = table.get_Item(1, 1);
ITextFrame txtFrm = table.get_Item(1, 1).getTextFrame();
txtFrm.getParagraphs().clear();


// Suppose I add a text to txtFrm such that the height of the row increases from 50 to 100.

txtFrm.getParagraphs().add(textone);
txtFrm.getParagraphs().add(texttwo);
txtFrm.getParagraphs().add(texthree);
txtFrm.getParagraphs().add(textfour);
txtFrm.getParagraphs().add(textfive);

ICell tempCell = table.get_Item(2, 1);

/**
Now I want to split the 3rd column of the second row equally with height of 20 and populate data on the middle of the 3rd column. How can I do that?
**/ 

Tried with tempCell.splitByHeight(20); But it only created one split cell and does not work if I use for loop for splitting.

@Ganesh1402,
Thank you for describing the issue.

To understand your requirements better, could please share a sample presentation containing the table with the expected result?

Attached the slide as a pdf file as I am not able to upload the ppt file.

Example.pdf (46.4 KB)

As you can see in the attachment, Third column of the second row, I have split the cell equally and then added some score/text on the middle of the split cells.

@Ganesh1402,
Thank you for the sample table. I am working on your question and will get back to you as soon as possible.

@Ganesh1402,
Unfortunately, I was unable to understand your requirements, we need more detailed information.

Hi @andrey.potapov

Please refer to the pdf file shared previously.
As you can see on the third column of the second row, the column is split by a specific height to get the splits rows on this column and then the data is populated on the centre cell and also the cell is coloured with a specific colour.

Explaining the requirement step by step as below:-

Step 1: We populate the players names on the second column of the second row and suppose the row height has increased to 300.

Step 2: Now in order to populate the year and colour on the middle of the third column of the same row, I have to split this row’s height by say with static split cell height (let us consider the split cell height as 20 for example). I will get the number of split cells by dividing 300 (row height) by 20 (split cell height), i.e. 15 split cells on the third column for second row. Now, I will put the score and colour on the middle of the split cells, 8th cell (i.e. 15/2) so that the year and colour is populated on the middle of the third column.

Logic to be implemented: We split the third column of second row by static split cell height, and fetch the number of split cell and then populate the data and colour on the middle cell on the third column.

We need help on implementing this logic using Aspose Library to split the third column by the height of 20, get the number of split cells and then populate data and colour on the middle of the split cells.

I hope this help in understanding the requirement.

@Ganesh1402,
Thank you for the detailed information. Unfortunately, I have not found a way to achieve your purpose yet.

We have opened the following new ticket(s) in our internal issue tracking system and will consider your question according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESJAVA-39305

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

The issues you have found earlier (filed as SLIDESJAVA-39305) have been fixed in this update. This message was posted using Bugs notification tool.

@Ganesh1402,
With Aspose.Slides for Java 23.11, please try using the following code example:

Presentation pres = new Presentation();
try {
    pres.getSlideSize().setSize(1280, 720, SlideSizeScaleType.DoNotScale);
    ITable table = pres.getSlides().get_Item(0).getShapes().addTable(25, 110, new double[] { 35, 505, 55 }, new double[] { 40, 40 });

    table.get_Item(0, 0).getCellFormat().getFillFormat().setFillType(FillType.Solid);
    table.get_Item(0, 0).getCellFormat().getFillFormat().getSolidFillColor().setColor(Color.WHITE);
    table.get_Item(0, 0).getCellFormat().getBorderRight().setWidth(0);
    table.get_Item(0, 0).getCellFormat().getBorderLeft().setWidth(0);
    table.get_Item(0, 0).getCellFormat().getBorderTop().setWidth(0);
    table.get_Item(0, 0).getCellFormat().getBorderBottom().setWidth(0);

    table.get_Item(1, 0).getCellFormat().getFillFormat().setFillType(FillType.Solid);
    table.get_Item(1, 0).getCellFormat().getFillFormat().getSolidFillColor().setColor(Color.ORANGE);
    table.get_Item(1, 0).getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).setText("Team Members");
    table.get_Item(1, 0).getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().setFontHeight(24);
    table.get_Item(1, 0).getCellFormat().getBorderRight().setWidth(0);
    table.get_Item(1, 0).getCellFormat().getBorderLeft().setWidth(0);
    table.get_Item(1, 0).getCellFormat().getBorderTop().setWidth(0);
    table.get_Item(1, 0).getCellFormat().getBorderBottom().setWidth(0);

    table.get_Item(2, 0).getCellFormat().getFillFormat().setFillType(FillType.Solid);
    table.get_Item(2, 0).getCellFormat().getFillFormat().getSolidFillColor().setColor(Color.WHITE);
    table.get_Item(2, 0).getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).setText("Year");
    table.get_Item(2, 0).getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getFillFormat().setFillType(FillType.Solid);
    table.get_Item(2, 0).getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
    table.get_Item(2, 0).getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0).getPortionFormat().setFontBold(NullableBool.False);
    table.get_Item(2, 0).getCellFormat().getBorderLeft().getFillFormat().setFillType(FillType.Solid);
    table.get_Item(2, 0).getCellFormat().getBorderLeft().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
    table.get_Item(2, 0).getCellFormat().getBorderLeft().setWidth(4);
    table.get_Item(2, 0).getCellFormat().getBorderRight().setWidth(0);
    table.get_Item(2, 0).getCellFormat().getBorderTop().setWidth(0);
    table.get_Item(2, 0).getCellFormat().getBorderBottom().setWidth(0);

    table.get_Item(0, 1).setTextVerticalType(TextVerticalType.Vertical270);
    table.get_Item(0, 1).getTextFrame().getTextFrameFormat().getTextStyle().getDefaultParagraphFormat().setAlignment(TextAlignment.Center);
    table.get_Item(0, 1).getTextFrame().getParagraphs().get_Item(0).getParagraphFormat().setAlignment(TextAlignment.Center);
    table.get_Item(0, 1).getTextFrame().getParagraphs().get_Item(0).setText("INDIA");
    table.get_Item(0, 1).getCellFormat().getBorderRight().setWidth(0);
    table.get_Item(0, 1).getCellFormat().getBorderLeft().setWidth(0);
    table.get_Item(0, 1).getCellFormat().getBorderTop().setWidth(0);
    table.get_Item(0, 1).getCellFormat().getBorderBottom().setWidth(0);

    table.get_Item(1, 1).getCellFormat().getFillFormat().setFillType(FillType.Solid);
    table.get_Item(1, 1).getCellFormat().getFillFormat().getSolidFillColor().setColor(Color.WHITE);
    table.get_Item(1, 1).getCellFormat().getBorderTop().getFillFormat().setFillType(FillType.Solid);
    table.get_Item(1, 1).getCellFormat().getBorderTop().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
    table.get_Item(1, 1).getCellFormat().getBorderTop().setWidth(1);
    table.get_Item(1, 1).getCellFormat().getBorderBottom().getFillFormat().setFillType(FillType.Solid);
    table.get_Item(1, 1).getCellFormat().getBorderBottom().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
    table.get_Item(1, 1).getCellFormat().getBorderBottom().setWidth(1);
    table.get_Item(1, 1).getCellFormat().getBorderLeft().getFillFormat().setFillType(FillType.Solid);
    table.get_Item(1, 1).getCellFormat().getBorderLeft().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
    table.get_Item(1, 1).getCellFormat().getBorderLeft().setWidth(1);
    table.get_Item(1, 1).getCellFormat().getBorderRight().getFillFormat().setFillType(FillType.Solid);
    table.get_Item(1, 1).getCellFormat().getBorderRight().getFillFormat().getSolidFillColor().setColor(Color.BLUE);
    table.get_Item(1, 1).getCellFormat().getBorderRight().setWidth(1);
    table.get_Item(1, 1).getTextFrame().getParagraphs().clear();
    Paragraph p1 = new Paragraph();
    p1.setText("Virat Kohli");
    table.get_Item(1, 1).getTextFrame().getParagraphs().add(p1);
    Paragraph p2 = new Paragraph();
    p2.setText("Rohit Sharma");
    table.get_Item(1, 1).getTextFrame().getParagraphs().add(p2);
    Paragraph p3 = new Paragraph();
    p3.setText("Shubman Gill");
    table.get_Item(1, 1).getTextFrame().getParagraphs().add(p3);
    table.get_Item(1, 1).getTextFrame().getParagraphs().add(new Paragraph());
    table.get_Item(1, 1).getTextFrame().getParagraphs().get_Item(0).getParagraphFormat().getBullet().setType(BulletType.Symbol);
    table.get_Item(1, 1).getTextFrame().getParagraphs().get_Item(1).getParagraphFormat().getBullet().setType(BulletType.Symbol);
    table.get_Item(1, 1).getTextFrame().getParagraphs().get_Item(2).getParagraphFormat().getBullet().setType(BulletType.Symbol);

    table.get_Item(2, 1).getCellFormat().getFillFormat().setFillType(FillType.Solid);
    table.get_Item(2, 1).getCellFormat().getFillFormat().getSolidFillColor().setColor(Color.WHITE);
    table.get_Item(2, 1).getCellFormat().getBorderRight().setWidth(0);
    table.get_Item(2, 1).getCellFormat().getBorderLeft().setWidth(0);
    table.get_Item(2, 1).getCellFormat().getBorderTop().setWidth(0);
    table.get_Item(2, 1).getCellFormat().getBorderBottom().setWidth(0);

    table.get_Item(2, 1).splitByHeight((table.get_Item(2, 1).getHeight() - 30) / 2);
    table.get_Item(2, 2).splitByHeight(30);
    table.get_Item(2, 2).getTextFrame().getParagraphs().get_Item(0).setText("2023");
    table.get_Item(2, 2).getCellFormat().getFillFormat().setFillType(FillType.Solid);
    table.get_Item(2, 2).getCellFormat().getFillFormat().getSolidFillColor().setColor(Color.GREEN);

    pres.save("output.pdf", SaveFormat.Pdf);
} finally {
    if (pres != null) pres.dispose();
}

output.pdf (37.7 KB)