Auto Texts && Aspose.WORD

Dear all,

at the moment I’m looking for a way to create WORD Documents without Microsoft’s Com / Interop components. Aspose.Word seems to be a good solution. Right now I have two questions relating Aspose.Word functions.

  1. It is possible to use auto texts? I have to use plain documents. The content is given by a generic object model. Every object of these model knows, how it should be presented in a word document. Thereby, auto texts are used to create the basic structure of the document. In neraly every situation an auto text models a row of a table containing some bookmarks to insert contents on the right place. If this function isn’t available at the moment (or in the near future), I will try to adapt my models to use the existing table objects.

  2. It is possible to determine the current page (based on the cursor location) during the document generation process?

Thanks for your support

Regards

Erik

Hi Erik,

Thank you for your interest in Aspose.Word.

  1. Classes that represent and allow to manipulate bBookmarks and tables in a Word document are available in Aspose.Word, for more info see the API and the wiki documentation https://docs.aspose.com/words/net/

  2. I’m afraid you cannot determine the current page number in Aspose.Word because Word documents are not paginated and Aspose.Word does not paginate them either.

Roman,

thank you for your answer. As I take from your reply, auto texts are not supported today. But I believe that I’m able to use the powerful table object instead.

Still there is another, even more critical problem. Every document consists of an arbitrary number of tables. I must ensure that every table is located on one page (based on the assumption, that the height of a table is smaller than the page height). How can I do that? Using Com/Interop I retrieve the current page number and set an additional bookmark. After the creation of my table I retrieve the current page number again. If both numbers are different I’m able to insert a page break using the additional bookmark.

Maybe you are able to provide a small example to me. I found some useful properties relating paragraphs, but they didn’t work.

Please let me know, whether you need an example document.

Thanks in advance

Erik

Sorry I forgot about auto texts. Do you mean Auto Text as it is used in MS Word? I’m not exactly sure how you want to use it from Aspose.Word. From what I can see Auto Text is just a list of predefined words and phrases (I’m not yet sure where all of them are actually stored) and you simply start typing that phrase in MS Word and it suggests it so you can just hit Enter and it will complete the phrase. So how do you want to use it in Aspose.Word?

There is really no way Aspose.Word can ensure a specific page number at the moment. It will be possible, but later, several months away. You can somewhat play around by using paragraph properties KeepWithNext, KeepTogether and also RowFormat.AllowBreakAcrossPages to control where a page break is made by MS Word, but that’s all Aspose.Word can do.

Roman,

please take a look at the attached files. You should start with the .dot file. Please take a look over the existing auto texts (Insert\auto text\autotext --> example.dot). There you can see the predefined table rows. Each auto text ends with a bookmark denoting the next insert point.

The second document contains several tables, generated by the use of the existing auto texts. It is necessary to insert a page break between the second and the third table. Otherwise the third table would start on the first page.

Maybe you can give me just a little more help to implement your suggestions. A good example could be the document builder example. Extend the chessboard size to 20 x 8. Now, the chessboard table is plotted over two pages. How can I say Word that it should insert a page break before the table?

Regards

Erik

To make a table start from a new page, you either need to set Paragraph.ParagraphFormat.PageBreakBefore = true; in the first paragraph of the first cell in the table. Maybe it is easier to set PageBreakBefore on the paragraph that is just before the table.

Not sure if you intend to do that in MS Word or programmatically. If you want to do that programmatically, then lets say you find the Nth table:

//Get the 6th table (index is zero based).
Table table = (Table)doc.GetChildNode(NodeType.Table, 5, true);

//Let's say you know or you are sure there is a paragraph just before the table
Paragraph para = (Paragraph)table.PreviousSibling;
para.ParagraphFormat.PageBreakBefore = true;

The other option to set the first paragraph in the first cell:

table.FirstRow.FirstCell.FirstParagraph.ParagraphFormat.PageBreakBefore = true;

There is one big problem that prevents the use of your suggestions. I don’t know whether the current table fully fit into the current page or whether the table is split over 2 or more pages. It depends highly on the given data source. So I’m never being sure about the total size of a table.

The only way to determine, whether a page break is needed or not is the use of paging information’s of a document. When do you plan to realize that function? Maybe you can give some information about the ETA of that function?

Its a serious feature. ETA is several months. Cannot be more exact.