Free Support Forum - aspose.com

Relative (cursor) Positioning using DocumentBuilder?

Hi,

I’m attempting to parse documents from a template that has a repeating structure of:
section->table->row->cell->paragraph
… ->Table->Cell->paragraph (these are hanging off of the cell in the 1st line).

Using the DocumentBuilder, I’d like to position the cursor at the beginning of the 2nd paragragh listed above. Using moveToCell(), I can position the cursor at the beginning of the 1st paragraph. Using moveTo(), I can position the cursor at the end of the 2nd paragraph. What I’d like to be able to do is to use moveTo() to get to the desired paragraph and then tell DocumentBuilder to reposition the cursor at the beginning of the paragraph.

Is there a way to achieve the navigation?

I’ve attached a docuemt based upon the template.

Thanks,

Dave Wolf

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. You can use DocumentBuidler.moveToCell method to move cursor to the beginning of the cell:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/aspose.words.documentbuilder.movetocell.html

Here is an example:

// Open document and create DocumentBuidler.

Document doc = new Document(@"Test001\in.doc");

DocumentBuilder builder = new DocumentBuilder(doc);

// move builder cursor to the beggining of the first cell of the first table.

builder.MoveToCell(0, 0, 0, 0);

// Insert some text.

builder.Write("This is text at the begginng of the cell");

// Save output document.

doc.Save(@"Test001\out.doc");

If you need to move cursor to the beginning of a particular paragraph, you can use DocumentBuidler.moveTo method:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/aspose.words.documentbuilder.moveto.html

Here is code example:

// Open document and create DocumentBuidler.

Document doc = new Document(@"Test001\in.doc");

DocumentBuilder builder = new DocumentBuilder(doc);

// Get table.

Table table = doc.FirstSection.Body.Tables[0];

// Move builder cursor to the beggining of the first paragraph of the first cell of the table.

Cell cell = table.FirstRow.FirstCell;

if (cell.FirstParagraph.HasChildNodes)

builder.MoveTo(cell.FirstParagraph.FirstChild);

else

builder.MoveTo(cell.FirstParagraph);

// Insert some text.

builder.Write("This is text at the begginng of the cell");

// Save output document.

doc.Save(@"Test001\out.doc");

Hope this helps.

Best regards.

Thanks, That worked great!

Might I suggest that you add this to the moveTo() Javadoc? That might save some others time in the future.

Regards,

Dave

Hi Dave,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your suggestion. We will consider adding this into the documentation.

Best regards.