Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a table with rows and columns in C#. Is there any way to create 3 rows and 2 columns in each Ms Word page?
Thanks,
Prabhat
Posted
Comments
Maciej Los 28-May-13 4:55am    
What have you done till now?
Where are you stuck?

1 solution

Please, read my comment and follow the below links:
How to: Programmatically Create Word Tables[^]
How to: Create Word Tables[^]
 
Share this answer
 
Comments
PrabhatSharp 28-May-13 5:00am    
I have created a word file. Now, each page is supposed to have only 3 rows with 2 columns.
Maciej Los 28-May-13 5:23am    
and the problem is...
Please, follow the links and pass proper values as a parameter to create table.
PrabhatSharp 28-May-13 6:20am    
Hi Maciej,
I am sorry to confuse you. I have already created table with rows and columns. The number of column is fixed, but number of rows varies, and hence number of pages also. More than three rows are created. My problem is, each page in Ms Word (like page1,2,3) is supposed to have only three rows.
Maciej Los 28-May-13 6:29am    
Still don't get you ;(
Where is the problem? Please, be more specific and provide more details... I really do understand that yoou want to add table to each page of MS Word document (with different no. of rows and fixed no. of columns), but where are you stuck? Please, use "Improve question" widget and update your question adding new information. Share your code... etc.
PrabhatSharp 2-Jun-13 3:27am    
Hi Maciej,
Sorry for late reply. Below is my code:
Microsoft.Office.Interop.Word.Table tbl1;
Microsoft.Office.Interop.Word.Range wordRange = doc.Content;
tbl1 = doc.Content.Tables.Add(wordRange, TotalNumber, 2, ref objMiss, ref objMiss);//Here TotalNumber is number of rows that varies and computed beforehand.

tbl1.Borders.Enable = 1;
tbl1.AllowAutoFit = true;


int cc = 1;

for (int r = 1; r <= TotalNumber; r++)
{
for (int c = 1; c <= 2; c++)
{


if (cc < UserNameOne.Length)
{
tbl1.Cell(r, c).Range.Text = "Welcome to YZ Company" + "\n" + "User Name:" + UserNameOne[cc] + "\n" + "Password:" + UserPassword[cc] + "\n";// UserName and Password comes from string list
tbl1.Cell(r, c).Range.Font.Bold = 0;
tbl1.Cell(r, c).Range.Font.Size = 28;

cc = cc + 1;

}
}
}
////////////////////////
In the code above, number of rows is determined by TotalNumber. like, if its 6 number of rows created are 6 in Word file. My problem is, I want that 6 rows in two pages, 3 rows in each.
Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900