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. Image for the cookie policy date

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 ?

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

5 Replies

TE Testname 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


AK Ayswarya Krishna Kumar Syncfusion Team 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.
(4)
We have found the maximum column width by measuring the text width using Graphics.MeasureString() method for each cell text content.
(5)
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:
https://www.syncfusion.com/downloads/support/forum/127072/ze/GenerateWord-1906430176.zip

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.

Regards,
Ayswarya



TE Testname 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 ?


TE Testname October 25, 2016 02:58 PM UTC

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


AK Ayswarya Krishna Kumar Syncfusion Team 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:
https://www.syncfusion.com/downloads/support/forum/127072/ze/GenerateWord-508976443.zip

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

1) Working with Word document:
https://help.syncfusion.com/file-formats/docio/working-with-word-document

2) Working with Sections:
https://help.syncfusion.com/file-formats/docio/working-with-sections

3) Working with Paragraphs:
https://help.syncfusion.com/file-formats/docio/working-with-paragraph

 
4) Working with Tables:
https://help.syncfusion.com/file-formats/docio/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.

Regards,
Ayswarya


Loader.
Live Chat Icon For mobile
Up arrow icon