We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

I want the heading to be in the same line, not if the table is to large to move to the next line ,espeaciylly if there is one column which is much more smaller but it does not need that much space.How ?

Thread ID:





127072 Oct 24,2016 01:54 PM UTC Oct 26,2016 06:46 AM UTC ASP.NET MVC 5
Tags: DocIO
Asked On October 24, 2016 01:54 PM UTC

I want the heading to be in the same line, not if the table is to large to move to the next line ,espeaciylly if there is one column which is much more smaller but it does not need that much space.How ?
Word, table

Replied On October 24, 2016 02:53 PM UTC

Or mybe its is better the table should get its width by the biggest coumn not header , I tried "table.TableFormat.IsAutoResized" but I need something which will take the biggest coumns width

Ayswarya Krishna Kumar [Syncfusion]
Replied On October 25, 2016 01:25 PM UTC

Hi Customer,

Thank you for contacting Syncfusion support.

On analyzing, we have prepared the sample to meet your requirement. In the sample we have achieved the mentioned scenario with the following steps.

(1) Adds the table to the document section.
(2) Sets the first row of the table as table header row.
(3) Append text to each column.
We have found the maximum column width by measuring the text width using Graphics.MeasureString() method for each cell text content.
Sets the maximum column width to each column of the table.

We have attached the sample for your reference. Try running the sample and let us know whether it helps you?

Sample Link:

If we misunderstood your requirement, kindly elaborate your requirement with clear description (like screenshot of your output or expected output document), thereby we will analyse further on your requirement and update you with appropriate solution at the earliest.


Replied On October 25, 2016 02:51 PM UTC

thanks, I get   "A first chance exception of type 'System.NullReferenceException' occurred in SyncfusionWrapper.dll", somewhere in "     foreach (WTableRow row in table.Rows)
                    foreach (WTableCell cell in row.Cells)

                        //cell.CellFormat.Paddings.All = 5;
                        float textWidth = MeasureString(cell.LastParagraph.ChildEntities.LastItem as WTextRange);
                        if (textWidth > maxColumnWidth)
                            maxColumnWidth = textWidth;

Can you help ?

Replied On October 25, 2016 02:58 PM UTC

'((Syncfusion.DocIO.DLS.ICompositeEntity)(((Syncfusion.DocIO.DLS.WTextBody)(cell)).LastParagraph))' is null

Ayswarya Krishna Kumar [Syncfusion]
Replied On October 26, 2016 06:46 AM UTC

Hi Customer,

Thank you for your update.

On analyzing on the reported “Null reference Exception”, we found that the exception occurred due to accessing inappropriate child entity (there might be the chance of occurrences some other paragraph items like WPicture, BookmarkStart, BookmarkEnd, etc) from the paragraph entity collection. We have modified the sample to access the child entity of the paragraph with iterations. Please find the below code snippet for more understanding.

Code Snippet:

//To iterate the paragraphs of the cell 
foreach (WParagraph paragraph in cell.Paragraphs) 
   //To iterate the child entities of the paragraph 
   foreach (Entity entity in paragraph.ChildEntities) 
       //To Access the text range 
       if (entity is WTextRange) 
           //To measure the string width 
           float textWidth = MeasureString(entity as WTextRange); 
           if (textWidth > maxColumnWidth) 
           maxColumnWidth = textWidth; 

We have attached the modified sample for your reference. Please find the modified sample from the below link.

Sample Link:

For more details about the document elements please find the below UG Documentation links.

1) Working with Word document:

2) Working with Sections:

3) Working with Paragraphs:

4) Working with Tables:

Note: If you could still reproduce the issue at your end, please provide us the sample that reproduce the issue, along with the Word document you are using, if any? So that we could analyze further and could provide you more appropriate details at the earliest.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon