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
close icon

How to take the full width of a word page using a word-table, it should not matter wether it is landscape or portrait ?!

How to take the full width of a word page using a word-table, it should not matter wether it is landscape or portrait ?!

6 Replies

PE Priyanga Elangovan Syncfusion Team July 14, 2016 07:20 AM UTC

Hi Customer,

Thank you for contacting Syncfusion support.

Yes, you can retrieve the full width of
a page for each section using PageSize property of WPageSetup class in DocIO.  
Kindly refer the below code snippet to retrieve the page width using a Word Table. 
//creates the document 
WordDocument document = new WordDocument(); 
document.EnsureMinimal(); 
//Adds the table to the document 
WTable table = document.LastSection.AddTable() as WTable; 
table.ResetCells(4, 4); 
//Gets the owner section of table using GetOwnerSection method 
WSection section = GetOwnerSection(table); 
//Retrieve the page width by using pagesize property 
float pagewidth = section.PageSetup.PageSize.Width; 
 
//Gets the owner section of the table: 
Private WSection GetOwnerSection(WTable table) 
{ 
//Gets the owner of the table 
Entity entity = table.Owner; 
while (!(entity is WSection)) 
{ 
if (entity.Owner != null) 
entity = entity.Owner; 
else 
break; 
} 
return entity as WSection 
} 


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

Please let us know if you have any other queries.

Regards,
Priyanga.E
 



NT New Tester July 15, 2016 06:36 AM UTC

Thank you, for your answer, but I want the word table to have the same size as the page with, so that that the table will use the entire width(horizontal and vertically pages) and it should look good(the proportions of the cells).



AK Ayswarya Krishna Kumar Syncfusion Team July 18, 2016 11:00 AM UTC

Hi Customer,

Thank you for your update.

Yes, it is possible to have the Word table as of same size of its page width. Kindly use the below code snippet to achieve your requirement.

 
//Retrieve the page client area width by using page setup property  
float pageClientWidth = section.PageSetup.ClientWidth; 
//Iterating through each cells and setting up width 
//in order to fit the table 
foreach (WTableRow row in table.Rows) 
{ 
foreach (WTableCell cell in row.Cells) 
{ 
//Updates the cell width based on the page client area width 
cell.Width = pageClientWidth / row.Cells.Count; 
} 
} 
Note: Page client width excludes page margins (left and right) where as page width includes the complete width.

Regards,
Ayswarya



NT New Tester July 18, 2016 11:31 AM UTC

My table has the following declaration "IWTable table = section.AddTable();" , can you adjust your example for this `??


NT New Tester July 18, 2016 11:32 AM UTC

"table[y, x]" maybe over indexers ?!


PE Priyanga Elangovan Syncfusion Team July 19, 2016 11:19 AM UTC

Hi Customer

Thank you for your update

We have prepared the sample to meet your requirement. Please find the sample from below link. Try running the sample and let us know whether it helps you.
Sample link:
http://www.syncfusion.com/downloads/support/forum/124999/ze/SampleTable1-1888733693.zip

Regards,
Priyanga.E
 
  


Loader.
Live Chat Icon For mobile
Up arrow icon