PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Sep 20, 2019 7:28 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Mar 06, 2019 2:19 pm 
Offline

Joined: Tue Mar 05, 2019 10:33 am
Posts: 7
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 409 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;
}


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 06, 2019 3:47 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2967
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 07, 2019 8:36 am 
Offline

Joined: Tue Mar 05, 2019 10:33 am
Posts: 7
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 122 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group