Pre Purchase Questions

Hi,

We are interested in buying your product “Aspose.words for java”, but before that we have some questions regarding our requirement. We want to write and modify Word documents without utilizing Microsoft Word and wants to be sure that your product will help us in achieving the following requirements :-

  1. Can we create Table of contents using your product?

  2. Can we create hyperlinks, bullets, numbering, headers & footers?

  3. Can we create tables and insert rows and columns as and when they are required?

  4. Apart from these requirements what are the limitations of your product.

This message was posted using Email2Forum by sheliah.

Hi

Thank you for your interest in Aspose.Words.

  1. Yes, you can insert TOC into the word document, please see the following link for more information:
    https://docs.aspose.com/words/net/working-with-table-of-contents/
    However, Aspose.Words still does not update TOC fields. As a workaround you can update fields inside the document manually (ctrl+A and F9) or using macro. See the following link to learn more.
    https://support.microsoft.com/en-us/topic/the-filename-field-does-not-automatically-update-when-you-open-a-document-in-word-de2bfb95-d990-1ced-a618-5ac0a2ec1be4
  2. Yes, you can insert all these elements into the document.
    How to insert hyperlink
    https://docs.aspose.com/words/net/working-with-hyperlinks/
    How to create list
    https://docs.aspose.com/words/net/working-with-lists/
    How to create header/footer
    https://docs.aspose.com/words/net/working-with-headers-and-footers/
  3. Yes, you can create tables using Aspose.Words:
    https://docs.aspose.com/words/net/introduction-and-creating-tables/
  4. The only limitation is that Aspose.Words does not evaluate TOC fields as I described in first point.
    Please let me know in case of any issue, I will be glad to help you.
    Best regards.

I have one more Question, how to add a Row in table of an existing document. I know how to add a row in a new table but how can we add a row in an existing table, please reply.
Regards,
Gorav

Hi

Thanks for your inquiry. If you need to add rows to an existing table then I think you should clone existing row and add it at the end of table as shown in the following code:

'Get last row from the table
Dim refRow As Row = myTable.LastRow
'Clone and insert rows after ref row
For i As Integer To 10
'Clone row
Dim clone As Row = CType(row.Clone(True), Row)
'Inser clone of row 
myTable.Rows.Add(clone)
Next

Hope this helps.
Best regards.

Please send the java code.
Regards,
Gorav

Sure, here is java code:

// Open document
Document doc = new Document("C:\\Temp\\in.doc");
// Create DocumentBuilder
DocumentBuilder builder = new DocumentBuilder(doc);
// Get table from the first section of document
Table myTable = doc.getFirstSection().getBody().getTables().get(0);
// Get last row of table
Row myRow = myTable.getLastRow();
// Add 10 more rows into the table
for (int rowIndex = 0; rowIndex < 10; rowIndex++)
{
    // Clone last row
    Row newRow = (Row)myRow.deepClone(true);
    // Insert created row into the table
    myTable.appendChild(newRow);
    // Loop through all cells in row
    for (Cell cell : newRow.getCells())
    {
        // Remove old content from the cell
        // Remove paragraphs
        while (cell.getParagraphs().getCount() > 1)
            cell.getLastParagraph().remove();
        // Remove content of first paragraph
        cell.getFirstParagraph().getChildNodes().clear();
        // Move DocumentBuilder cursor to the cell
        builder.moveTo(cell.getFirstParagraph());
        // Insert new content
        builder.write("This is new content");
    }
}
// Save document
doc.save("C:\\Temp\\out.doc");

Hope this helps.
Best regards.

So far the information u provided has helped us in creating some portion of sample document which we have to show in order to purchase your product.
Now my next requirement is to link two fields i.e. if i click on one field it should take me to some other field already defined in my document.
The information that is provided on your site is very limited in terms of functionality, can u send me some technical document from where i can get to know which method to use according to my requiremt, please send the java specific doc. My mail id is gorav.gudwani@globallogic.com.
Thanks & Regards,
Gorav

Hi

Thanks for your inquiry. You can use Bookmarks and Hyperlinks to navigate in the document. Please see the following code for instance.

// Create new Document and DocumentBuilder
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert hyperlink to the mybk bookmark
builder.insertHyperlink("Link to my bookmark", "mybk", true);
// Insert few page breaks
builder.insertBreak(BreakType.PAGE_BREAK);
builder.insertBreak(BreakType.PAGE_BREAK);
// Insert bookmark and some text
builder.startBookmark("mybk");
builder.write("This is text inside bookmark");
builder.endBookmark("mybk");
// Save document
doc.save("C:\\Temp\\out.doc");

Hope this helps.
You can find all Aspose.Words documentation here:
https://reference.aspose.com/words/net/
Best regards.

Hi,
Thanks for the reply, i have already tried this solution by reffering to the documentation guide which is there on your website. My Question is to link two existing fields in a document.
The solution you provided creates a new string as hyerlink and points to an already defined bookmark which is working fine, but cant we link two already defined fields. I hope i am clear this time :slight_smile:
Thanks,
Gorav

Hi

What kind of fields would you like to link? Can you do the same in MS Word? If so, please attach sample document here. I will investigate the issue and provide you more information.
Best regards.

Hi,
Yes we can do the same in word, suppose I have written “Question” and after few lines “Answer”.
Now i’ll bookmark “Answer” and then create a hyperlink on “Question” which will point to “Answer” bookmark.
I can send the sample document if u want , give me your mail id.

Hi

Thanks for your request. You can send e-mail via out site. Please send me the document to my e-mail, as described here:
https://forum.aspose.com/t/aspose-words-faq/2711
Best regards.

Hi

Thank you for additional information. The code I provided in my previous answer does exactly the same. I suppose you already have the document and need to find “Question” and “Answer” text in your document and link them. Right? If so, I suppose you can try using ReplaceEvaluator to find text in the document. I created simple example for you.
I also attached sample documents.

// Open document
Document doc = new Document("C:\\Temp\\in.doc");
// find "answer" text and insert bookmarks
doc.getRange().replace(Pattern.compile("Answer"), new ReplaceEvaluatorInsertBookmark(), false);
// find "question" text and insert hyperlink
doc.getRange().replace(Pattern.compile("Question"), new ReplaceEvaluatorInsertHyperlink(), false);
// Save output document
doc.save("C:\\Temp\\out.doc");

=================================================================

public class ReplaceEvaluatorInsertBookmark implements ReplaceEvaluator
{
    // There could be many matched words,
    // we will use counter to generate unique names for bookmarks
    private int mBookmarkCounter = 0;
    public synchronized int replace(Object object, ReplaceEvaluatorArgs e) throws Exception
    {
        // Get MatchNode
        Run matchedRun = (Run)e.getMatchNode();
        // Get parent paragrpah
        Paragraph par = matchedRun.getParentParagraph();
        // We will supose that answer text that should be bookmarked is
        // in the pagraph wit Heading 2 style
        if(par.getParagraphFormat().getStyleIdentifier() == StyleIdentifier.HEADING_2)
        {
            // Create documentbuilder to insert bookmark
            DocumentBuilder builder = new DocumentBuilder(e.getMatchNode().getDocument());
            // Move builser to node
            builder.moveTo(matchedRun);
            // Insert bookmark
            builder.startBookmark("answer_" + mBookmarkCounter);
            builder.endBookmark("answer_" + mBookmarkCounter);
            mBookmarkCounter++;
        }
        return ReplaceAction.SKIP;
    }
}

==================================================================

public class ReplaceEvaluatorInsertHyperlink implements ReplaceEvaluator
{
    // There could be many matched words,
    // we will use counter to generate unique names for bookmarks
    // We supose that there is the same number of question and answers
    private int mBookmarkCounter = 0;
    public synchronized int replace(Object object, ReplaceEvaluatorArgs e) throws Exception
    {
        // Get MatchNode
        Run matchedRun = (Run)e.getMatchNode();
        // Get parent paragrpah
        Paragraph par = matchedRun.getParentParagraph();
        // We will supose that question text that should be a hyperlink is
        // in the pagraph wit Heading 2 style
        if(par.getParagraphFormat().getStyleIdentifier() == StyleIdentifier.HEADING_2)
        {
            // Create documentbuilder to insert hyperlink
            DocumentBuilder builder = new DocumentBuilder(e.getMatchNode().getDocument());
            // Move builser to node
            builder.moveTo(matchedRun);
            // Insert hyperlink
            builder.insertHyperlink(matchedRun.getText(), "answer_" + mBookmarkCounter, true);
            // Remove text from matched run
            matchedRun.setText("");
            mBookmarkCounter++;
        }
        return ReplaceAction.SKIP;
    }
}

Please see the following link to learn more about replace evaluator.
https://reference.aspose.com/words/java/com.aspose.words/range#replace(java.util.regex.Pattern,java.lang.String,com.aspose.words.FindReplaceOptions)
Regarding TOC, you can insert TOC into the word document, please see the following link for more information:
https://docs.aspose.com/words/net/working-with-table-of-contents/
However, Aspose.Words still does not update TOC fields. As a workaround you can update fields inside the document manually (ctrl+A and F9) or using macro. See the following link to learn more.
https://support.microsoft.com/en-us/topic/the-filename-field-does-not-automatically-update-when-you-open-a-document-in-word-de2bfb95-d990-1ced-a618-5ac0a2ec1be4
PS: If you need, you can attach your docuemnts in the forum, only you can Aspose staff members can download attached files.
Best regards.