I've managed to get the template set up and insert the table from a building
block into the page followed by a paragraph mark which does as intended and
adds a new page. the following code does this:
object bb = "QtrPage";
object richText = false;
wordDoc = wordApp.Documents.Add(ref templateFile, ref
paramMissing, ref paramMissing, ref visable);
//MessageBox.Show(wordApp.Documents.Count.ToString());
wordDoc.Select();
((Microsoft.Office.Interop.Word.Template)wordDoc.get_AttachedTemplate()).BuildingBlockEntries.Item(ref bb).Insert(wordApp.Selection.Range,ref richText);
//MessageBox.Show(wordDoc.Tables.Count.ToString());
wordDoc.Tables[1].AllowAutoFit = false;
wordDoc.Tables[1].AllowPageBreaks = false;
wordDoc.Tables[1].Cell(1, 1).Select();
wordApp.Selection.Paste();
prior to this code there is a piece which copies a chart from Excel and this
is pasted into one of the table elements.
This is all fine but when i try to copy the insert code and use it again it
overwrites the first table instead of adding it to the following page.
What i want to know is how to insert the second table on the second page.
and a better idea of how to insert further items into the document.
Thanks in advance,
G
Jay Freedman said:
Hi All,
I'm fairly new to using the Word object model (2007) and have a couple of
questions regarding controling the pages programatically. What i need to be
able to do is to copy various charts and images from excel and lay them out
on a word page. I'm going to be resizing these images so that the fill a 1/4
page size each.
WHat i'd like to know firstly is how are new pages added? My intention is to
resize the images and ensure that there is no way that 4 images will flow
over onto the next page. How, if i do this can i add a new page and then
reference this to start adding further elements?
Any help is most appreciated, thanks in advance,
G
Word automatically adds a new page whenever the document's contents won't fit
within the current set of pages, or when you insert a manual page break. From a
programmatic viewpoint, though, the question is essentially meaningless.
The best way to solve this problem goes like this:
- Create a template specifically as a base for this type of document.
- Make a 2x2 table. Use the Table > AutoFit > Fixed Column Width and Table >
Table Properties > Row > Specify row height commands to fix the sizes of the
cells to 1/4 page each. (Note that Word requires a paragraph mark below a table,
so you can't make the table go all the way to the bottom margin. You can format
the paragraph mark to 1 pt, which will get you close.) Turn off the table's
borders if you want to.
- Save the table as a Building Block in this template.
- In a document based on the template, your code will start by inserting a table
from the Building Block.
- Insert the images, with inline wrapping, one per cell. If they're larger than
the cell dimensions, they'll automatically resize to fit the cell.
- After each set of four images, insert a second paragraph mark at the end of
the document (which will automatically create another page, since it won't fit
on the first page) and another copy of the table Building Block.