PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

MigraDoc: How to get the width of a cell with MergeRight>0 ?
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3924
Page 1 of 1

Author:  NewUserHere [ Wed Mar 06, 2019 2:19 pm ]
Post subject:  MigraDoc: How to get the width of a cell with MergeRight>0 ?

Is there a simple way to get the whole cell width of a cell merging over other cells (Using e.g. MergeRight = 3)?

The problem, I'm currently facing with my algorithm from my previous question viewtopic.php?f=2&t=3923, is that if a cell uses the MergeRight property with a value bigger than 0 (Or to put it in other words, with the MergeRight property at all), I get only the width of the first column of the table (The green frame in the attached image) while I wanted to get the width of the whole row (The red frame in the attached image). Is there a simple way to achieve this?

Attachment:
SpannedCellWidthExample.png
SpannedCellWidthExample.png [ 29.38 KiB | Viewed 4225 times ]


Just as an idea: I would start from the current cell, get all cells that are within the range of MergeRight (So, if MergeRight = 3), I would get the next 3 cells and sum up the width of all of them:

Something like that:
Code:
var totalWidth = cell.Column.Width;

foreach (var column in cell.Table.Columns)
{
   var realColumn = column as Column;

   if (realColumn.Index <= cell.Column.Index)
   {
      continue;
   }

   totalWidth += realColumn.Width;
}

Author:  Thomas Hoevel [ Wed Mar 06, 2019 3:47 pm ]
Post subject:  Re: MigraDoc: How to get the width of a cell with MergeRight

NewUserHere wrote:
I would start from the current cell, get all cells that are within the range of MergeRight (So, if MergeRight = 3), I would get the next 3 cells and sum up the width of all of them
I would also try something along that line.

Author:  NewUserHere [ Thu Mar 07, 2019 8:36 am ]
Post subject:  Re: MigraDoc: How to get the width of a cell with MergeRight

Thanks again.

I'm now using the following code:

Code:
var cellWidth = 0d;
if (cell.MergeRight != 0)
{
   var counter = 0;
   cellWidth += cell.Column.Width.Millimeter;

   foreach (var column in cell.Table.Columns)
   {
      var realColumn = column as Column;

      if (realColumn.Index <= cell.Column.Index)
      {
         continue;
      }

      if (cell.MergeRight > counter)
      {
         cellWidth += realColumn.Width.Millimeter;
      }

      counter++;
   }

   // Add correction factor
   cellWidth -= 4;
}
else
{
   cellWidth = cell.Column.Width.Millimeter - 4;
}


Full code is available here: https://gist.github.com/SeppPenner/5bbe ... eebb324560

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/