Colspan before cell combination disappears (C# .NET)

Hello.

I am using Aspose.Slides, and I may be anxious.
The following problems occur.

We create Table one row at a time, first create eight columns.
・ Colspan 1, 1, 1, 1, 1, 1, 1, 1 (total 8 columns) in the first row at this point

Cell merge the eight columns (the merge is for me).
・ Colspan 2, 1, 2, 3 (total 8 columns) in the first row at this point

Next, clone the added row and create a new column.
Once at this stage, use SplitByColSpan to break the cell merge.
・ Colspan 1, 1, 1, 1, 1, 1, 1, 1 of the second line at this time

I’ll merge the second row of cells too (the merge is for me).
・ Colspan 1, 1, 1, 1, 1, 1, 2 of the 2nd line at this time
But if you merge the last column at this stage,
Colspan on the first line is (2, 1, 2, 2)
The second line colspan is (1, 1, 1, 1, 1, 1, 1)
It will be a total of 7 columns from a total of 8 columns.

Then you want to add rows and 8 columns (1,1,1,1,1,1,1,1), so
I want to keep the eight columns before cell merging.

Is there a target method? Thank you.

https://forum.aspose.com/t/table-mergecells-reduct-total-number-of-rows-and-columns/94407
I will ask you a question as it does not seem to be resolved.
My opinion is that we sometimes want to keep the original column information.

@yuya,

I have observed the information shared by you and request you to please provide the working sample project reproducing issue along with generated output and desired output presentation. I will investigate the issue further on my end on provision of requested information.

@mudassir.fayyaz

Thank you for your reply.

I made a sample code.
If “rowNum = 3”, I think that a PPT file will be output without a problem.
This output table is my ideal form.

However, you should change it to “rowNum = 2” from this source code and execute it.
I think that an error occurs at the location of “SplitByColSpan”.

Why? If “rowNum = 3”,
The eighth column is left in the third row, so the seventh column in the second row is “colspan = 2”.
However, in the case of “rowNum = 2,” at the stage of “table.MergeCells (table [6, 1], table [7, 1], true);”, the seventh column of the second row is "colspan = 1 It becomes ".

I can understand that this result is automatic and good result.
I think that there is a better thing in this case.

However, I think there are cases where this is not the case.
When I merge, I also want a method argument that keeps “colspan = 2” instead of automatically “colspan = 1”.

I think that the questioner who put it in the reference URL in the previous reply is the same idea as me.

Best regard.

var presentation = new Presentation();
var slide = presentation.Slides[0];

var columnNum = 8;
var rowNum = 3;

// テーブルを追加
var table = slide.Shapes.AddTable(50, 50, new double[] { 80, 80 }, new double[] { 50, 50 });
// 行列を初期設定
var tempRow = table.Rows[table.Rows.Count - 1];
while (rowNum > table.Rows.Count)
{
    table.Rows.AddClone(tempRow, false);
}

var tempColumn = table.Columns[table.Columns.Count - 1];
while (columnNum > table.Columns.Count)
{
    var column = table.Columns.AddClone(tempColumn, false);
}

for (var i =0 ; i < table.Rows.Count; i++)
{
    for (var j = 0; j < table.Columns.Count; j++)
    {
        var cell = table[j, i];
        cell.TextFrame.Text = i.ToString() + j.ToString();
    }
}

// マージする
// 1行目
table.MergeCells(table[0, 0], table[1, 0], true);
table.MergeCells(table[3, 0], table[4, 0], true);
table.MergeCells(table[5, 0], table[7, 0], true);
// 2行目
table.MergeCells(table[6, 1], table[7, 1], true);

// 3行目を追加
table.Rows.AddClone(table.Rows[1], true);
// ### Problem location ###
table.Rows.LastOrDefault()[6].SplitByColSpan(1);

presentation.Save(pptPath, SaveFormat.Pptx);

@yuya,

I have worked with the sample code shared by you by providing the presentation files using two different values of rowNum to 2 and 3 respectively. If I sum up your code, you are performing following:

  • Adding a table with 2 rows and 2 columns
  • Then based on rowNum values cloning new rows. If rowNum = 2, no New row is cloned and for rowNum=3, a new row is cloned.
  • Then you are cloning columns and making 8 columns
  • In short for rowNum=2, we will have 2 rows and 8 column table and for rowNum=3, we will have 3 rows and 8 column table
  • You are merging columns 1,2, 4, 5 and 6,7,8 belonging to row1.
  • You are merging columns 7,8 belonging to row 2
  • You are now cloning row 2 which will be added at end of table
  • For rowNum=2, we will have 3 rows in final table and for rowNum=3, we will have 4 rows in the end.

The API is performing as expected and there is no issue or wrong doing being done. The output is generated as expected by API.

For your following comments,

I am unable to understand this point.

I’m sorry, it seems that I made it difficult to understand in my sample.
There is no problem with copying the columns or merging the cells themselves.

What I am talking about is the value of colspan.
In “rowNum = 2” and “rowNum = 3” respectively
“Table.MergeCells (table [6, 1], table [7, 1], true);” Put debug points here and stop.

At this time, look at the value of colspan in the seventh column.
When “rowNum = 2”, colspan is 2,
In the case of “rowNum = 3”, I think that colspan is 2.

Then step over debugging and proceed.

At this time, look at the value of colspan in the seventh column.
When ‘rowNum = 2’, then colspan is 1
In the case of “rowNum = 3”, I think that colspan is 2.

I say that colspan will be 1 automatically.
I want to keep the original colspan value.

@yuya,

Thank you for sharing further details. An issue with ID SLIDESNET-41115 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

1 Like