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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Using entire width of a word documentent without margins, to create a table

Thread ID:

Created:

Updated:

Platform:

Replies:

144031 Apr 15,2019 03:01 PM UTC Apr 16,2019 11:36 AM UTC ASP.NET MVC - EJ 2 1
loading
Tags: DocIO
Kevin
Asked On April 15, 2019 03:43 PM UTC

How to use the entire width of a word document without margins, to create a table(which uses the entire space) ?

Not like this:
 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;
                }
            }
I want to use the entire width, like an Excel sheet, which is used in Excel, but using IWTable table .

Meikanda Nayanar [Syncfusion]
Replied On April 16, 2019 11:36 AM UTC

Hi Kevin, 

Thank you for contacting Syncfsuion support.  

To meet your requirement, we suggest you to set 0 margins for the Word document and set width of the table cells to fit in entire page width. Please refer the below code example and let us know if it helps you:  

//Creates a Word document.  
WordDocument document = new WordDocument();  
//Adds one section.  
IWSection section = document.AddSection();  
//Initializes a new instance of the WTable class with the specified WordDocument instance.   
IWTable table = section.AddTable();  
//Resets the table with the specified number of rows and columns.   
table.ResetCells(2, 3);  
  
//Append text in each cells in table.  
table[0, 0].AddParagraph().AppendText("First cell First row");  
table[0, 1].AddParagraph().AppendText("Second cell First row");  
table[0, 2].AddParagraph().AppendText("Third cell First row");  
table[1, 0].AddParagraph().AppendText("First cell Second row");  
table[1, 1].AddParagraph().AppendText("Second cell Second row");  
table[1, 2].AddParagraph().AppendText("Third cell Second row");  
//Sets table border line width.  
table.TableFormat.Borders.LineWidth = 1;  
  
//Reset the margins.  
section.PageSetup.Margins.All = 0;  
//Calculate the page client width and exclude the border line width to preserve inside page.  
float pageClientWidth = section.PageSetup.ClientWidth - (table.TableFormat.Borders.Left.LineWidth + table.TableFormat.Borders.Right.LineWidth);  
//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;  
    }  
}  
  
//Saves and closes the document   
document.Save("Sample.docx");  
document.Close();  


Please let us know whether this suits your requirement.  

Thanks. 
Meikandan 


CONFIRMATION

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

Live Chat Icon For mobile
Live Chat Icon